Stop_reversal_bluestops

Download script
Author: Dominic.
Stop_reversal_bluestops

This tool is designed to identify specific price reversal points on a trading chart by tracking the momentum and structural "levels" of price movement. Instead of simply looking at individual price candles, the logic focuses on how the market behaves relative to previous price trends to determine when a shift in direction is likely occurring.

Core Logic Overview

The script operates by maintaining a dynamic "Stop Level." This level acts as a moving boundary that adjusts based on whether the price is currently trending upward, downward, or moving sideways. By constantly recalculating this level, the tool attempts to identify the "breaking point" where a trend might exhaust itself and reverse.

How the Trend Tracking Works

The logic evaluates the relationship between the current price and the previous price points:

  • Trend Continuation: If the price is consistently moving in one direction (up or down), the tool adjusts the internal Stop Level to follow that movement, incorporating a small buffer (calculated in pips) to ensure it doesn't react to minor noise.
  • Price Stagnation: If the price remains unchanged, the tool holds the current level steady.
  • Directional Shifts: The script specifically looks for instances where the price moves against its previous momentum. It identifies these moments as potential reversal zones.

Signal Generation and Visuals

When the market price crosses over the calculated Stop Level in a way that suggests a change in trend, the tool triggers visual signals:

  1. Reversal Detection: The script checks if the current price has successfully breached the established boundary while the previous candle showed a move in the opposite direction.
  2. Dynamic Stop Calculation: Depending on your settings, the "Stop" point (the blue line shown on the chart) can be calculated in two ways:
    • Fixed Pip Buffer: A consistent distance based on a set number of pips.
    • ATR Adjustment: A more sophisticated method that uses the Average True Range (ATR). This adjusts the distance based on current market volatility—widening the lines during high activity and tightening them during calm periods.
  3. Visual Indicators: Once a reversal is confirmed, the tool places visual markers (arrows) and trend lines on the chart to highlight exactly where the logic detected a potential entry point for a trade.

Summary of Purpose

Essentially, this script automates the process of "trailing" price action. It filters out minor fluctuations to find significant structural breaks in the market, providing traders with a visual cue of when a trend has likely flipped from bullish to bearish, or vice versa.

Indicators Used
Indicator of the average true range
Miscellaneous
Implements a curve of type %1
10 Views
1 Downloads
0 Favorites
Stop_reversal_bluestops
//+------------------------------------------------------------------

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