Zig Zag indicator: separate pivot price from confirmation time
The Zig Zag indicator compresses price history into alternating swing highs and lows. TradingView filters pivots by a percentage reversal and a left/right confirmation window. A line anchored to an earlier candle became available later, and its latest endpoint can still move. Treat the drawing as a changing description of swings, not an entry timestamp.
This page follows the current TradingView built-in documentation and the official TradingView/ZigZag library v9 release notes, checked October 17, 2026. Library v8 moved to Pine Script v6; v9 replaced extendLast with projectionPivots. The old extension to the latest price and the v9 search for a potential pivot are different behaviors. Do not transfer settings from an unrelated community script by name alone.
For the worked example, use a 5% deviation, Pivot legs = 4, and projections off. Evaluate only completed bars with positive prices.
The library update() result can mean either a new line or a changed last line. A true result alone is not a new reversal signal.
Apply the pivot test before the deviation test
TradingView uses floor(Pivot legs / 2) bars on each side. Highs must exceed the left highs and match or exceed the right highs; lows use the inverse comparisons. An opposite pivot meeting the deviation threshold adds a segment. A more extreme pivot of the same type replaces the endpoint. Other candidates are ignored.
The formula here assumes a positive last price. Specify zero and negative-price handling before extending this fixture to other instruments.
A threshold crossing alone does not satisfy the two-right-bar test. Both conditions must be checked.
Calculation in this example
Result
Left bars = right bars = floor(4 / 2)
2 bars each side
Reversal magnitude = 100 × abs(new price − last price) / last price
Compare with 5% after the pivot test
Drop from 110 to 106 = 100 × 4 / 110
3.6364%; reject the opposite pivot
Drop from 114 to 106 = 100 × 8 / 114
7.0175%; accept the opposite pivot
The 16-bar input fixture
These are invented high and low prices in arbitrary price units, not market data. Start with no saved pivots and require two available bars on each side. Opens and closes can lie anywhere inside each range; only highs and lows enter this calculation. The first two bars provide left-side history.
Bar
High
Low
1
105
103
2
104
102
3
102
100
4
104
102
5
107
105
6
110
108
7
109
107
8
108
106
9
109
107
10
112
110
11
114
112
12
112
110
13
110
108
14
108
106
15
109
107
16
110
108
What was available at each completed bar?
The event log below is derived from the fixture. At bar 8 the visible segment ends at bar 6. At bar 11 that endpoint remains unchanged with projections off: the new high at 114 still lacks its two right bars. Only at bar 13 can the saved endpoint move to bar 11. The final chart no longer shows the earlier endpoint at bar 6.
Original fixture diagram. Blue is the structure after bar 16. Orange dashes preserve the earlier snapshot for comparison; they are not TradingView projected pivots. View original source
The final vertices sit at bars 3, 11, and 14. Their first acceptance times in this fixture are bars 5, 13, and 16.
A simulated entry at the bar 11 high would use information unavailable at that time. An event emitted at bar 13 still needs a separate execution rule and fill assumption.
Observed at close
Candidate and decision
Saved structure after evaluation
5
Bar 3 low = 100 passes its left/right test; initialize
Low at bar 3; no segment yet
8
Bar 6 high = 110; rise from 100 is 10%
3:100 → 6:110
10
Bar 8 low = 106; drop from 110 is only 3.6364%
3:100 → 6:110; unchanged
11
High = 114 is visible, but the bar 11 pivot is unconfirmed
3:100 → 6:110; unchanged
13
Bar 11 high = 114 confirms; replace the previous high
3:100 → 11:114
16
Bar 14 low = 106 confirms; drop from 114 is 7.0175%
3:100 → 11:114 → 14:106
Replay the updates, then test projections separately
TradingView warns that the latest solid segment can be redrawn. With projections enabled, a dashed candidate can also change or disappear. Disabling projections removes that candidate display; it does not freeze the last solid endpoint.
On your chosen symbol, save the timeframe, session, script version, deviation, and pivot legs. Start replay before the swing under inspection.
Advance one completed bar at a time. Record observation time, pivot time, pivot price, and whether the operation added or replaced an endpoint.
Capture the intermediate structure before advancing. Compare those snapshots with the final drawing; a final screenshot cannot preserve a removed endpoint.
Repeat with projections enabled and label provisional events separately. The hypothetical table above covers only projections off, not intrabar projection behavior.
Give Pineify an observable calculation contract
Ask the Pine Script AI Coding Agent to draft a Zig Zag inspection script with separate outputs for pivot location, detection time, and endpoint replacement. Use the fixture as a manual acceptance check before adding alerts or strategy orders.
Pin the implementation or library version. State high/low inputs, deviation, left/right lengths, projection policy, and how to handle a candle that qualifies as both a high and a low.
Keep an event log when a candidate is accepted or replaced. Plotting a label at the old pivot bar must not backdate the event timestamp.
Request syntax validation, then compare per-bar values and operation types. Define entries, exits, sizing, execution timing, and costs separately; a swing compression rule is not a complete strategy.
Where Pineify fits
Pine Script AI Coding Agent
Turn a written Zig Zag rule into inspectable Pine Script. Specify when pivots become available and compare generated behavior with the fixture before using alerts.
Record events when you first observe them. In this fixture, the bar 11 high is accepted at bar 13. Any subsequent trading rule must use that later availability time and its own execution assumptions.
The intervening low at 106 failed the 5% reversal test from 110. The later high at 114 therefore replaced the existing high when it confirmed at bar 13. The event log preserves what the final line omits.
Zig Zag selects swing vertices. A BOS or CHOCH rule must additionally define which swing level counts as a break, whether a wick or close triggers it, and how directional state changes. This example makes none of those classifications.
Educational indicator analysis, not investment advice. The prices and diagram are hypothetical. No backtest or trading performance is reported, and a confirmed local pivot does not guarantee a reversal or profit.
Published by Pineify. Pineify is an independent product and is not affiliated with TradingView. Sources support the technical explanations; examples do not establish trading performance.