ZigXard-Pointer-V3
Download scriptThis script is designed to identify and visualize significant price movements on a trading chart by highlighting key "peaks" (highs) and "valleys" (lows). It acts as a structural filter, helping traders see the general direction of the market by connecting important turning points while ignoring minor market noise.
Core Functionality
The logic operates by scanning historical price data to find extreme points that meet specific criteria defined by the user (Depth, Deviation, and Backstep). Instead of marking every single price fluctuation, it filters out small movements to ensure only substantial trend shifts are highlighted.
How the Logic Works
1. Identifying Extreme Points The script continuously scans the price history looking for the highest and lowest points within a specific look-back window (the "Depth"). It evaluates these points based on how much they differ from the surrounding price action (the "Deviation"). If a price move is too small, the script ignores it; if it is significant enough, it marks it as a potential turning point.
2. Filtering and Smoothing To prevent the chart from becoming cluttered with too many markers, the logic uses a "Backstep" mechanism. This ensures that if several high or low points occur very close to each other in time, the script only recognizes the most significant one. This creates a cleaner, more readable path for the user to follow.
3. Dynamic Refinement (The "ZigZag" Effect) One of the most important features of this logic is its ability to self-correct as new data arrives. The script performs a multi-pass review of the identified peaks and valleys:
- Peak Comparison: If the script identifies a new high that is higher than a previously recorded high, it "cuts" or removes the previous point so that only the absolute highest peak remains in that sequence.
- Valley Comparison: Similarly, if it finds a new low that is lower than a previous one, it updates the path to reflect the true bottom of that price swing.
4. Visual Representation The final result is a series of visual markers on your chart. By identifying these structural "swings," the script allows you to see the skeleton of the market trend—showing you where the price has successfully reversed and where the momentum is currently heading.
//+------------------------------------------------------------------+
//| zigzag-pointer.mq4 |
//| zigzag modified by Dr. Gaines |
//| dr_richard_gaines@yahoo.com |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "dr_richard_gaines"
#property link "http://www.metaquotes.net/"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_width1 5
#property indicator_color2 Lime
#property indicator_width2 5
//---- indicator parameters
extern int ExtDepth=115;//105;//21;
extern int ExtDeviation=130;//120;//24;
extern int ExtBackstep=80;//70;//14;
//---- indicator buffers
double ZigZagUp[];
double ZigZagDown[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(2);
//---- drawing settings
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0, 233);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1, 234);
//---- indicator buffers mapping
SetIndexBuffer(0,ZigZagUp);
SetIndexBuffer(1,ZigZagDown);
SetIndexEmptyValue(0,0.0);
SetIndexEmptyValue(1,0.0);
//---- indicator short name
IndicatorShortName("ZigZag("+ExtDepth+","+ExtDeviation+","+ExtBackstep+")");
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
int shift, back,lasthighpos,lastlowpos;
double val,res;
double curlow,curhigh,lasthigh,lastlow;
for(shift=Bars-ExtDepth; shift>=0; shift--)
{
val=Low[Lowest(NULL,0,MODE_LOW,ExtDepth,shift)];
if(val==lastlow) val=0.0;
else
{
lastlow=val;
if((Low[shift]-val)>(ExtDeviation*Point)) val=0.0;
else
{
for(back=1; back<=ExtBackstep; back++)
{
res=ZigZagUp[shift+back];
if((res!=0)&&(res>val)) { ZigZagUp[shift+back]=0.0; }
}
}
}
ZigZagUp[shift]=val;
//--- high
val=High[Highest(NULL,0,MODE_HIGH,ExtDepth,shift)];
if(val==lasthigh) val=0.0;
else
{
lasthigh=val;
if((val-High[shift])>(ExtDeviation*Point)) val=0.0;
else
{
for(back=1; back<=ExtBackstep; back++)
{
res=ZigZagDown[shift+back];
if((res!=0)&&(res<val)){ ZigZagDown[shift+back]=0.0; }
}
}
}
ZigZagDown[shift]=val;
}
// final cutting
lasthigh=-1; lasthighpos=-1;
lastlow=-1; lastlowpos=-1;
for(shift=Bars-ExtDepth; shift>=0; shift--)
{
curlow=ZigZagUp[shift];
curhigh=ZigZagDown[shift];
if((curlow==0)&&(curhigh==0)) continue;
//---
if(curhigh!=0)
{
if(lasthigh>0)
{
if(lasthigh<curhigh)
{
ZigZagDown[lasthighpos]=0;
}
else ZigZagDown[shift]=0;
}
//---
if(lasthigh<curhigh || lasthigh<0)
{
lasthigh=curhigh;
lasthighpos=shift;
}
lastlow=-1;
}
//----
if(curlow!=0)
{
if(lastlow>0)
{
if(lastlow>curlow)
{
ZigZagUp[lastlowpos]=0;
}
else ZigZagUp[shift]=0;
}
//---
if((curlow<lastlow)||(lastlow<0))
{
lastlow=curlow;
lastlowpos=shift;
}
lasthigh=-1;
}
}
for(shift=Bars-1; shift>=0; shift--)
{
if(shift>=Bars-ExtDepth) ZigZagUp[shift]=0.0;
else
{
res=ZigZagDown[shift];
if(res!=0.0) ZigZagDown[shift]=res;
}
}
}
//end//
Comments