Zigzag Pivot Detection, Ratios, and Chart Drawing in Pine Script
Summary
This Pine Script library provides a lightweight Zigzag implementation for identifying alternating swing highs and lows and drawing them on a chart. It defines pivot and calculation objects, tracks a configurable number of recent pivots, and can expose their prices, bar indices, and chart points for reuse. The pivot length and optional input price series determine the candidate highs and lows.
When a pivot is added, the library checks direction, records price and bar-distance ratios against earlier swings, and can replace the latest pivot when the movement extends. It supports continuous updates, fresh redraws, line or polyline output, and optional labels showing pivot information. The source describes implementation features rather than a trading strategy or performance results. Zigzag points can change as new bars arrive, and the document provides no evidence that the calculated swings predict future prices or account for trading costs.
Key ideas
- The library identifies swing pivots from highs and lows over a configurable lookback length.
- It stores a limited set of recent pivots and provides helper methods to retrieve their prices, bars, or points.
- Pivot metadata includes price and bar ratios relative to preceding swings.
- Drawing options include continuous updates, full redraws, optional labels, and line or polyline rendering.
- The document offers no backtest or evidence of predictive performance.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.