Skip to content
All library documents

Building a ZigZag Indicator with Pivot Ratios and High-Low Counts

Article ProRealCode

Summary

The document describes a ZigZag indicator that identifies candidate swing highs and lows from rolling price extremes, stores pivot prices, directions, and bar indices in arrays, and connects the pivots. It classifies highs and lows as higher or lower relative to earlier pivots and tracks counts for those sequences. It also calculates ratios comparing the current move with the preceding move, including retracement size, bar duration, and move size relative to the prior move in the same direction.

Parameters control whether a high and low may occur on the same bar, whether a pivot is forced after a configured interval without a new extreme, and whether candle direction is required to confirm a pivot. The indicator can return the latest four pivot values for downstream pattern or breakout logic. The document provides implementation code but no performance tests or trading results. ZigZag pivots may be revised as new extremes appear, and the description gives no validation of its signals or explicit treatment of that repainting risk.

Key ideas

  • The indicator detects swing candidates using rolling highs and lows over a configurable lookback.
  • It stores pivot direction, price, and bar position in arrays and links successive points.
  • It classifies pivots as higher or lower and tracks the corresponding sequence counts.
  • Move ratios compare price retracement, elapsed bars, and move size with prior swings.
  • Optional settings permit same-bar pivots, forced pivots after inactivity, and candle-direction checks.

Tags

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