High_Low v2 (ZigZag)_003

Download script
Author: rewritten by CrazyChart
High_Low v2 (ZigZag)_003

This script is designed to analyze historical price movements and visually map out significant trend reversals on a trading chart. Rather than showing every tiny fluctuation in price, it focuses on identifying major "peaks" and "valleys," creating a structured path that helps traders see the broader direction of the market.

How the Logic Works

The tool functions by scanning through past price data to identify structural turning points. Here is the step-by-step breakdown of its internal logic:

1. Data Scanning & Neighborhood Analysis The script looks at a specific window of recent candles (defined by the "Length" setting) to determine the relative high and low points. By looking at these surrounding bars, it can differentiate between minor price noise and meaningful price movements.

2. Identifying Swing Points As the script moves backward through the chart history, it categorizes price action into three states:

  • Upward Movement: When a new high is established compared to its neighbors.
  • Downward Movement: When a new low is established compared to its neighbors.
  • Reversal Points: The specific moments where the trend switches from up to down, or vice versa.

3. Trend Tracking and Peak Capture The script maintains a "memory" of the current active trend. While moving through the data:

  • If it identifies an upward trend, it keeps track of the highest point reached during that specific move.
  • If it identifies a downward trend, it keeps track of the lowest point reached during that move.
  • When a reversal occurs, it "locks in" the extreme point (the peak or the valley) from the previous move and prepares to track the new direction.

4. Visual Mapping Once the script identifies these significant turning points, it maps them onto the chart as a continuous line segment. This creates a "ZigZag" style visual that connects the major highs and lows.

Summary for the User

Essentially, this script cleans up the "messy" price action of a chart. It ignores the small, insignificant wiggles and draws a clear line connecting the important structural peaks and valleys. This allows you to see the core architecture of the market trend more clearly, making it easier to identify support, resistance, and overall momentum.

Miscellaneous
Implements a curve of type %1
9 Views
0 Downloads
0 Favorites
High_Low v2 (ZigZag)_003
//+------------------------------------------------------------------+
//|                                         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];
   } 


ObjectSetText( "PRASXZ" , 9, "Arial", Yellow );


   return(0);
  }
//+------------------------------------------------------------------+

Comments