Pine Script v5 · Indicator
Supertrend
A Pine Script v5 indicator built on Supertrend (3.0, 10). It draws 3 lines, 2 fills and 2 marker series on the price chart. It declares 2 alerts. 2 settings; defaults include ATR multiplier 3.0 and ATR period 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 Supertrend 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 Supertrend have?
- 2
- Defaults include ATR multiplier 3.0, ATR period 10.
- What alerts does Supertrend have?
- 2
- Supertrend turns up; Supertrend turns down.
- Does Supertrend 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 Supertrend draw on the price chart?
- Yes
- It is declared with overlay = true.
BTCUSDT · 1D · default settings
- Support
- Resistance
- Anchor
- Turns up
- Turns down
- Support
- 79,663.50
- on the last bar
- Resistance
- —
- not plotted on the last bar
- Anchor
- 83,766.70
- on the last bar
The value of each line the script plots, on the last of 1,000 bars, 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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| ATR multiplier | 3.0 | float · min 0.5 · step 0.5 | stLine stDir |
| ATR period | 10 | int · min 1 | stLine stDir |
What it calculates
- SupertrendATR multiplier (3.0), ATR period (10)
stLine · line 12 - SupertrendATR multiplier (3.0), ATR period (10)
stDir · line 12
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.
What it draws
| Output | Call | Value | By default | Line |
|---|---|---|---|---|
| Support | plot | isUp ? stLine : na | Shown | 17 |
| Resistance | plot | isUp ? na : stLine | Shown | 18 |
| Anchor | plot | hl2 | Shown | 19 |
| fill | fill | anchor | Shown | 22 |
| fill | fill | anchor | Shown | 23 |
| plotshape | plotshape | flipUp | Shown | 25 |
| plotshape | plotshape | flipDn | Shown | 26 |
Alerts
| Alert | Call | Message | Line |
|---|---|---|---|
| Supertrend turns up | alertcondition | Supertrend flipped to the up side | 28 |
| Supertrend turns down | alertcondition | Supertrend flipped to the down side | 29 |
Does it repaint?
No
No repainting patterns in the source, and the live replay matched history.
- 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.
| Market | Support | Resistance | Anchor |
|---|---|---|---|
| BTCUSDT 1D | 79,663.50 | — | 83,766.70 |
| BTCUSDT 4h | 82,311.00 | — | 84,646.70 |
| ETHUSDT 1D | — | 2,676.01 | 2,481.74 |
| ETHUSDT 4h | 2,392.61 | — | 2,494.32 |
| SOLUSDT 1D | — | 117.70 | 107.42 |
| SOLUSDT 4h | 102.96 | — | 108.06 |
| BNBUSDT 1D | — | 778.25 | 745.88 |
| BNBUSDT 4h | 732.18 | — | 749.72 |
Each line's value on the last bar.
Similar scripts
Indicators and strategies built from the same calculations.
| Script | Shares | Type |
|---|---|---|
| Supertrend Strategy by Zeal Terminal | supertrend | v5 strategy |
| Supertrend - Long & Short -Sachin Ughade by hello_sachin | supertrend | v4 strategy |
| Multi Supertrend with no-repaint HTF option strategy by ramki_simple | supertrend | v4 strategy |
| Supertrend - Intraday by Pritesh-StocksDeveloper | supertrend | v5 strategy |
| SuperTrend - Custom Screener and Dynamic Alerts by sharaaU7 | supertrend | v4 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
VerifiedNothing 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.
⋯// © Zeal Terminal-//@version=5+//@version=6indicator("Supertrend", overlay = true)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 14 ms | With a workaround 1,000 bars in 83 ms | Not measured |
| PineTS | Not tested | Not tested | Not measured |
The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.
“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("Supertrend", overlay = true) // Test material as well as a library entry: the renderer tests expect two// trend lines with gaps, a hidden anchor line, two fills and two marker// series, in these greens and reds (e2e/complex.spec.ts).multiplier = input.float(3.0, "ATR multiplier", minval = 0.5, step = 0.5)atrPeriod = input.int(10, "ATR period", minval = 1) [stLine, stDir] = ta.supertrend(multiplier, atrPeriod)isUp = stDir < 0flipUp = isUp and not isUp[1]flipDn = not isUp and isUp[1] longLine = plot(isUp ? stLine : na, "Support", color = color.green, style = plot.style_linebr)shortLine = plot(isUp ? na : stLine, "Resistance", color = color.red, style = plot.style_linebr)anchor = plot(hl2, "Anchor", display = display.none) // Shade between price and whichever line is active.fill(anchor, longLine, color.new(color.green, 90), fillgaps = false)fill(anchor, shortLine, color.new(color.red, 90), fillgaps = false) plotshape(flipUp, "Turns up", style = shape.triangleup, location = location.belowbar, color = color.green, size = size.small)plotshape(flipDn, "Turns down", style = shape.triangledown, location = location.abovebar, color = color.red, size = size.small) alertcondition(flipUp, "Supertrend turns up", "Supertrend flipped to the up side")alertcondition(flipDn, "Supertrend turns down", "Supertrend flipped to the down side")