# ZigZag

ZigZag is an indicator on [Vela](https://vela.luxalgo.com/chart), our next-generation charting platform, written in Pine Script®.

Connects successive swing highs and swing lows with straight line segments, filtering out price movements smaller than a set threshold to show the larger swings in price. Defaults are a 5 percent deviation filter with a pivot depth of 10 bars, and the most recent leg repaints until a new pivot is confirmed. This is the standard raw ZigZag construction.

- Indicator in the LuxAlgo Library, by LuxAlgo, published Apr 13, 2020.
- Access: free.
- Concepts: [Zigzag Structure](https://www.luxalgo.com/library/concept/zigzag-structure/) (primary)
- Open on Vela: https://vela.luxalgo.com/chart?pineScriptCodeId=dphhupozv8s53s60wcmy7xxf
- Page: https://www.luxalgo.com/library/indicator/zigzag/

The **ZigZag** connects successive swing highs and swing lows with straight line segments, discarding every countermove smaller than a set threshold so only the larger swings in price remain visible. Defaults are a 5% deviation filter with a pivot depth of 10 bars, and, as in any faithful zigzag, the most recent leg stays provisional, extending to each new extreme until the next pivot is confirmed. This is the standard raw construction: no labels, no ratios, just the chart reduced to alternating legs.

Once candles collapse into legs, structure that hides in bar noise (trend sequence, swing levels, pattern shapes) becomes explicit and measurable.

## How to Trade the ZigZag?

- **Rising pivots**: successive higher swing highs and higher swing lows define an uptrend; the read holds until a confirmed pivot breaks the sequence.
- **Falling pivots**: lower highs and lower lows mark the downtrend; the first pivot violating the sequence is an early structural warning.
- **Confirmed pivot levels**: support and resistance references, stop placements behind structure, and anchors for measuring a completed leg.
- **The live leg**: treat the newest segment as unfinished. Its endpoint follows price until the reversal criteria are met.

The tool draws structure rather than entries: it decides which swings count at your chosen scale.

## ZigZag Settings

- **Deviation (%)** (default 5): the minimum reversal from the running leg extreme, as a percentage of that extreme, required to confirm a pivot. Raise it to keep only major swings; lower it to expose finer structure.
- **Depth** (default 10): the minimum number of bars required between two consecutive pivots, blocking rapid pivot alternation even when the percentage threshold is met.
- **Up Leg** / **Down Leg** / **Width** (default width 2): purely visual, the colors of rising and falling segments and their thickness.

## Frequently Asked Questions

### Which parts of the ZigZag repaint?

Only the final leg. A pivot confirms once price reverses from the leg extreme by the full deviation with the depth spacing satisfied; until then, the last segment's endpoint slides to every new extreme. Confirmed pivots never move afterward.

### How do Deviation and Depth work together?

A candidate pivot must clear both gates: the countermove has to reach the Deviation percentage, and the new pivot must sit at least Depth bars after the previous one. If the zigzag skips swings you care about, lower Deviation; if it flickers on choppy charts, raise Depth.

### When do the alerts fire?

**New Swing High** and **New Swing Low** fire on the confirmation bar (the first moment a pivot is knowable), not at the extreme where the pivot is later drawn. Since pivots are placed retroactively, systematic use should anchor to confirmation rather than the plotted extreme.

## Related indicators

- [Delta ZigZag](https://www.luxalgo.com/library/indicator/delta-zigzag/) (Zigzag Structure): markdown at https://www.luxalgo.com/library/indicator/delta-zigzag.md
- [Price Simplification](https://www.luxalgo.com/library/indicator/price-simplification/) (Zigzag Structure): markdown at https://www.luxalgo.com/library/indicator/price-simplification.md
- [Elliott Wave](https://www.luxalgo.com/library/indicator/elliott-wave/) (Zigzag Structure): markdown at https://www.luxalgo.com/library/indicator/elliott-wave.md
- [Wave Consolidation](https://www.luxalgo.com/library/indicator/wave-consolidation/) (Zigzag Structure): markdown at https://www.luxalgo.com/library/indicator/wave-consolidation.md
- [Donchian Zig-Zag](https://www.luxalgo.com/library/indicator/donchian-zig-zag/) (Zigzag Structure): markdown at https://www.luxalgo.com/library/indicator/donchian-zig-zag.md
- [Zig Zag Channels](https://www.luxalgo.com/library/indicator/zig-zag-channels/) (Zigzag Structure): markdown at https://www.luxalgo.com/library/indicator/zig-zag-channels.md
- [Structural Leg Profiler](https://www.luxalgo.com/library/indicator/structural-leg-profiler/) (Zigzag Structure): markdown at https://www.luxalgo.com/library/indicator/structural-leg-profiler.md
- [Wolfe Wave Detector](https://www.luxalgo.com/library/indicator/wolfe-wave-detector/) (Zigzag Structure): markdown at https://www.luxalgo.com/library/indicator/wolfe-wave-detector.md

---

Source: https://www.luxalgo.com/library/indicator/zigzag/ (LuxAlgo Library). Free to use with attribution: https://www.luxalgo.com/library/license/
