High_Low_v2_ZigZag

Download script
Author: rewritten by CrazyChart
High_Low_v2_ZigZag

This script is designed to identify and visualize significant price turning points—specifically high and low peaks—on a trading chart. It functions by filtering out minor market noise to highlight the primary structural movements of the asset.

Core Logic and Behavior

The tool operates by scanning historical price data to determine which price points are "significant" enough to be considered a structural high or low. Here is a breakdown of how it processes information:

1. Trend Filtering (The "Lookback" Mechanism) Instead of reacting to every single price tick, the script looks at a specific window of recent candles (defined by the user's length settings). It constantly compares the current candle's high and low against this surrounding neighborhood. This ensures that a small, insignificant wiggle in price doesn't trigger a signal unless it stands out as a distinct peak or valley relative to its immediate surroundings.

2. Swing Identification The logic continuously tracks the direction of the market movement. It classifies price action into three primary states:

  • Upward Momentum: Identifying points where the price is pushing higher.
  • Downward Momentum: Identifying points where the price is pushing lower.
  • Reversal Points: Detecting the exact moment the momentum switches from up to down, or vice versa.

3. Peak and Valley Tracking As the script moves through the history of the chart, it "remembers" the highest and lowest points reached during a specific trend. If a new price point is discovered that is even higher (during an uptrend) or lower (during a downtrend) than the previous peak/valley, the script updates its internal memory to ensure it captures the absolute extreme of that movement.

4. Data Mapping and Visualization Once the script identifies a confirmed structural peak or valley, it stores the coordinates of these points. It then maps these values back onto the chart as a continuous line (a section drawing). This allows traders to see a visual "skeleton" of the market’s price action, clearly connecting the major highs and lows in a sequence.

Summary for the User

Essentially, this script acts as an automated "trend tracer." It ignores the chaotic small movements of the market and draws a line connecting the most important high and low points. By doing this, it provides a clearer picture of the overall market structure, helping you see where the price has turned and how the primary waves are moving.

Miscellaneous
Implements a curve of type %1
11 Views
0 Downloads
0 Favorites
High_Low_v2_ZigZag
//+------------------------------------------------------------------+
//|                                         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=3000;
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