ZigZag
All indicators

LibraryLevels

Indicator

ZigZag

The swing highs and lows that a reversal of at least the set percentage has confirmed, drawn as a level that steps to each new swing.

LevelsOn the price2 inputsZigZag

How it is calculated

Extremes are highs and lows, reversals are judged on the close. After a swing high the candidate low is the lowest low at least depth bars after it, confirmed by the first close at or above candidate times (1 plus deviation/100); lows mirror this. Before the first swing both sides are open and the first confirmed sets the direction. At most one swing per bar. The zigzag output is the price of the last confirmed swing, swing is +1 for a high and -1 for a low; no value before the first swing.

Reference: ZigZag by percent deviation, confirmed without repainting

How to read it

A swing shows on the bar that confirms it, at the price of its extreme, and never moves afterwards. Most charting tools draw ZigZag from extreme to extreme and keep moving the last leg as price goes on, which looks cleaner in hindsight than anything a strategy could have traded. Here each swing arrives late, by the bars the reversal took, but a backtest only sees what was known at the time.

In a strategy

Reacting to a fresh swing: when ctx.ind("zigzag", deviation=5.0, depth=10).swing turns from +1 to -1 a low has just been confirmed, a long entry with its stop below .zigzag, the price of that low.

Inputs

InputTypeDefaultRange or choices
Deviation %deviationNumber5min 0.01, max 100
Depth (bars)depthWhole number10min 1, max 500

What it draws

LineDrawn as
ZigZagSteps

Used in

No strategy template reads it yet.

OrionQuant