Indicators: ZigZag

 

ZigZag:

The Zigzag indicator is a series of section lines connecting significant tops and bottoms at the price plot.

Minimum price change parameter determines the percentage for the price to move in order to form a new "Zig" or "Zag" line. This indicator eliminates those changes on the plot we analyze that are less than the given value. Therefore, the Zigzag reflects significant changes only.

In most cases, we use Zigzag to facilitate the perception of plots as it shows only the most important changes and turns. You can also reveal Elliot Waves and various figures on the plot with its aid.

It is important to understand that the last section of the indicator may vary depending on the changes of data you analyze. This is one of those indicators, where a change of securities price can provoke a change of the previous value. This ability to correct its values by the following price changes makes Zigzag a perfect tool for analyzing price changes that have already happened. Therefore, you should not try to create a trade system basing on the Zigzag. It is more suitable for analyzing historical data than for making prognoses.

ZigZag Indicator

Author: MetaQuotes Software Corp.


 

The Zig-Zag indicator is extremely useful for determining price trends, support and resistance areas, and classic chart patterns like head and shoulders, double bottoms and double tops. The Zig-Zag indicators uses both swing highs and swing lows in its calculation:

  • Swing Highs: When a price (usually close) is both higher than the price previous to it and after it.
  • Swing Lows: When a price is both lower than the price prior to it and lower than the price following it.

The Zig-Zag indicator can use both percentages or points in its construction. To construct the Zig-Zag indicator, there must be a certain percentage or number of points between a swing high and a swing low before a line will be drawn. The chart below of the E-mini Nasdaq 100 Futures contract visually illustrates the difference between a price retracement Zig-Zag of 3% and a price retracement Zig-Zag of 5%:


Notice how in the chart above that a Zig-Zag with a retracement percentage of 3% makes more distinct lines than the Zig-Zag with a retracement percentage of 5%. The purpose of using a Zig-Zag with a larger retracement percentage is to help eliminate price noise that is not significant for the trader's analysis.

Zig-Zag indicator is extremely effective at uncovering stock cycles while screening out short-term price noise.

The Zig-Zag indicator is extremely effective in filtering short-term noise and identifying significant trends and significant changes in market prices.

Below is a chart of the E-mini S&P 500 Futures contract that illustrates how effective the Zig-Zag indicator was in finding areas of support and resistance and price breakouts:


The chart above of the e-mini uses a 5% Zig-Zag retracement value; therefore, only price changes of 5% or greater are shown, helping a long-term trader or investor determine important areas of support, resistance, and areas of price breakouts.

On the left of the chart, the S&P 500 was forming a triangle consolidation pattern. When prices broke resistance, a long-term buy was generated. During the middle of the chart, the Zig-Zag indicator was effective in illustrating that the S&P 500 was in an upward price channel. Buying in areas where price touched the lower support trendline and selling when prices touched the upper resistance line would have proved extremely profitable.

Using the Zig-Zag indicator for shorter-term trades can prove profitable as well. The chart below of Intel (INTC) shows a classic chart head and shoulder pattern easily seen by the Zig-Zag indicator ($1 retracement):


The easily identified head and shoulders pattern gave a sell signal when price on the right shoulder broke the upward slanting trendline.

The Zig-Zag indicator is an excellent technical analysis tool for identifying classic charting patterns. The Zig-Zag indicator is also effective in reducing noise and helping the technical trader see the true market direction.

 
helps me to understand the zz behaviour
 

in this code, specific to below block, does 'res' variables needed? in other blocks, I get its usage but not in this block.

//--- final rejection
   for(shift=limit;shift<rates_total && !IsStopped();shift++)
     {
      res=0.0;
      switch(whatlookfor)
        {
         case 0: // search for peak or lawn
            if(lastlow==0 && lasthigh==0)
              {
               if(HighMapBuffer[shift]!=0)
                 {
                  lasthigh=high[shift];
                  lasthighpos=shift;
                  whatlookfor=Sill;
                  ZigzagBuffer[shift]=lasthigh;
                  res=1;
                 }
               if(LowMapBuffer[shift]!=0)
                 {
                  lastlow=low[shift];
                  lastlowpos=shift;
                  whatlookfor=Pike;
                  ZigzagBuffer[shift]=lastlow;
                  res=1;
                 }
              }
            break;
         case Pike: // search for peak
            if(LowMapBuffer[shift]!=0.0 && LowMapBuffer[shift]<lastlow && HighMapBuffer[shift]==0.0)
              {
               ZigzagBuffer[lastlowpos]=0.0;
               lastlowpos=shift;
               lastlow=LowMapBuffer[shift];
               ZigzagBuffer[shift]=lastlow;
               res=1;
              }
            if(HighMapBuffer[shift]!=0.0 && LowMapBuffer[shift]==0.0)
              {
               lasthigh=HighMapBuffer[shift];
               lasthighpos=shift;
               ZigzagBuffer[shift]=lasthigh;
               whatlookfor=Sill;
               res=1;
              }
            break;
         case Sill: // search for lawn
            if(HighMapBuffer[shift]!=0.0 && HighMapBuffer[shift]>lasthigh && LowMapBuffer[shift]==0.0)
              {
               ZigzagBuffer[lasthighpos]=0.0;
               lasthighpos=shift;
               lasthigh=HighMapBuffer[shift];
               ZigzagBuffer[shift]=lasthigh;
              }
            if(LowMapBuffer[shift]!=0.0 && HighMapBuffer[shift]==0.0)
              {
               lastlow=LowMapBuffer[shift];
               lastlowpos=shift;
               ZigzagBuffer[shift]=lastlow;
               whatlookfor=Pike;
              }
            break;
         default: return(rates_total);
        }
     }


really needed?

 
soi kawasaki:

in this code, specific to below block, does 'res' variables needed? in other blocks, I get its usage but not in this block.


really needed?

Check what is it doing with it prior to that code you are showing. Or better yet : remove it and see what happens to zigzag indicator
 
Mladen Rakic:
Check what is it doing with it prior to that code you are showing. Or better yet : remove it and see what happens to zigzag indicator

thank you for your reply : )

did Print() to check the value and also where it is used but was not able to figure out why it needed in this block.

also did remove it ran the indicator but works fine without it too.

I was curious because it is default indicator came with MT5.

just was seeking for the second opinion if I have misunderstood the existence of the usage in this block of code.

Reason: