5_bar
Download scriptThis custom trading indicator is designed to identify potential momentum shifts and price reversals by analyzing specific patterns in historical price action. It operates by comparing a recent "active" window of price movement against a "reference" window that occurred slightly further back in time.
How the Logic Works
The tool scans the market history to find specific price extremes—specifically, the highest highs and the lowest lows—over a set period (defaulting to 5 bars). It then compares these values between two consecutive periods:
1. The "Sell" Signal (Bearish Reversal) The indicator looks for a scenario where the current price action shows a significant break in structure. Specifically, it identifies a situation where:
- The highest point of the most recent price movement is higher than the highest point of the previous period.
- The current closing price has dropped below the lowest point of that same previous period.
When both these conditions are met simultaneously, the script recognizes a potential "breakdown" and places a red arrow on the chart to signal a sell opportunity.
2. The "Buy" Signal (Bullish Reversal) Conversely, the tool looks for an upward breakout in price structure. It triggers a signal when:
- The lowest point of the most recent price movement is lower than the lowest point of the previous period.
- The current closing price has risen above the highest point of that previous period.
When these conditions align, indicating that the price has "broken out" of its prior range, the script places a yellow arrow on the chart to signal a buy opportunity.
Summary for the Trader
Essentially, this tool acts as a breakout detector. It ignores minor fluctuations and only highlights instances where the price has moved aggressively enough to exceed the boundaries established by the preceding 5 bars of trading. By visualizing these levels with arrows, it helps traders identify moments where the market may be shifting from one trend to another or exhausting its previous range.
//+------------------------------------------------------------------+
//| 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 1
#property indicator_color2 Yellow
#property indicator_width2 1
extern int NrOfBars=500;
extern int bars1 = 5;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double fhigh;
double flow;
double fclose;
double shigh;
double slow;
double sclose;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_ARROW,4);
SetIndexArrow(0,218);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexEmptyValue(0,EMPTY_VALUE);
SetIndexStyle(1,DRAW_ARROW,4);
SetIndexArrow(1,217);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexEmptyValue(1,EMPTY_VALUE);
//----
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<=NrOfBars;i++)
{
shigh=High[iHighest(NULL, 0,2,bars1,i)];
slow=Low[iLowest(NULL,0,1,bars1,i)];
sclose=Close[i];
fhigh=High[iHighest(NULL, 0, 2, bars1, (i+bars1))];
flow=Low[iLowest(NULL,0,1,bars1,(i+bars1))];
fclose=Close[i+bars1];
if ((shigh>fhigh) && (sclose<flow))
{//SELL
ExtMapBuffer1[i+5]=High[i+5]+0.0005;
}
if ((slow<flow) && (sclose>fhigh))
{//BUY
ExtMapBuffer2[i+5]=Low[i+5]-0.0005;
}
//Print(ExtMapBuffer2[i+5]);
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments