ZigZag
Swing highs and lows, each shown only once a reversal has confirmed it.
Inputs
| Name | Type | Default | Range |
|---|---|---|---|
| depth | int | 12 | 2 to 200 |
| backstep | int | 3 | 0 to 100 |
| atr_period | int | 14 | 1 to 500 |
| atr_mult | float | 1 | 0.1 to 10 |
Outputs
| Name | Type | Required | Description |
|---|---|---|---|
| up | value | Optional | color theme.accent, shape circle, shift 0, style marker, where at_price |
| down | value | Optional | color theme.accent, shape circle, shift 0, style marker, where at_price |
| offset | value | Optional | color theme.accent, style line, width 1 |
| pivot | value | Optional | color theme.accent, style step, width 1 |
| direction | value | Optional | color theme.accent, style line, width 1 |
- Warm-up
- max(depth - 1, atr_period - 1) + backstep bars (16 at the defaults)
- Repaints
- Yes
- Parity
- None
Formula
A bar is a low (high) candidate when its low (high) is the lowest (highest) of the last depth bars. A candidate is final after backstep more bars, once weaker candidates of the same kind within backstep bars are cleared.
One swing is pending at a time. A stronger candidate of the same kind replaces it. An opposite candidate at least atr_mult average true ranges away confirms it.
The confirmed swing is written on the confirming bar: up or down holds its price and offset the bars back to it. pivot is the last confirmed price, direction is 1 after a low and -1 after a high. The swing pending at the end is never written.