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
| Input | Type | Default | Range or choices |
|---|---|---|---|
Deviation %deviation | Number | 5 | min 0.01, max 100 |
Depth (bars)depth | Whole number | 10 | min 1, max 500 |
What it draws
| Line | Drawn as |
|---|---|
| ZigZag | Steps |
Used in
No strategy template reads it yet.