stopreversal_v2

Download script
Author: Dominic.
stopreversal_v2

This script is designed as a visual trading tool that identifies specific price reversal points on a chart. It works by tracking the historical movement of prices and calculating dynamic "Stop Levels" to signal potential shifts in market momentum.

Core Logic Overview

The indicator scans the market history from older candles to the most recent ones, analyzing how the closing price of each candle relates to the previous one. Its primary goal is to determine the trend's direction and identify the exact moment when that trend breaks or reverses.

How the Calculations Work

The script uses a specific set of rules to establish a reference level (the Stop Level) based on current market conditions:

  • Stability Tracking: If the price remains unchanged between candles, the script maintains the previous reference level.
  • Downward Momentum: When prices are falling consistently, the logic calculates a downward target by looking at the lowest point reached, adjusted by a small user-defined buffer (pips).
  • Upward Momentum: When prices are rising consistently, it calculates an upward target based on the highest points reached, also adjusted by the specified buffer.
  • Directional Shifts: If the price switches from falling to rising (or vice versa), the script resets the reference level to the current price point plus or minus that small buffer to adapt to the new movement.

Visual Signals

The ultimate purpose of this logic is to provide clear visual cues on your chart:

  1. Buy Signals: The script looks for a specific "reversal" pattern where the current price climbs above a calculated downward Stop Level, following a period of decline. When this happens, it marks the spot with a Lime (Green) arrow.
  2. Sell Signals: Conversely, if the price drops below a calculated upward Stop Level after a period of growth, it marks the spot with a Red arrow.

Summary for the User

Instead of just following a moving average or a simple trend line, this tool focuses on "price action." It creates a trailing boundary that moves with the market; when the price breaks through that boundary in the opposite direction of the prevailing trend, the script interprets this as a high-probability reversal point and alerts you visually.

Miscellaneous
Implements a curve of type %1
13 Views
0 Downloads
0 Favorites
stopreversal_v2
/*-----------------------------+
|			       |
| 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 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