This script is a visual trading tool designed to help identify specific momentum shifts and price patterns by analyzing the relationship between current price action and historical data. Instead of following every minor fluctuation, it looks for distinct "breakout" behaviors over a set window of time (specifically looking back at groups of 5 bars).
How the Logic Works
The script scans the market history to compare two different periods: the most recent five bars and the five bars that immediately preceded them. By looking at these two snapshots, it attempts to identify specific conditions for buying and selling opportunities.
Identifying Sell Signals The tool looks for a "bearish" exhaustion or reversal pattern. It triggers a visual signal when:
- The highest price reached in the current period is higher than the high of the previous period (showing strength).
- AND the closing price of the current bar finishes significantly lower than the lowest point of the previous period. Essentially, it flags moments where the price made a high peak but then "collapsed" back down below the previous low.
Identifying Buy Signals Conversely, the tool looks for "bullish" momentum patterns. It triggers a visual signal when:
- The lowest price reached in the current period is lower than the low of the previous period (showing a dip).
- AND the closing price of the current bar finishes higher than the high of the previous period. This identifies moments where the price dipped to a new low but then "surged" upward to break past the previous high.
Visual Representation
Rather than appearing on the main price chart, this script operates in a separate window below your main chart. It uses two distinct colors to highlight these signals:
- Red: Represents the identified sell conditions.
- Yellow: Represents the identified buy conditions.
By visualizing these specific price breaks as histograms, the tool allows traders to quickly see where significant volatility or trend shifts occurred relative to recent history, filtering out the "noise" of everyday minor movements.
//+------------------------------------------------------------------+
//| 5 Bars.mq4 |
//| Copyright © 2006, EvgeniX |
//|
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, EvgeniX"
#property link "EvgeniX"
//----
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_width1 1
#property indicator_color2 Yellow
#property indicator_width2 1
#property indicator_level1 0
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_HISTOGRAM);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexEmptyValue(0,EMPTY_VALUE);
SetIndexStyle(1,DRAW_HISTOGRAM);
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]=-1;//High[i+5]+0.0005;
}
if ((slow<flow) && (sclose>fhigh))
{//BUY
ExtMapBuffer2[i+5]=1;//Low[i+5]-0.0005;
}
// Print(ExtMapBuffer2[i+5]);
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments