Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Indicator

ZigZag

A Pine Script v5 indicator built on Pivothigh (high, 10) and Pivotlow (low, 10). It draws 2 marker series on the price chart. It declares 2 alerts. 3 settings; defaults include Pivot depth 10.

Generated from the script's code by a template: every clause is a fact read from the source. Not written by a person or a model, and not taken from the author's description.

Does ZigZag repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 300 of 300 bars.
How many settings does ZigZag have?
3
Defaults include Pivot depth 10, Label each swing true.
What alerts does ZigZag have?
2
Swing high confirmed; Swing low confirmed.
Does ZigZag run in Pine Script v6?
Yes
Every plotted value identical on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. The v6 script can be downloaded below.
Does ZigZag draw on the price chart?
Yes
It is declared with overlay = true.

BTCUSDT · 1D · default settings

  • Swing high
  • Swing low
  • Line colour
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (2)
60775.0071769.5459600.0171979.0053485.9370079.9949000.0065000.0052550.0066498.0058946.0099588.0190500.00108353.0089256.69109588.0091231.0099475.0076606.0088765.4374508.00111980.00100372.26110530.1798200.00123218.00111920.00124474.00107255.00117900.00108620.07126199.63102000.00116400.0080600.0094588.9984450.0197924.4960000.0074050.0065000.0082850.0059130.9167292.1557800.1966956.1562275.0082300.0074967.9787395.6740,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Lines and shading are what the script draws. Lines, boxes and labels are the script's own drawings, the most recent ones its limits keep.
Line colour
0.0%
of bars

Share of 1,000 bars spent in each state with the default settings.

Review

What a careful reader of this script would point out, found by checking the source and the backtest.

Nothing to point out.

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
Pivot depth10int · min 2ph pl pivotBar plotshape
Label each swingtrueboolline 34
Line colour#ffb74dcolorleg line 37

What it calculates

  • Pivothighhigh, Pivot depth (10), Pivot depth (10)ph · line 10
  • Pivotlowlow, Pivot depth (10), Pivot depth (10)pl · line 11

Signal flow

How price data and settings reach what is drawn. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.

highhighprice datadepthPivot depthsetting · 10lowlowprice dataphPivothigh→ phplPivotlow→ pllastPricelastPricevaluelastBarlastBarvaluelastDirlastDirvaluepivotPrice, pivotDirpivotPrice · pivotDir2 valuespivotBarpivotBarvaluebetterbettervaluelegColourlegplotshape:42plotshapeplotshapeplotshape:43plotshapeplotshapealertcondition:45Swing high confirmedalertconditionalertcondition:46Swing low confirmedalertcondition

What it draws

OutputCallValueBy defaultLine
plotshapeplotshapenot na(ph)Shown42
plotshapeplotshapenot na(pl)Shown43

The shading takes one of 1 colours on every bar, each a state the script names in its settings: Line colour

Alerts

AlertCallMessageLine
Swing high confirmedalertconditionA swing high was confirmed45
Swing low confirmedalertconditionA swing low was confirmed46

Does it repaint?

No

No repainting patterns in the source, and the live replay matched history.

300/300bars identical at close when replayed liveThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. On 0 of them the colour changed while the bar was forming before it settled.
  • ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
  • ClearFuture-bar referencesNo negative history offsets such as close[-1].
  • ClearIntrabar recalculationNo varip or realtime-only state. Values move while a bar forms and settle when it closes, as every indicator's do.

The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.

Other markets

The same script with default settings on 8 Binance markets, each the most recent 1,000 bars.

MarketLine colour
BTCUSDT 1D0% of bars—
BTCUSDT 4h0% of bars—
ETHUSDT 1D0% of bars—
ETHUSDT 4h0% of bars—
SOLUSDT 1D0% of bars—
SOLUSDT 4h0% of bars—
BNBUSDT 1D0% of bars—
BNBUSDT 4h0% of bars—

Second line: the average size of the move over the next 10 bars after the colour first appears, against the average 10-bar move on any bar.

Similar scripts

Indicators and strategies built from the same calculations.

ScriptSharesType
Pivot Point Breakout by EduardoMattjepivotlow pivothighv5 strategy
Monthly Returns of a Strategy in a Chart by QuantNomadpivothigh pivotlowv5 strategy
RSI Centered Pivots by OztheWozpivotlow pivothighv4 strategy
ABCD Strategy by kerok3gpivothigh pivotlowv5 strategy
Steven Primo's bollinger bands strategy by EduardoMattjepivothigh pivotlowv5 strategy

Upgrade and export

Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.

  • No v6-only features. v6 is not needed to run this script.

Clean v5

Verified

Nothing to change.

Does it run in Pine Script v6?

Yes

Every plotted value identical on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. It differs from the v5 version by 1 edit.

Download the v6 script

⋯// © Zeal Terminal-//@version=5+//@version=6indicator("ZigZag", overlay = true, max_lines_count = 500, max_labels_count = 500)⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 25 msYes 1,000 bars in 26 msNot measured
PineTSNot testedNot testedNot measured

“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report.

Source

Written by Zeal Terminal and published under the Mozilla Public License 2.0.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © Zeal Terminal//@version=5indicator("ZigZag", overlay = true, max_lines_count = 500, max_labels_count = 500) depth      = input.int(10, "Pivot depth", minval = 2)showLabels = input.bool(true, "Label each swing")lineCol    = input.color(#ffb74d, "Line colour") ph = ta.pivothigh(high, depth, depth)pl = ta.pivotlow(low, depth, depth) // Each confirmed pivot joins the previous one. Two highs in a row keep only// the higher, two lows only the lower.var float lastPrice = navar int   lastBar   = navar int   lastDir   = 0var line  leg       = na pivotPrice = not na(ph) ? ph : plpivotDir   = not na(ph) ? 1 : not na(pl) ? -1 : 0pivotBar   = bar_index - depth if pivotDir != 0    if pivotDir == lastDir and not na(leg)        better = pivotDir == 1 ? pivotPrice > lastPrice : pivotPrice < lastPrice        if better            line.set_xy2(leg, pivotBar, pivotPrice)            lastPrice := pivotPrice            lastBar   := pivotBar    else        if not na(lastPrice)            leg := line.new(lastBar, lastPrice, pivotBar, pivotPrice, color = lineCol, width = 2)            if showLabels                label.new(pivotBar, pivotPrice, str.tostring(pivotPrice, format.mintick),                     style = pivotDir == 1 ? label.style_label_down : label.style_label_up,                     color = color.new(lineCol, 70), textcolor = color.white, size = size.tiny)        lastPrice := pivotPrice        lastBar   := pivotBar        lastDir   := pivotDir plotshape(not na(ph), "Swing high", style = shape.triangledown, location = location.abovebar, color = #ef5350, size = size.tiny, offset = -depth)plotshape(not na(pl), "Swing low",  style = shape.triangleup,   location = location.belowbar, color = #26a69a, size = size.tiny, offset = -depth) alertcondition(not na(ph), "Swing high confirmed", "A swing high was confirmed")alertcondition(not na(pl), "Swing low confirmed",  "A swing low was confirmed")