Stop_reversal_bluestops_v1

Download script
Author: Dominic.
Stop_reversal_bluestops_v1

The Stopreversal Mt4 script is an analytical tool designed to identify potential market reversals by monitoring price action and establishing dynamic "stop levels" based on historical trends. Instead of simply reacting to every price movement, the logic focuses on tracking how the market interacts with previous price points to highlight moments where a trend may be exhausting or turning.

Core Logic and Behavior

Dynamic Stop Level Calculation The primary engine of this script is its ability to track a moving "Stop Level." The script looks at the relationship between the current closing price and the previous price levels. It categorizes price movement into four distinct behaviors:

  • Steady Trends: If the price is consistently moving in one direction (up or down) relative to the previous level, the script adjusts the Stop Level to follow that momentum, incorporating a small "buffer" (defined by pips) to account for minor market noise.
  • Price Consolidation: If the price remains stagnant or matches the previous level, the Stop Level stays fixed at that point.
  • Directional Shifts: When the price moves against the established trend or creates a new local high/low, the script recalculates the Stop Level to reflect this new boundary.

Volatility Integration (ATR) A key feature of this tool is its ability to adapt to different market environments. It includes an option to use the Average True Range (ATR) indicator. When enabled, the script doesn't just look at a fixed number of pips; it measures the current "volatility" of the market. This allows the tool to automatically widen its requirements during high-activity periods and tighten them during calm periods, helping to filter out false signals.

Reversal Identification The script identifies a potential reversal when the price closes on the opposite side of the calculated Stop Level while simultaneously showing a "pullback" or specific movement pattern from the previous candle.

When these conditions are met:

  1. Visual Signaling: The script places specific visual markers (arrows) on the chart to alert the user to the potential shift in trend.
  2. Dynamic Drawing: It draws horizontal segments (trend lines) on the chart to visually represent where the stop level was triggered.
  3. Real-time Feedback: It provides a dynamic comment on the chart screen displaying the exact price level at which the reversal occurred.

Summary for Traders

Essentially, this tool acts as a "trend-aware" filter. It maps out the boundaries of current market momentum and flags instances where price action breaks through those boundaries in a way that suggests a trend change is likely occurring. By combining historical price behavior with real-time volatility measurements (ATR), it aims to provide more context than a simple moving average or RSI indicator alone.

Indicators Used
Indicator of the average true range
Miscellaneous
Implements a curve of type %1
15 Views
0 Downloads
0 Favorites
Stop_reversal_bluestops_v1
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

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

//|                                            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 3
#property indicator_color1 Lime
#property indicator_width1 2 
#property indicator_color2 Red
#property indicator_width2 2



extern double nPips = 0.004;// for calculation of arrows
extern int StopPips =40; // for calculation of blue stop line ignored if UseATRStop is true
extern bool UseATRStop = true;//  
extern double ATRmultiplier= 0.45; //  

double stop,atr;
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;
}

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 deinit()
  {
//----
for(int shift=Bars-2;shift>=0 ;shift--)
   {
   if (ObjectFind(TimeToStr(Time[shift]))>-1) ObjectDelete(TimeToStr(Time[shift]));
   }

//----
   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) 
{
if (UseATRStop)
   {
   atr=iATR(NULL,0,14,shift);
   stop =NormalizeDouble(TrStopLevel-atr*ATRmultiplier,MarketInfo(Symbol(),MODE_DIGITS));
   }
   else stop =NormalizeDouble(TrStopLevel-StopPips*Point,MarketInfo(Symbol(),MODE_DIGITS));
if (ObjectFind(TimeToStr(Time[shift]))>-1) ObjectDelete(TimeToStr(Time[shift])); 
ObjectCreate(TimeToStr(Time[shift]),OBJ_TREND,0,Time[shift+1],stop,Time[shift],stop);
ObjectSet(TimeToStr(Time[shift]),OBJPROP_RAY,0);
ObjectSet(TimeToStr(Time[shift]),OBJPROP_COLOR,DodgerBlue);
ObjectSet(TimeToStr(Time[shift]),OBJPROP_WIDTH,2);
Comment(stop);
//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);
if (UseATRStop)
   {
   atr=iATR(NULL,0,14,shift);
   stop =NormalizeDouble(TrStopLevel+atr*ATRmultiplier,MarketInfo(Symbol(),MODE_DIGITS));
   }
   else stop =NormalizeDouble(TrStopLevel+StopPips*Point,MarketInfo(Symbol(),MODE_DIGITS));
if (ObjectFind(TimeToStr(Time[shift]))>-1) ObjectDelete(TimeToStr(Time[shift])); 
ObjectCreate(TimeToStr(Time[shift]),OBJ_TREND,0,Time[shift+1],stop,Time[shift],stop);
ObjectSet(TimeToStr(Time[shift]),OBJPROP_RAY,0);
ObjectSet(TimeToStr(Time[shift]),OBJPROP_COLOR,DodgerBlue);
ObjectSet(TimeToStr(Time[shift]),OBJPROP_WIDTH,2);

SetIndexValue2(shift, TrStopLevel);
Comment(stop);
//Alert("Sell");
}


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

  return(0);
}

Comments