Stop reversal

Author: Dominic.
Stop reversal

This script is designed as a visual trading indicator for the MetaTrader 4 platform, specifically crafted to identify potential trend reversal points based on price action dynamics. It functions by monitoring historical price movements to establish "Stop Levels"—dynamic price thresholds that indicate where a trend may be losing momentum or shifting direction.

Core Logic and Functionality

The primary objective of this tool is to track the relationship between current market closes and previous price levels. Instead of looking at simple moving averages or volume, it focuses on the following logic:

  • Trend Tracking: The script continuously evaluates whether the market is moving upward or downward by comparing the current closing price to a stored "previous" level.
  • Dynamic Stop Level Calculation: Depending on the direction of the price movement, the tool calculates a specific threshold (the Stop Level). It uses a user-defined sensitivity factor (measured in pips) to create a buffer around the price. This ensures that the indicator reacts to significant movements rather than minor market noise.
  • Momentum Analysis: The logic distinguishes between different types of price action:
    • If prices are consistently falling, it adjusts the Stop Level downward to reflect the current trajectory.
    • If prices are consistently rising, it adjusts the Stop Level upward.
    • In cases where the price direction changes or fluctuates significantly, the script re-calculates these levels to adapt to the most recent market behavior.

Visual Signals and Execution

The indicator provides clear visual feedback on your chart to highlight these potential turning points:

  • Buy Signals: When the market shows a specific upward surge that breaks through a downward-trending Stop Level, the script identifies this as a potential reversal and marks it with a visual arrow.
  • Sell Signals: Conversely, when the price drops below an upward-trending Stop Level, the script marks this as a potential bearish reversal with a different visual indicator.

Summary for the Trader

Essentially, this tool acts as a "trend watcher." It automates the tedious task of calculating where price support and resistance might flip based on recent momentum. By highlighting these reversal points visually, it allows traders to identify areas where a trend might be exhausted, providing potential entry points for counter-trend trades or confirmation for trend continuations.

Miscellaneous
Implements a curve of type %1
12 Views
0 Downloads
0 Favorites
Stop reversal
//+------------------------------------------------------------------

//|                                            Stopreversal Mt4.mq4 
//|                                                                  
//|                                                                  

//|                                 Conversion only Dr. Gaines       

//|                                 dr_richard_gaines@yahoo.com      

//|                                                                  

//+------------------------------------------------------------------


#property copyright " Dominic."
#property link      " http://www.metaquotes.net/"

#property indicator_chart_window
#include <stdlib.mqh>
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_width1 2 
#property indicator_color2 Red
#property indicator_width2 2


//+------------------------------------------------------------------

//| Common External variables                                        

//+------------------------------------------------------------------


//+------------------------------------------------------------------

//| External variables                                               

//+------------------------------------------------------------------

extern double nPips = 0.004;

//+------------------------------------------------------------------

//| Special Convertion Functions                                     

//+------------------------------------------------------------------


int LastTradeTime;
double ExtHistoBuffer[];
double ExtHistoBuffer2[];

void SetLoopCount(int loops)
{
}

void SetIndexValue(int shift, double value)
{
  ExtHistoBuffer[shift] = value;
}

void SetIndexValue2(int shift, double value)
{
  ExtHistoBuffer2[shift] = value;
}

//+------------------------------------------------------------------

//| End                                                              

//+------------------------------------------------------------------


//+------------------------------------------------------------------

//| Initialization                                                   

//+------------------------------------------------------------------


int init()
{
   SetIndexStyle(0, DRAW_ARROW, STYLE_SOLID);
   SetIndexArrow(0, 233);
   SetIndexBuffer(0, ExtHistoBuffer);
   SetIndexStyle(1, DRAW_ARROW, STYLE_SOLID);
   SetIndexArrow(1, 234);
   SetIndexBuffer(0, ExtHistoBuffer);
   SetIndexBuffer(1, ExtHistoBuffer2);
   return(0);
}
int start()
{
//+------------------------------------------------------------------

//| Local variables                                                  

//+------------------------------------------------------------------

int shift = 0;
double cnt = 0;
double TrStopLevel = 0;
double PREV = 0;
double pass = 0;

SetLoopCount(0);
// loop from first bar to current bar (with shift=0)
for(shift=Bars-2;shift>=0 ;shift--){ 


if( (Close[shift] == PREV) ) 
{
TrStopLevel=PREV;

}
else 
{
if( (Close[shift+1])<PREV && (Close[shift]<PREV)  ) 
{
TrStopLevel=MathMin(PREV,Close[shift]*(1+nPips));
}

      else 
      {
            if( ((Close[shift+1])>PREV) && (Close[shift]>PREV) ) 
            {
            TrStopLevel=MathMax(PREV,Close[shift]*(1-nPips));
            }


            else 
                  {
                  if( (Close[shift]>PREV) ) 
                  {                   
                  TrStopLevel=Close[shift]*(1-nPips);
                  }

                        else TrStopLevel=Close[shift]*
(1+nPips);
                  }
      }
}


if( Close[shift] > TrStopLevel &&  Close[shift+1]<PREV && PREV != 
0 ) 
{
//SetOrder(OP_BUY,1,ask,2,0,ask+TakeProfit*Point,blue);
//Alert("buy");
SetIndexValue(shift, TrStopLevel);
}


if( Close[shift] < TrStopLevel &&  Close[shift+1]>PREV  && PREV != 
0  ) 
{
//SetOrder(OP_SELL,1,bid,2,0,bid-TakeProfit*Point,Red);
SetIndexValue2(shift, TrStopLevel);
//Alert("Sell");
}


PREV=TrStopLevel;
//Alert(TrStopLevel);
} 

  return(0);
}

Comments