Skip to content
All library documents

Building a Fibonacci Retracement ZigZag with ATR Wave Filters

Article MQL5 code base

Summary

This indicator tutorial describes a ZigZag that changes direction after price retraces a configurable percentage of the current wave. It tracks local highs and lows, the current wave’s start and end, and bar distances so it can move a plotted turning point when a new extreme appears. A rolling average of bar ranges, measured in points, provides an ATR-like volatility unit; an optional minimum wave size filters out moves smaller than a selected number of those units.

To initialize the sequence, the method waits until the rolling range average has enough bars, then accepts whichever qualifying move first breaks a tracked high or low. Subsequent reversals must satisfy both the retracement threshold and minimum wave-size condition. The examples use a 23.6% retracement and compare no minimum wave filter with a three-unit filter. This is an indicator construction explanation, not a tested trading strategy: it gives no performance evidence, and turning points can shift as new price extremes arrive. The rolling volatility calculation uses bar ranges, so it is not a full true-range ATR.

Key ideas

  • The ZigZag extends an active wave when price makes a new extreme and switches direction after a configurable retracement.
  • A rolling average of bar ranges sets a volatility scale for an optional minimum wave-size filter.
  • The first wave is initialized by a qualifying high or low break after the range average fills.
  • Stored bar distances let the indicator relocate wave endpoints as new extremes occur.
  • The tutorial explains indicator mechanics but presents no trading results, and plotted turning points can change as prices evolve.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.