Explainers / ZigZag++
ZigZag++, explained from the source
ZigZag++ by DevLucem is the most-boosted zigzag on TradingView. It joins swing highs and lows with straight lines, tags each turn HH, HL, LH or LL, and shades the background by direction. It is built to work like the classic MT4 ZigZag, with the same three settings: Depth, Deviation and Backstep. The question everyone asks is whether it repaints. The answer from the code: the direction does not, the last leg does, by design.
The three settings
- Depth (default 12): how many bars back the script looks for the highest high and the lowest low.
- Deviation (default 5): how close, in ticks, a bar's high must be to that highest high to count as "at a new high" (and the same for lows). It is a number of the symbol's minimum price steps, not a percentage.
- Backstep (default 2): how many bars in a row the most recent new low must be newer than the most recent new high (or the reverse) before the direction flips.
How it decides direction
On every bar the script counts two things: bars since price was last at a new Depth-bar high, and bars since it was last at a new Depth-bar low. If the new low is more recent than the new high, and that has been true for at least Backstep bars, the direction is down. Otherwise it is up.
Both counts are taken from the previous bar. So the direction for a bar is settled when that bar opens, and it cannot flip back and forth while the bar is forming.
How it draws the legs
While the direction is up, the script tracks the highest high since the last flip; that is the end of the current leg. When the direction flips to down, that high becomes a fixed pivot, and the script starts tracking the lowest low. The HH/LH (or HL/LL) label compares the new pivot with the previous pivot of the same kind.
Does ZigZag++ repaint?
Yes, the last leg does, and the setting that controls it is called "Repaint Levels" and is ON by default. While a leg is still running, the script deletes its line and label every bar and draws them again to the newest extreme. So:
- the end of the last line moves as price makes new highs (or lows) in that leg;
- the label on it can change, for example from LH to HH, when price goes past the previous high;
- the HH, LH, HL and LL alerts fire on that live leg, each time its end point moves, before the pivot is final.
Earlier legs do not move. Once the direction flips, the old end point is fixed for good.
Turn "Repaint Levels" off and each leg is drawn only after the direction has flipped. Nothing on the chart moves, but every line appears one leg late. Neither mode knows a pivot is a pivot until price has already moved away from it. More in what repainting is, or test a script with the repaint checker.
How late is a pivot?
The pivot is confirmed on the bar the direction flips, which comes after the extreme bar. On random-walk prices (our simulation, 100,000 bars, ZigZag++'s rule re-implemented exactly):
| Setting | new leg every | pivot confirmed after the extreme |
|---|---|---|
| Depth 12, Deviation 5, Backstep 2 (default) | 17 bars | median 7 bars (1 in 10 took 12 or more) |
| Depth 5 | 7 bars | 4 bars |
| Depth 30 | 44 bars | 16 bars |
| Backstep 5 | 19 bars | 9 bars |
At the default, the end of the live leg moved on about 30% of bars, the live label changed its text in about one leg in four, and the HH/LH/HL/LL alerts fired about five times per leg. Random-walk prices have nothing to predict, so these numbers describe how the rule reacts to noise, not how it trades.
Deviation is in ticks
Deviation is multiplied by the symbol's minimum tick. On a stock or a crypto pair quoted to 0.01, 5 ticks is five cents, far smaller than a typical bar, so Deviation 1 and Deviation 5 gave almost the same legs in our simulation. On a futures contract with a 0.25 tick, 5 ticks is 1.25 points. Copying "best settings" from another market copies a different setting. In our simulation Deviation also did not act as a simple minimum swing size: some larger values gave more legs, not fewer. Change it and look, rather than assume.
Where it fails
- The last leg is provisional. Its end point, its label and its alerts can all change until the direction flips.
- Every pivot is confirmed late. At the default a median of 7 bars after the high or low it marks; on a finished chart that delay is invisible.
- A finished chart flatters it. Every line on history connects real turns, because each was drawn after the fact. Live, you only ever see the turn after it has happened.
- Deviation depends on the symbol. It is counted in ticks, so the same number is a big filter on one market and nothing on another.
- No test of any setting. The script has no record of how its labels performed, and HH/HL/LH/LL describe what happened, not what comes next.
Also explained: Pivot highs and lows · HalfTrend · Repainting · Repaint checker
Educational only. Not financial advice. Nothing here is a recommendation to buy or sell anything. ZigZag++ is by DevLucem on TradingView; this page explains its published open-source code and is not affiliated with the author.
Also explained: Repaint checker, VWAP, Supertrend, RSI, UT Bot Alerts, Nadaraya-Watson Envelope, Squeeze Momentum, What is repainting on TradingView?, Is TradingView backtesting accurate?, Chandelier Exit, WaveTrend Oscillator, QQE MOD, Pivot highs and lows, Hull Suite, Range Filter, Twin Range Filter, HalfTrend, SSL Hybrid, CM MacD Ultimate MTF, Volume Profile / Fixed Range, ADX and DI, Support Resistance Channels, Market Structure Break & Order Block, Order Block Finder, Pivot Point SuperTrend, Trendlines with Breaks [LuxAlgo], Divergence for Many Indicators, TradingView script selling terms, Support and Resistance Levels with Break, Liquidity Swings [LuxAlgo], Pine Script errors, Breakout Probability (Expo), Did ChatGPT or Claude write your Pine Sc, Lorentzian Classification, SuperTrend AI (Clustering), Machine Learning Adaptive SuperTrend, Dynamic Swing Anchored VWAP, Support and Resistance Power Channel by , Support and Resistance (High Volume Boxe, Trendline Breakouts With Targets by Char, Breakout Finder by LonesomeTheBlue
Get the next teardown by email
One short email when a new teardown or free tool goes live, about twice a month. No signals, no hype. Unsubscribe in one click.
Almost done. Check your inbox and click the confirmation link.
Sent with Kit. Your address is used only for these emails. Privacy
No TradingView account yet? This affiliate link gives you a $15 coupon toward a paid plan, and we earn a commission if you buy one. The free plan is enough to follow this page.