High_Low_v2

Download script
Author: rewritten by CrazyChart
High_Low_v2

This script is designed to identify and map significant price movements on a trading chart by detecting structural "swings" in the market. Instead of showing every minor price fluctuation, it filters out noise to highlight the primary highs and lows that define the trend.

How the Logic Works

1. Data Filtering and Neighborhood Analysis The tool looks at the historical price action starting from a specific point in the past (defined by the "barn" setting). For every candle on the chart, it examines a small surrounding window of time (the "Length"). By comparing a candle to its neighbors, the script determines if that specific point represents a local peak, a local valley, or simply a continuation of the current move.

2. Identifying Trend Direction The logic categorizes price action into three distinct states:

  • Upward Movement: When the price creates a new high relative to its neighbors.
  • Downward Movement: When the price creates a new low relative to its neighbors.
  • Reversal Points: When the price switches from an upward trend to a downward trend (or vice versa).

3. Mapping Significant Peaks and Valleys The core of the script is its ability to remember "Swing" points. As it moves backward through the historical data, it stores specific coordinates for these significant turns.

  • When a new high is established during an uptrend, the script marks that price level.
  • When a new low is established during a downtrend, it captures that level.
  • If the price action indicates a reversal (a "Swing"), the script logs the exact price and the location of the previous peak or valley.

4. Visual Output and Tracking Once the script has analyzed the history and identified these structural turning points, it populates a buffer on your chart. It essentially "draws" a line or section that connects these significant high and low points.

Finally, the script provides a real-time status update in the corner of your chart area, displaying the most recent significant price level it has identified. This allows traders to quickly see the current "high" or "low" milestone without having to manually scan through every candle.

Miscellaneous
Implements a curve of type %1
11 Views
0 Downloads
0 Favorites
High_Low_v2
//+------------------------------------------------------------------+
//|                                         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 White
//---- 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;
   double Uzel[10000][3];
   string text;
// loop from first bar to current bar (with shift=0) 
   Swing_n=0;Swing=0;uzl=0;
   if(Bars<barn) return(-1);
   if (barn>=ArraySize(Uzel)/3) return(-1);

   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];

      Comment("\n","\n","\n","\n","\n","\n","\n","\n",ExtMapBuffer1[mv]);
     }


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

Comments