Skip to content
All library documents

Building an Oscillator-Triggered ZigZag with Pattern Coloring

Article MQL5 articles

Summary

The article walks through developing a price-chart ZigZag whose reversals are triggered when an oscillator crosses overbought or oversold levels. It uses Williams %R as an example, marks the bars where those thresholds are reached, and tracks price highs and lows to place ZigZag turning points. The implementation is divided into stages, progressing from the core indicator to pattern detection, oscillator options, and a graphical interface.

A central challenge is that oscillator signals and price extremes can occur on different bars, and signals or reversals may change while a bar is forming. The article also explains how overlapping patterns complicate historical segment coloring: segments already assigned to another pattern should retain their color when a new pattern appears. The proposed design choices and examples illustrate these issues, but the indicator is not presented as a tested trading strategy. The author notes that repainting historical segments can hinder interpretation and that the pattern display behavior should be clarified with the customer.

Key ideas

  • Oscillator threshold crossings trigger ZigZag reversals, while price highs and lows determine the turning points.
  • Oscillator signals can change during a forming bar, so the indicator must handle provisional reversals and extremes.
  • Overlapping patterns require careful coloring so that clearing a new pattern does not erase an existing one.
  • A staged development process helps separate ZigZag construction, pattern detection, oscillator inputs, and interface work.
  • Historical recoloring can make a signal harder to interpret because the pattern may only become actionable after it appears.

Tags

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