5 bar reversal v1[real][1].5
Download scriptThis tool is designed to analyze price action on a trading chart to identify potential trend reversals by comparing current market extremes against historical peaks and valleys. Rather than looking at simple moving averages, the logic focuses on identifying specific structural "breaks" in price momentum over a 5-bar window.
Core Logic Overview
The script continuously scans the price history to evaluate the relationship between current high/low prices and previous price levels. It essentially looks for moments where the market has "stretched" significantly enough to suggest that a change in direction is imminent.
How it Identifies Opportunities
The indicator looks for two distinct scenarios:
1. Sell Signal Identification (Bearish Reversal) The logic triggers a sell alert when the following conditions are met simultaneously:
- Price Peak: The highest price reached in the current recent period is significantly higher than the highest price reached in the preceding period.
- Price Drop: The current closing price has dropped below the lowest point of that previous period.
- Result: When these two conditions align, it suggests that the upward momentum has exhausted and the price is breaking downward, prompting a visual red arrow on the chart and an audible alert.
2. Buy Signal Identification (Bullish Reversal) Conversely, the logic triggers a buy alert when the opposite structural shift occurs:
- Price Floor: The lowest price reached in the current recent period is significantly lower than the lowest point of the preceding period.
- Price Rise: The current closing price has risen above the highest price of that previous period.
- Result: This indicates that the downward pressure has bottomed out and the price is breaking upward, triggering a visual yellow arrow and an alert.
Key Features for the User
- Visual Guidance: The script places distinct arrows (Red for Sell, Yellow for Buy) directly on your chart to highlight these structural reversals in real-time.
- Automated Alerts: To ensure you don't miss a potential move, the tool provides an instant notification pop-up and sound alert specifically when a new signal is detected on the current candle.
- Duplicate Prevention: The logic includes a "time filter" to ensure that it only alerts you once per bar, preventing multiple redundant notifications for the same price movement.
- Historical Analysis: Because the script scans back through historical data, it allows you to review past performance and see how accurately these structural breaks have signaled reversals in different market conditions.
//+------------------------------------------------------------------+
//| 5 Bars.mq4 |
//| Copyright © 2006, EvgeniX |
//|
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, EvgeniX"
#property link "EvgeniX"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_width1 3
#property indicator_color2 Yellow
#property indicator_width2 3
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double fhigh;
double flow;
double fclose;
double shigh;
double slow;
double sclose;
double ttfn;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_ARROW,4);
SetIndexArrow(0,218);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexEmptyValue(0,0.0);
SetIndexStyle(1,DRAW_ARROW,4);
SetIndexArrow(1,217);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexEmptyValue(1,0.0);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
//----
//for(int i=1 ;i<=500;i++)
for(int i=50000; i>0; i--)
{
//Comment (i);
shigh=High[Highest(NULL, 0,2,5,i)];
slow=Low[Lowest(NULL,0,1,5,i)];
sclose=Close[i];
fhigh=High[Highest(NULL, 0, 2, 5, (i+5))];
flow=Low[Lowest(NULL,0,1,5,(i+5))];
fclose=Close[i+9];
//ExtMapBuffer2[i+5]=High[i]+0.0005;
//ExtMapBuffer1[i]=High[i]+0.0005;
Comment (i);
if ((shigh>fhigh) && (sclose<flow))
{
ExtMapBuffer1[i]=High[i+5]+0.0005;
if (i==1 && !ttfn )Alert ("5Bar Reverse S E L L ", Symbol()," M",Period());
{
ttfn=Time[0];
}
}
if ((slow<flow) && (sclose>fhigh))
{
ExtMapBuffer2[i]=Low[i+5]-0.0005;
{
if (i==1 && !ttfn ) Alert ("5Bar Reverse B U Y ", Symbol()," M",Period());
ttfn=Time[0];
}
}
// Comment(Close[i+4]+" "+" "+DoubleToStr(i,1)+" "+TimeToStr(Time[i],TIME_MINUTES)+
// "\n"+" "+shigh+" "+slow+" "+sclose+
// "\n"+" "+fhigh+" "+flow+" "+fclose);
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments