Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (3)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$9,867$20,253Equity from $10,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots.
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.

SettingDefaultType and rangeFeeds
Factor3.0float · min 0.5 · step 0.5st dir
ATR length10int · min 1st dir
Trade the short sidetrueboolentry 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.

high · low · closehigh · low · closeprice datafactorFactorsetting · 3.0atrLenATR lengthsetting · 10stSupertrend→ stdirSupertrend→ dirturnUpturnUpconditionturnDownturnDownconditionentry:LongOpen Longstrategy.entryentry:ShortOpen Shortstrategy.entryclose:LongClose Longstrategy.closeplot:24Up trendplotplot:25Down trendplotalertcondition:27Supertrend turns upalertconditionalertcondition:28Supertrend turns downalertcondition

Order rules

OrderFires whenBy defaultLine
Open Long longturnUpOn17
Open Short shortallowShortsOn “Trade the short side”20
Close Longstrategy.position_size > 0On22

Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.

Alerts

AlertCallMessageLine
Supertrend turns upalertconditionSupertrend direction turned up27
Supertrend turns downalertconditionSupertrend direction turned down28

Does it repaint?

No

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

6/6trades identical 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. Orders are decided once per closed bar, so nothing can change mid-bar.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D−4.0%+102.5%2631%0.779.2%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+0.3%+5.5%2438%1.072.0%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+4.3%+9.8%2343%1.259.1%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+0.2%+8.4%2227%1.032.8%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+7.9%+16.7%2339%1.554.9%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.5%+21.5%2433%1.072.8%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−2.1%+148.3%2733%0.8915.1%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−0.3%+17.1%2433%0.931.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.

Before 26 Dec 2025 · in-sample
ATR length ↓ · Factor →1.51.82.12.5533.64.25.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%
From 26 Dec 2025 · out-of-sample
ATR length ↓ · Factor →1.51.82.12.5533.64.25.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 barsTradesWonP&L
Rising market617%−$574.82
Sideways market1436%$515.24
Falling market633%−$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.

0%14%
All 26 trades
SideEntryExitBarsP&L
long10 Feb 2024 47,132.8020 Mar 2024 61,937.4039$312.79
short20 Mar 2024 61,937.4021 May 2024 71,446.6062−$159.37
long21 May 2024 71,446.6022 Jun 2024 64,143.6032−$104.70
short22 Jun 2024 64,143.6016 Jul 2024 64,724.1024−$10.10
long16 Jul 2024 64,724.104 Aug 2024 60,698.0019−$63.39
short4 Aug 2024 60,698.0024 Aug 2024 64,037.3020−$55.88
long24 Aug 2024 64,037.306 Sep 2024 56,180.0013−$122.58
short6 Sep 2024 56,180.0020 Sep 2024 62,948.0014−$119.01
long20 Sep 2024 62,948.0024 Dec 2024 94,881.5095$489.52
short24 Dec 2024 94,881.5018 Jan 2025 104,077.0025−$99.57
long18 Jan 2025 104,077.0025 Feb 2025 91,552.9038−$122.05
short25 Feb 2025 91,552.903 Mar 2025 94,270.006−$30.51
long3 Mar 2025 94,270.0011 Mar 2025 78,595.908−$165.69
short11 Mar 2025 78,595.9023 Apr 2025 93,443.0043−$185.16
long23 Apr 2025 93,443.0023 Jun 2025 100,964.0061$75.95
short23 Jun 2025 100,964.0010 Jul 2025 111,234.0017−$99.03
long10 Jul 2025 111,234.0022 Aug 2025 112,500.0043$9.90
short22 Aug 2025 112,500.002 Oct 2025 118,595.0041−$52.70
long2 Oct 2025 118,595.0011 Oct 2025 112,774.009−$47.52
short11 Oct 2025 112,774.0014 Jan 2026 95,414.0095$144.55
long14 Jan 2026 95,414.0021 Jan 2026 88,427.607−$71.15
short21 Jan 2026 88,427.605 Mar 2026 72,666.8043$168.81
long5 Mar 2026 72,666.8030 Mar 2026 66,010.9025−$89.67
short30 Mar 2026 66,010.9014 Apr 2026 74,418.0015−$123.27
long14 Apr 2026 74,418.0023 May 2026 75,539.5039$13.33
short23 May 2026 75,539.5022 Jul 2026 66,556.2060$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.

ScriptSharesTypeNetTradesMax drawdown
Supertrend Strategy this page—v5 strategy−4.0%269.2%
Supertrend - Long & Short -Sachin Ughade by hello_sachinsupertrendv4 strategy+185.8%57163.4%
Multi Supertrend with no-repaint HTF option strategy by ramki_simplesupertrendv4 strategy−18.4%3667.6%
Supertrend - Intraday by Pritesh-StocksDevelopersupertrendv5 strategyNo trades on this market
SuperTrend - Custom Screener and Dynamic Alerts by sharaaU7supertrendv4 strategy−9.7%2751.9%
Supertrend by Zeal Terminalsupertrendv5 indicatorindicator

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

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.

Download the v6 script

⋯// © 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

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 11 msYes 1,000 bars in 22 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=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")