StopReversal

Download script
Author: Dominic.
StopReversal

The StopReversal script is designed as a visual technical indicator for the MetaTrader platform, specifically crafted to identify potential trend reversals in price action. It operates by tracking price movements and establishing a dynamic "stop level" based on historical behavior.

Core Logic and Functionality

The primary goal of this tool is to monitor how the market price interacts with previous levels to signal when a current move might be exhausted or reversing. Here is how the logic breaks down:

1. Tracking Historical Price Movement The script continuously scans past price data, looking at the closing prices of candles. It maintains a memory of the "previous" significant level. By comparing the current price to this historical data, it determines the direction of the momentum—whether the market is currently pushing higher, pulling lower, or consolidating.

2. Dynamic Stop Level Calculation The tool calculates a reactive threshold (the Stop Level) based on four specific market scenarios:

  • Stability: If the price remains unchanged from the previous level, the stop level stays steady.
  • Downward Momentum: If the price is consistently falling, the script adjusts the stop level downwards, taking into account a small buffer (defined by "nPips").
  • Upward Momentum: If the price is consistently rising, it adjusts the stop level upwards with a similar buffer.
  • Trend Shifts: If the price makes an abrupt move against the established trend (for example, a sudden spike upward in a downward market), the script recalculates the stop level to reflect this new reality.

3. Reversal Signal Identification The "Reversal" alert occurs when a specific contradiction happens between the current price action and the historical momentum. The script looks for instances where:

  • The price moves significantly above (or below) the established Stop Level, while the preceding candle showed movement in the opposite direction.

4. Visual Representation Once these conditions are met, the indicator places visual markers on your chart:

  • Lime/Green Arrows: Generally indicate a potential "Buy" opportunity where the price has broken out of a downward trend or hit a significant support level.
  • Red Arrows: Generally indicate a potential "Sell" opportunity where the price has broken out of an upward trend or hit a significant resistance level.

Summary for the Trader

In simple terms, this script acts as a "trend watcher." It follows the market's path and draws a line in the sand. When the market price manages to break through that line in a way that suggests it is changing direction (reversing), the script highlights that spot on your chart with an arrow, helping you identify potential entry points for trades based on shifts in market sentiment.

Miscellaneous
Implements a curve of type %1
15 Views
0 Downloads
0 Favorites
StopReversal
//+------------------------------------------------------------------
//|                                            StopReversal.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.001;

//+------------------------------------------------------------------
//| 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