High_Low_v2_ZigZag_v1

Download script
Author: rewritten by CrazyChart
High_Low_v2_ZigZag_v1

This custom indicator is designed to identify and visualize significant structural turning points in price action. By analyzing historical market data, it filters out minor price fluctuations (market "noise") to highlight the most important high and low peaks, creating a continuous path that represents the core trend of the asset.

Core Logic and Mechanism

The script functions by performing a comprehensive scan of the historical chart, starting from a user-defined point in the past and moving forward to the present. It operates using the following logic:

1. Trend Identification (Swing Detection) The tool evaluates price movements based on a specific "Length" window. For every bar on the chart, it looks at the surrounding candles to determine if the current price is reaching a new local peak or a new local valley.

  • If the price breaks significantly higher than the recent high, it identifies an upward movement.
  • If the price breaks significantly lower than the recent low, it identifies a downward movement.
  • If the price moves in both directions simultaneously relative to its neighbors, it marks that specific point as a significant "pivot."

2. Peak and Valley Tracking As the script moves through the data, it maintains a memory of the highest and lowest points reached during a specific trend.

  • When the market is moving upward, the script continuously updates its "Highest Point" memory. If a new high is reached, it records that exact position.
  • When the market is moving downward, it continuously updates its "Lowest Point" memory. If a new low is reached, it records that exact position.

3. Filtering and Data Selection The logic ensures that only the most extreme points are captured. Instead of drawing a line for every single price tick, it waits until a trend actually reverses. Once a reversal is confirmed (e.g., the price stops moving up and begins to move down), the script takes the highest point recorded during that upward stretch and connects it to the previous low.

4. Visual Representation The final output is a continuous line drawn on your chart window. This line connects the "peaks" of upward moves and the "valleys" of downward moves. By doing this, it provides a cleaned-up visual representation of the market's structure, making it easier for a trader to see the overall "skeleton" of the price action without being distracted by small, insignificant fluctuations.

Miscellaneous
Implements a curve of type %1
14 Views
1 Downloads
0 Favorites
High_Low_v2_ZigZag_v1
//+------------------------------------------------------------------+
//|                                         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