StopReversalv2alert_001

Download script
Author: Dominic.
StopReversalv2alert_001

Technical Logic Overview: Stopreversal Indicator

The Stopreversal tool is designed to identify specific structural shifts in market momentum by tracking price behavior relative to previous historical levels. Instead of simply following the current trend, the logic focuses on "reversals"—identifying moments when the price breaks through established resistance or support boundaries to signal a potential change in direction.

Core Logic and Price Tracking

The script functions by constantly monitoring the relationship between the current closing price and the previous price point. It maintains a dynamic "Stop Level" that evolves based on four distinct market behaviors:

  • Stability: If the price remains unchanged from the previous close, the stop level stays constant.
  • Consistent Downtrend: If the price drops consecutively, the logic calculates a new stop level by taking the lower of the previous level or a small percentage (defined by the user as nPips) below the current price.
  • Consistent Uptrend: If the price rises consecutively, it establishes a new stop level at the higher of the previous level or a small percentage above the current price.
  • Momentum Shifts: If the price changes direction from the previous bar (moving from down to up or vice versa), the script resets the stop level to a position slightly offset from the current price in the opposite direction.

Signal Generation

The primary goal of this script is to detect "crosses." A signal is triggered when the price moves across the calculated Stop Level in a way that confirms a momentum shift:

  1. Upside Reversal (Buy Signal): This occurs when the current price closes above the Stop Level, while the previous candle's close was below the prior price point. This indicates that the price has "broken out" upward with enough strength to overcome the established resistance.
  2. Downside Reversal (Sell Signal): This occurs when the current price closes below the Stop Level, while the previous candle's close was above the prior price point. This suggests a breakdown through support.

Visual and Alert Features

To assist the trader, the script provides three layers of feedback:

  • Visual Markers: It places specific icons (arrows) on the chart at the exact moment a reversal is detected, allowing for easy historical analysis.
  • Reference Lines: It draws a dotted line representing the Stop Level to help traders visualize the "boundary" the price is currently interacting with.
  • Real-Time Notifications: The script can be configured to provide immediate feedback via on-screen alerts and audible sounds. If enabled, it can also send an email notification to the user, providing a secondary way to monitor the market while away from the trading terminal.
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screenIt plays sound alertsIt sends emails
10 Views
0 Downloads
0 Favorites
StopReversalv2alert_001
//+------------------------------------------------------------------
//|                                            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

#property indicator_color3 Magenta
#property indicator_width3 1

//+------------------------------------------------------------------
//| Common External variables                                        
//+------------------------------------------------------------------


//+------------------------------------------------------------------
//| External variables                                               
//+------------------------------------------------------------------

extern double nPips = 0.001;
extern bool      Alerts = true;
extern bool      Email = false;

//+------------------------------------------------------------------
//| Special Convertion Functions                                     
//+------------------------------------------------------------------


int LastTradeTime;
//static datetime dt = 0;
double ExtHistoBuffer[];
double ExtHistoBuffer2[];
int up=0,dn=0;
double LBuffer[];
double SBuffer[];
int above = 0;
int below = 0;

void SetLoopCount(int loops)
{
}

void SetIndexValue(int shift, double value)
{
  ExtHistoBuffer[shift] = value;
  //     if ((Alerts == true) && (dt != iTime(NULL,0,0))) //&& (Close[0]==Close[shift]))
//         {
//               Alert(Symbol(), " M", Period(), " Stopreversal has crossed up");
//               PlaySound("timeout.wav");
//               if (Email == true)
//                   {
//                      SendMail(Symbol()+" "+OrderComment(),"Stopreversal crossed up");
//                   }
//               dt = iTime(NULL,0,0);
//               above=1;
//               below=0;
//         }
}

void SetIndexValue2(int shift, double value)
{
  ExtHistoBuffer2[shift] = value;
//    if ((Alerts == true) && (dt != iTime(NULL,0,0))) //&& (Close[0]==Close[shift]))
//         {
//               Alert(Symbol(), " M", Period(), " Stopreversal has crossed down");
//               PlaySound("timeout.wav");
//               if (Email == true)
//                   {
//                      SendMail(Symbol()+" "+OrderComment(),"Stopreversal crossed down");
//                   }
//               dt = iTime(NULL,0,0);
//               above=0;
//               below=1;
//         }
}

//+------------------------------------------------------------------
//| End                                                              
//+------------------------------------------------------------------


//+------------------------------------------------------------------
//| Initialization                                                   
//+------------------------------------------------------------------


int init()
{
   IndicatorBuffers(2);
   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(0, ExtHistoBuffer);
   SetIndexBuffer(1, ExtHistoBuffer2);
   SetIndexBuffer(2, LBuffer);
   SetIndexStyle(2, DRAW_LINE, STYLE_DOT);
   
   return(0);
}
int start()
{
//+------------------------------------------------------------------
//| Local variables                                                  
//+------------------------------------------------------------------
  
static datetime dt = 0; 
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);
                  }
      }
}

LBuffer[shift]=TrStopLevel;

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);
   //SetOrder(OP_BUY,1,ask,2,0,ask+TakeProfit*Point,blue);
      if ((Alerts == true) && (dt != iTime(NULL,0,0))&& (ExtHistoBuffer[0]== TrStopLevel))//&& (Close[0]==Close[shift]))
         {
              Alert(Symbol(), " M", Period(), " Stopreversal has crossed up");
               PlaySound("timeout.wav");
               if (Email == true)
                   {
                     SendMail(Symbol()+" "+OrderComment(),"Stopreversal crossed up");
                  }
              dt = iTime(NULL,0,0);
              above=1;
              below=0;
        }
}


if( Close[shift] < TrStopLevel &&  Close[shift+1]>PREV  && PREV != 
0  ) 
{
      //SetOrder(OP_SELL,1,bid,2,0,bid-TakeProfit*Point,Red);
      SetIndexValue2(shift, TrStopLevel);
      if ((Alerts == true) && (dt != iTime(NULL,0,0))&& (ExtHistoBuffer2[0]== TrStopLevel))//&& (Close[0]==Close[shift]))
         {
               Alert(Symbol(), " M", Period(), " Stopreversal has crossed down");
               PlaySound("timeout.wav");
               if (Email == true)
                   {
                     SendMail(Symbol()+" "+OrderComment(),"Stopreversal crossed down");
                  }
              dt = iTime(NULL,0,0);
              above=0;
              below=1;
        }
//Alert("Sell");
}


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

  return(0);
}

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

Comments