High_Low v2 (ZigZag)_v2
Download scriptThis script is designed to identify and map significant price structural points—specifically "swing" highs and lows—on a trading chart. It simplifies the complex movement of market price into a clear visual path by focusing on historical extremes rather than every minor fluctuation.
Core Logic Overview
The tool operates by scanning through historical price data to detect significant turning points. It distinguishes between three types of price movements:
- Highs: When the price reaches a peak that is higher than its immediate surroundings.
- Lows: When the price drops to a trough that is lower than its immediate surroundings.
- Swing Points: These are the "pivot" points where the price trend changes direction. The script specifically tracks these transitions to establish the backbone of the market structure.
How the Analysis Works
- Neighborhood Evaluation: To ensure the script doesn't react to every tiny "wiggle" in the price, it examines a specific window of nearby candles (defined by the "Length" setting). It determines if a current price point is a true local maximum or minimum compared to its neighbors.
- Trend Identification: The logic continuously monitors whether the current price is moving toward creating a new high or a new low. If the price breaks out beyond the previously established boundaries, the script updates its internal tracking to recognize a potential change in direction.
- Point Recording: Whenever the script identifies a confirmed shift (e.g., from an upward move to a downward move), it captures the exact coordinates of that peak or valley.
- Visual Mapping: Finally, the script takes all these identified structural points and draws them as a connected sequence on your chart. Instead of showing you every single price candle, it creates a visual "pathway" that connects the most important highs and lows.
Summary for Traders
Essentially, this script acts as an automated "trend mapper." It filters out market noise to highlight the primary structure of the market. By connecting these significant highs and lows, it helps traders visualize the overall flow of price action, making it easier to identify major support and resistance zones or structural shifts in the market trend.
//+------------------------------------------------------------------+
//| High_Low v2 (ZigZag).mq4 |
//| rewritten by CrazyChart |
//| |
//+------------------------------------------------------------------+
#property copyright "rewritten by CrazyChart"
#property link ""
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Blue
//---- 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);
//----
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