StopReversalv2Alert

Download script
Author: Dominic.
StopReversalv2Alert

The Stopreversal Mt4 script is a specialized technical analysis tool designed to identify specific momentum shifts and potential price reversals in the trading market. Its primary purpose is to track a dynamic "stop level" and notify traders when the current market price breaks through this threshold, signaling a change in trend direction.

Core Logic Overview

The script works by constantly monitoring the closing prices of candles to calculate a trailing "Stop Level." Rather than using standard indicators like Moving Averages, it focuses on the relationship between the current price and the previous price levels. It builds a logical boundary that follows the market's movement, adjusting itself based on whether the price is trending upwards or downwards.

How the Calculation Works

The script evaluates the price action based on four distinct scenarios to determine where the next "Stop Level" should be placed:

  1. Static Price: If the current closing price remains unchanged from the previous price, the stop level stays exactly where it was.
  2. Downward Trend: If the price is moving lower than the previous levels, the script calculates a new stop level by taking the lower of the previous value or the current price plus a small defined buffer (Pips). This helps "lock in" the downward momentum.
  3. Upward Trend: Conversely, if the price is climbing higher, the script calculates the stop level as the higher of the previous value or the current price minus a small buffer. This tracks the upward momentum.
  4. Directional Shifts: If the price moves in an unpredictable way (e.g., a sudden jump that doesn't follow the immediate preceding trend), the script automatically adjusts the stop level to stay slightly behind the current price movement to ensure the "trap" or "stop" is always relevant to the new price action.

Visual and Interactive Features

To make this information useful for a trader, the script provides several visual and notification layers:

  • On-Chart Visuals: It plots specific markers (arrows) on the chart at the exact points where a reversal signal occurs. It also draws a dotted line representing the current Stop Level, allowing traders to see the "boundary" in real-time.
  • Real-Time Alerts: The tool is designed to be proactive. When the market price crosses above or below the calculated Stop Level, it can trigger several types of notifications:
    • Audible Alerts: A sound file plays to grab the trader's attention immediately.
    • Pop-up Notifications: A visual alert box appears on the trading platform.
    • Email Notifications: If enabled, the script can send an automated email with the specific details of the reversal signal.

Summary for Traders

In essence, this script acts as a dynamic "tripwire." By constantly recalculating where a trend's "breaking point" sits, it filters out minor market noise and alerts you only when the price makes a significant enough move to potentially indicate a reversal in the current market direction.

Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screenIt plays sound alertsIt sends emails
11 Views
0 Downloads
0 Favorites
StopReversalv2Alert
//+------------------------------------------------------------------
//|                                            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 1 
#property indicator_color2 Orange
#property indicator_width2 1
#property indicator_color3 Magenta
#property indicator_width3 0

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


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

extern double nPips = 0.0008;
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(3);
   SetIndexStyle(0, DRAW_ARROW, STYLE_SOLID);
   SetIndexArrow(0, 159);
   SetIndexBuffer(0, ExtHistoBuffer);
   SetIndexStyle(1, DRAW_ARROW, STYLE_SOLID);
   SetIndexArrow(1, 159);
//   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