High_Low v2 (ZigZag)_v3
Download scriptThis script is designed to analyze price action on a trading chart to identify significant structural turning points, specifically highlighting the "peaks" and "valleys" where the market changes direction. It functions similarly to a trend-tracking tool that filters out minor market noise to show you the broader flow of price movements.
How the Logic Works
1. Scanning for Significant Price Points The tool looks back through historical data (starting from a specific point in the past) and examines small "windows" of price action. Instead of reacting to every tiny tick or movement, it compares the current price against a set length of previous bars. This allows the script to distinguish between a minor fluctuation and a meaningful high or low point.
2. Identifying Market "Swings" The core logic focuses on identifying shifts in momentum. It categorizes price movements into three types:
- Upward Momentum: When the price establishes a new local high.
- Downward Momentum: When the price establishes a new local low.
- Complex Reversals: When a bar manages to create both a new high and a new low simultaneously, indicating a period of high volatility or a transition phase.
3. Tracking Trend Continuity As the script moves forward in time, it keeps track of which direction the "swing" is currently heading. If the price continues to move in the same direction (making higher highs or lower lows), the script maintains its current state. However, once the price breaks out in the opposite direction beyond a certain threshold, the script recognizes this as a structural change and captures that new coordinate.
4. Mapping the Visual Results Once these significant peaks and valleys are identified, the tool stores their exact positions and prices. Finally, it draws a continuous line (a "section") across your chart connecting these points.
Summary for the Trader
Essentially, this tool acts as a visual guide that cleans up the "messy" price data. By connecting only the most significant highs and lows, it helps you visualize the underlying structure of the market—making it easier to see where trends are forming, where they might be exhausting, and how the market has transitioned from one movement to the next.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| 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