StopReversalAlert
Download scriptThe Stopreversal Mt4 script is a technical analysis tool designed to identify specific price action shifts and potential trend reversals on a trading chart. Rather than simply following the current price, this logic focuses on "Stop Levels"—imaginary thresholds that represent points where market momentum might change or where previous trends are likely to be exhausted.
Core Logic Overview
The script functions by tracking the historical progression of price movements to establish a dynamic resistance or support level (referred to in the code as the TrStopLevel). It evaluates how the current price relates to these levels to determine when a reversal is occurring.
How the Logic Works:
- Dynamic Level Tracking: The script continuously monitors the closing prices of candles. It builds a memory of previous price points to decide where the "Stop Level" should sit. Depending on whether the market is moving upward or downward, it adjusts this level slightly using a user-defined sensitivity factor (Pips).
- Trend Identification:
- If the market is consistently moving in one direction, the script calculates a threshold that anticipates where a move might "stop" or turn around.
- It accounts for different scenarios: steady climbs, steady declines, and sudden price spikes. In each scenario, it applies a small buffer to ensure it isn't reacting to minor market noise, but rather significant shifts in momentum.
- Reversal Detection: The primary goal of the script is to identify "Crosses." It looks for specific conditions where:
- The current price breaks through a previously established threshold.
- The price movement confirms a change in direction relative to the previous price history.
- Visual and Audio Feedback: When the logic detects a "Cross Up" (potential bullish reversal) or a "Cross Down" (potential bearish reversal), it provides immediate feedback to the user:
- Visuals: It places specific markers (arrows) on the chart at the exact point of the reversal.
- Alerts: It triggers an on-screen notification and plays an audio sound to notify the trader in real-time.
- Communication: If configured, it can also send an automated email notification, ensuring the user is alerted even if they are not looking directly at the screen.
Summary for the User
Essentially, this script acts as a "tripwire" system. It analyzes the history of price action to draw invisible lines where the market is likely to struggle. When the price manages to break through these lines in a specific way, the script alerts you that a trend reversal may be occurring, allowing for more proactive trading decisions based on momentum shifts.
//+------------------------------------------------------------------
//| 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 4
#property indicator_color2 Orange
#property indicator_width2 4
//+------------------------------------------------------------------
//| 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 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, 159);
SetIndexStyle(1, DRAW_ARROW, STYLE_SOLID);
SetIndexArrow(1, 159);
// SetIndexBuffer(0, ExtHistoBuffer);
SetIndexBuffer(0, ExtHistoBuffer);
SetIndexBuffer(1, ExtHistoBuffer2);
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);
}
}
}
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 ((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