Pine Script v5 · Strategy
Supertrend Strategy
A Pine Script v5 strategy built on Supertrend (3.0, 10). It has 3 order rules, 2 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 10% of equity and pays 0.05% commission. 3 settings; defaults include Factor 3.0 and ATR length 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 Strategy repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 6 of 6 trades.
- How did Supertrend Strategy do on BTCUSDT 1D with default settings?
- −3.95%
- From 26 Jan 2024 to 21 Oct 2026, over 26 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- What alerts does Supertrend Strategy have?
- 2
- Supertrend turns up; Supertrend turns down.
- Does Supertrend Strategy run in Pine Script v6?
- Yes
- Same 26 trades and the same P&L 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 Strategy use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
BTCUSDT · 1D · default settings
- Up trend
- Down trend
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −3.95%
- −$395.03
- Buy and hold
- +102.5%
- same period
- Closed trades
- 26
- 8 won · 18 lost
- Profitable
- 30.8%
- of closed trades
- Profit factor
- 0.77
- gross profit ÷ gross loss
- Max drawdown
- 9.19%
- −$947.70
One run with the author's default settings, $10,000 starting capital, commission as the script sets it. A long position was still open at the last bar. A single backtest says little about future results and is not a recommendation. Backtests are simulations on historical data and are not investment advice.
Review
What a careful reader of this script would point out, found by checking the source and the backtest.
-
Check
No stop loss
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
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 |
|---|---|---|---|
| Factor | 3.0 | float · min 0.5 · step 0.5 | st dir |
| ATR length | 10 | int · min 1 | st dir |
| Trade the short side | true | bool | entry Short line 19 |
What it calculates
- SupertrendFactor (3.0), ATR length (10)
st · line 12 - SupertrendFactor (3.0), ATR length (10)
dir · line 12
Signal flow
How price data and settings reach the orders. 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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Long long | turnUp | On | 17 |
| Open Short short | allowShorts | On “Trade the short side” | 20 |
| Close Long | strategy.position_size > 0 | On | 22 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Alerts
| Alert | Call | Message | Line |
|---|---|---|---|
| Supertrend turns up | alertcondition | Supertrend direction turned up | 27 |
| Supertrend turns down | alertcondition | Supertrend direction turned down | 28 |
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, calc_on_every_tick or realtime-only state. Orders are decided once per closed bar.
- ClearOrder timingOrders fill at the next bar's open, after the signal bar has closed.
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 row is a separate backtest over the most recent 1,000 bars.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | −4.0% | +102.5% | 26 | 31% | 0.77 | 9.2% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +0.3% | +5.5% | 24 | 38% | 1.07 | 2.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +4.3% | +9.8% | 23 | 43% | 1.25 | 9.1% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +0.2% | +8.4% | 22 | 27% | 1.03 | 2.8% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +7.9% | +16.7% | 23 | 39% | 1.55 | 4.9% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.5% | +21.5% | 24 | 33% | 1.07 | 2.8% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −2.1% | +148.3% | 27 | 33% | 0.89 | 15.1% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −0.3% | +17.1% | 24 | 33% | 0.93 | 1.9% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
Settings heatmap
Two settings that feed the entry signal, moved around their defaults. The best in-sample pair (Factor 5.1, ATR length 5) made +6.1% before 26 Dec 2025 and −0.5% after it, worse than the defaults' +0.1% after. Tuning on the past did not carry forward. 42% of the 64 combinations made money in-sample and 80% out-of-sample.
| ATR length ↓ · Factor → | 1.5 | 1.8 | 2.1 | 2.55 | 3 | 3.6 | 4.2 | 5.1 |
|---|---|---|---|---|---|---|---|---|
| 5 | +2% | −3% | −1% | −4% | +3% | +0% | −0% | +6% |
| 6 | +0% | −1% | −0% | −4% | +3% | −0% | −3% | +6% |
| 7 | +0% | −1% | +1% | −5% | +0% | −1% | +1% | +1% |
| 9 | +2% | −1% | +3% | −4% | −1% | −1% | +3% | −0% |
| 10 | +2% | +2% | +2% | −4% | −4% | −1% | −1% | −0% |
| 12 | +1% | +1% | +2% | −4% | −6% | +2% | +3% | −1% |
| 14 | −0% | −2% | +1% | −4% | −6% | +1% | +2% | −2% |
| 17 | −2% | −5% | −0% | −5% | −8% | −0% | +1% | −3% |
| ATR length ↓ · Factor → | 1.5 | 1.8 | 2.1 | 2.55 | 3 | 3.6 | 4.2 | 5.1 |
|---|---|---|---|---|---|---|---|---|
| 5 | +3% | +4% | +3% | +1% | +1% | +2% | +0% | −0% |
| 6 | +3% | +2% | +6% | +1% | +0% | +1% | +0% | −0% |
| 7 | +3% | +2% | +6% | +1% | +0% | +1% | +0% | −1% |
| 9 | +2% | +2% | +3% | +1% | +0% | +1% | −0% | −1% |
| 10 | +2% | +2% | +3% | +1% | +0% | +1% | −0% | −1% |
| 12 | +1% | +0% | +1% | +1% | +2% | +0% | −0% | −2% |
| 14 | +1% | +0% | +1% | +0% | +2% | +0% | −0% | −2% |
| 17 | +1% | +0% | +1% | +0% | +1% | +0% | −1% | −3% |
Net P&L of trades opened in each period, as a share of starting capital. marks the defaults and the best in-sample cell. Hover a cell for its trade count. Backtests are simulations on historical data and are not investment advice.
The trades
By market direction
| At entry, last 90 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 6 | 17% | −$574.82 |
| Sideways market | 14 | 36% | $515.24 |
| Falling market | 6 | 33% | −$334.96 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
12.3%
The 95th percentile of the worst drawdown when the same 26 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 5.9% to 12.3%; the tick is what actually happened, 8.4%. Order luck alone moves it this much.
All 26 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 10 Feb 2024 47,132.80 | 20 Mar 2024 61,937.40 | 39 | $312.79 |
| short | 20 Mar 2024 61,937.40 | 21 May 2024 71,446.60 | 62 | −$159.37 |
| long | 21 May 2024 71,446.60 | 22 Jun 2024 64,143.60 | 32 | −$104.70 |
| short | 22 Jun 2024 64,143.60 | 16 Jul 2024 64,724.10 | 24 | −$10.10 |
| long | 16 Jul 2024 64,724.10 | 4 Aug 2024 60,698.00 | 19 | −$63.39 |
| short | 4 Aug 2024 60,698.00 | 24 Aug 2024 64,037.30 | 20 | −$55.88 |
| long | 24 Aug 2024 64,037.30 | 6 Sep 2024 56,180.00 | 13 | −$122.58 |
| short | 6 Sep 2024 56,180.00 | 20 Sep 2024 62,948.00 | 14 | −$119.01 |
| long | 20 Sep 2024 62,948.00 | 24 Dec 2024 94,881.50 | 95 | $489.52 |
| short | 24 Dec 2024 94,881.50 | 18 Jan 2025 104,077.00 | 25 | −$99.57 |
| long | 18 Jan 2025 104,077.00 | 25 Feb 2025 91,552.90 | 38 | −$122.05 |
| short | 25 Feb 2025 91,552.90 | 3 Mar 2025 94,270.00 | 6 | −$30.51 |
| long | 3 Mar 2025 94,270.00 | 11 Mar 2025 78,595.90 | 8 | −$165.69 |
| short | 11 Mar 2025 78,595.90 | 23 Apr 2025 93,443.00 | 43 | −$185.16 |
| long | 23 Apr 2025 93,443.00 | 23 Jun 2025 100,964.00 | 61 | $75.95 |
| short | 23 Jun 2025 100,964.00 | 10 Jul 2025 111,234.00 | 17 | −$99.03 |
| long | 10 Jul 2025 111,234.00 | 22 Aug 2025 112,500.00 | 43 | $9.90 |
| short | 22 Aug 2025 112,500.00 | 2 Oct 2025 118,595.00 | 41 | −$52.70 |
| long | 2 Oct 2025 118,595.00 | 11 Oct 2025 112,774.00 | 9 | −$47.52 |
| short | 11 Oct 2025 112,774.00 | 14 Jan 2026 95,414.00 | 95 | $144.55 |
| long | 14 Jan 2026 95,414.00 | 21 Jan 2026 88,427.60 | 7 | −$71.15 |
| short | 21 Jan 2026 88,427.60 | 5 Mar 2026 72,666.80 | 43 | $168.81 |
| long | 5 Mar 2026 72,666.80 | 30 Mar 2026 66,010.90 | 25 | −$89.67 |
| short | 30 Mar 2026 66,010.90 | 14 Apr 2026 74,418.00 | 15 | −$123.27 |
| long | 14 Apr 2026 74,418.00 | 23 May 2026 75,539.50 | 39 | $13.33 |
| short | 23 May 2026 75,539.50 | 22 Jul 2026 66,556.20 | 60 | $111.96 |
Similar scripts
Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Supertrend Strategy this page | — | v5 strategy | −4.0% | 26 | 9.2% |
| Supertrend - Long & Short -Sachin Ughade by hello_sachin | supertrend | v4 strategy | +185.8% | 57 | 163.4% |
| Multi Supertrend with no-repaint HTF option strategy by ramki_simple | supertrend | v4 strategy | −18.4% | 36 | 67.6% |
| Supertrend - Intraday by Pritesh-StocksDeveloper | supertrend | v5 strategy | No trades on this market | ||
| SuperTrend - Custom Screener and Dynamic Alerts by sharaaU7 | supertrend | v4 strategy | −9.7% | 27 | 51.9% |
| Supertrend by Zeal Terminal | supertrend | v5 indicator | indicator | ||
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
Same 26 trades and the same P&L 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=6strategy("Supertrend Strategy", overlay = true, initial_capital = 10000, default_qty_type = strategy.percent_of_equity, default_qty_value = 10, commission_type = strategy.commission.percent, commission_value = 0.05, slippage = 1)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 11 ms | Yes 1,000 bars in 22 ms | Not measured |
| PineTS | Not tested | Not tested | Not 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=5strategy("Supertrend Strategy", overlay = true, initial_capital = 10000, default_qty_type = strategy.percent_of_equity, default_qty_value = 10, commission_type = strategy.commission.percent, commission_value = 0.05, slippage = 1) // Not investment advice. Follows the Supertrend direction: long when it turns// up, and short too when shorts are enabled. The line itself is the stop.factor = input.float(3.0, "Factor", minval = 0.5, step = 0.5)atrLen = input.int(10, "ATR length", minval = 1)allowShorts = input.bool(true, "Trade the short side") [st, dir] = ta.supertrend(factor, atrLen)turnUp = ta.change(dir) < 0turnDown = ta.change(dir) > 0 if turnUp strategy.entry("Long", strategy.long)if turnDown if allowShorts strategy.entry("Short", strategy.short) else if strategy.position_size > 0 strategy.close("Long", comment = "Trend exit") plot(dir < 0 ? st : na, "Up trend", color = #26a69a, style = plot.style_linebr, linewidth = 2)plot(dir > 0 ? st : na, "Down trend", color = #ef5350, style = plot.style_linebr, linewidth = 2) alertcondition(turnUp, "Supertrend turns up", "Supertrend direction turned up")alertcondition(turnDown, "Supertrend turns down", "Supertrend direction turned down")