High_Low_(ZigZag)
Download scriptThis tool is designed to identify and map significant structural "swings" within a price chart, specifically focusing on high and low price points. It works by filtering out minor market noise to highlight major directional shifts, providing a visual representation of the market's core structure.
Core Logic Overview
The script functions by scanning historical price data to identify extreme peaks and valleys. It doesn't just look at every single price movement; instead, it uses a "look-back" window (defined by the length parameter) to confirm whether a specific point is truly significant compared to its neighbors.
How the Process Works
The logic follows a systematic multi-step approach:
- Neighborhood Analysis: For every point on the chart, the tool examines a surrounding range of bars. It determines the highest high and the lowest low within that specific window.
- Swing Detection: The script then evaluates the current price against those local extremes. If the price creates a new "extreme" (moving outside the established neighborhood boundaries), the tool flags it as a potential swing point.
- Trend Tracking: The logic maintains a memory of the current movement direction. It distinguishes between:
- Upward Swings: Identifying new highs that push the price further up.
- Downward Swings: Identifying new lows that push the price further down.
- Reversal Points: Recognizing when the market stops moving in one direction and begins to pivot toward the opposite side.
- Dynamic Updates: As the script processes the data, it constantly updates its "best" high and low values. If a new peak is reached during an uptrend, it replaces the previous one; if a new floor is reached during a downtrend, it replaces the old one.
Visual Output
Once the logic has identified these critical pivot points, it maps them onto the chart as a connected series of lines (a "ZigZag" style). This allows you to see the underlying "skeleton" of the market movement—the significant levels where price reversed or paused—removing the distraction of small, insignificant fluctuations.
Key Behavior Summary
- Smoothing: It ignores minor price "wiggles" by requiring a certain amount of relative movement before marking a point.
- Structure Mapping: It creates a continuous path of highs and lows, making it easier to see the primary trend of the market.
- Automatic Filtering: By using a look-back window, the script ensures that only substantial price changes are captured as structural points.
//+------------------------------------------------------------------+
//| High_Low (ZigZag).mq4 |
//| rewritten by CrazyChart |
//| |
//+------------------------------------------------------------------+
#property copyright "rewritten by CrazyChart"
#property link ""
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Red
//---- input parameters
extern int barn = 300;
extern int Length=6;
//---- buffers
double ExtMapBuffer1[];
//double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexEmptyValue(0, 0.0);
//SetIndexDrawBegin(0, barn);
SetIndexStyle(0, DRAW_SECTION);
SetIndexBuffer(0, ExtMapBuffer1);
//---- name for DataWindow label
SetIndexLabel(0, "HiLoZZ(" + Length + ")");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars = IndicatorCounted();
int shift, Swing, Swing_n, uzl, i, zu, zd, mv;
double LL, HH, BH, BL, NH, NL;
double Uzel[10000][3];
string text;
// loop from first bar to current bar (with shift=0)
Swing_n = 0;
Swing = 0;
uzl = 0;
BH = High[barn];
BL = Low[barn];
zu = barn;
zd = barn;
//----
for(shift = barn; shift >= 0; shift--)
{
LL = 10000000;
HH = -100000000;
//----
for(i = shift + Length; i >= shift + 1; i--)
{
if(Low[i] < LL)
{
LL=Low[i];
}
if(High[i] > HH)
{
HH = High[i];
}
}
//----
if(Low[shift] < LL && High[shift] > HH)
{
Swing = 2;
//----
if(Swing_n == 1)
{
zu = shift + 1;
}
//----
if(Swing_n == -1)
{
zd = shift + 1;
}
}
else
{
if(Low[shift] < LL)
{
Swing = -1;
}
if(High[shift] > HH)
{
Swing = 1;
}
}
//----
if(Swing != Swing_n && Swing_n != 0)
{
if(Swing == 2)
{
Swing = -Swing_n;
BH = High[shift];
BL = Low[shift];
}
uzl=uzl+1;
//----
if(Swing == 1)
{
Uzel[uzl][1] = zd;
Uzel[uzl][2] = BL;
}
//----
if(Swing == -1)
{
Uzel[uzl][1] = zu;
Uzel[uzl][2] = BH;
}
BH = High[shift];
BL = Low[shift];
}
if(Swing == 1)
{
if(High[shift] >= BH)
{
BH = High[shift];
zu = shift;
}
}
if(Swing == -1)
{
if(Low[shift] <= BL)
{
BL = Low[shift];
zd = shift;
}
}
Swing_n = Swing;
}
for(i = 1; i <= uzl; i++)
{
//text=DoubleToStr(Uzel[i][1],0);
//text=;
mv = StrToInteger(DoubleToStr(Uzel[i][1], 0));
ExtMapBuffer1[mv] = Uzel[i][2];
}
return(0);
}
//+------------------------------------------------------------------+
Comments