ZigZag Pass Node

ZigZag Pivot Detection — Series Input

AdvancedPrice ActionPass

Overview

The ZigZag Pass Node identifies significant price pivots in a series input by filtering out moves smaller than a specified percentage deviation. It outputs the pivot values at confirmed swing highs and lows — null between pivots — enabling swing-based analysis on any numeric series.

ZigZag is primarily a visual and analytical tool — it draws lines connecting significant swings, filtering out the noise between them. As a Pass node it accepts any numeric series, allowing swing analysis on derived indicator streams. Note that the last ZigZag line is always unconfirmed until the next pivot forms — the most recent pivot may be redrawn as new bars arrive.

Algorithm

Initialize: lastPivot = series[0], lastPivotType = "high", direction = "up"
For each bar i:
if direction == "up":
if series[i] > lastPivot: update pending high
if series[i] < lastPivot × (1 − deviation/100):
confirm lastPivot as swing high; direction = "down"
if direction == "down":
if series[i] < lastPivot: update pending low
if series[i] > lastPivot × (1 + deviation/100):
confirm lastPivot as swing low; direction = "up"
Output[i] = pivotValue at confirmed pivots, null otherwise
Output: pivot values at swing highs/lows; null between pivots. No warm-up.
Warning: the most recent (unconfirmed) ZigZag line may be redrawn as new bars are added.

Parameters

ParameterDefaultDescription
deviation5Minimum percentage move from a swing extreme required to confirm that pivot and begin a new swing

Inputs & Outputs

SlotDirectionTypeDescription
inputInput{ values, timestamps }Any numeric series (price, oscillator, etc.)
valuesOutput(number | null)[]Pivot values at swing highs/lows; null between confirmed pivots
timestampsOutputnumber[]Unix timestamps aligned to input

Use Cases

Support and Resistance Levels

Collect non-null ZigZag pivot values and cluster them — high-density price levels represent historically significant support and resistance zones. The deviation parameter controls how significant a swing must be to qualify as a structural level.

Elliott Wave and Pattern Analysis

ZigZag pivots provide the anchor points for Elliott Wave counts, Fibonacci retracement measurements, and chart pattern detection (head and shoulders, double top/bottom). Use the pivot sequence to automate the identification of these structures.

Swing High/Low Detection

Filter the output to identify alternating swing highs and lows — use the sequence of pivots to determine whether the market is making higher highs and higher lows (uptrend) or lower highs and lower lows (downtrend), tracking overall trend structure.

Tips & Best Practices

ZigZag Is Repainting

The most recent ZigZag line is always provisional — the last non-null output value may change as new bars confirm or invalidate the current swing. Never use the current bar's ZigZag value as a live trading signal. Only use confirmed (past) pivots for backtesting.

Deviation Must Match Instrument Volatility

The default deviation=5% may be too tight for highly volatile assets (crypto) and too wide for stable instruments (T-bills). Calibrate by observing the pivot frequency on historical data — aim for 5–10 pivots per 100 bars as a starting point.

Use Pivot Timestamps Not Values Alone

When analyzing ZigZag output, pair each non-null value with its corresponding timestamp to build a pivot sequence. The timestamps tell you the time spacing between pivots — short spacing indicates rapid oscillation; long spacing indicates slow, sustained swings.

Related Indicators