Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Supertrend - Long & Short -Sachin Ughade

A Pine Script v4 strategy built on Supertrend (1.5, 7). It has 12 order rules, 6 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade is 15 contracts and pays no commission. 8 settings; defaults include ATR Length-1 7, Factor-1 1.5 and ATR Length-2 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 - Long & Short -Sachin Ughade repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 15 of 15 trades.
How did Supertrend - Long & Short -Sachin Ughade do on BTCUSDT 1D with default settings?
+185.77%
From 26 Jan 2024 to 21 Oct 2026, over 57 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can Supertrend - Long & Short -Sachin Ughade be converted to Pine Script v5?
Yes
The upgrade takes 1 step, from v4; each was run before and after on the same candles with identical results, and the v5 script can be downloaded below.
Does Supertrend - Long & Short -Sachin Ughade use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does Supertrend - Long & Short -Sachin Ughade run in Zeal Terminal?
Yes
It compiles in 15 ms and runs 1,000 bars in 44 ms, in the browser.

BTCUSDT · 1D · default settings

  • Plot
  • Plot
  • Plot
  • Plot
  • Plot
  • Plot
  • 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 (8)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$241,557$202,527Equity from $100,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
+185.77%
$185,771.00
Buy and hold
+102.5%
same period
Closed trades
57
22 won · 35 lost
Profitable
38.6%
of closed trades
Profit factor
1.08
gross profit ÷ gross loss
Max drawdown
163.43%
−$654,024.00

One run with the author's default settings, $100,000 starting capital, commission as the script sets it. A short 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.

  • Check

    No commission

    The backtest assumes free trading. Results on any real exchange will be lower.

  • Note

    No slippage

    Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.

  • Note

    Uses an argument v6 removed

    when = on line 20, 21, 26, 27, 33, 34. The upgraded version below moves each call inside an if block.

Upgrade and export

Written in Pine Script v4. The upgrade to v5 takes 1 step, one per version, each applied to the result of the one before. A last clean-v5 pass then types the settings and moves when = into if blocks, which v6 requires. Every step runs before and after on the same candles in Zeal Terminal's engine; a step whose results differ is shown but not offered as a download. Upgrades preserve behaviour: bugs are fixed in the Review, never silently here.

  • Upgrading to v5 renames supertrend → ta.supertrend, change → ta.change.
  • 6 strategy calls use the when = argument (line 20, 21, 26, 27, 33, 34). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

Same 57 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 3: //@version=4 → //@version=5
  • Line 5: input(type = input.bool) → input.bool()
  • Line 6: input(type = input.bool) → input.bool()
  • Line 8: input(type = input.float) → input.float()
  • Line 13: supertrend → ta.supertrend
  • Line 14: supertrend → ta.supertrend
7 more edits
  • Line 15: supertrend → ta.supertrend
  • Line 16: change → ta.change
  • Line 18: change → ta.change
  • Line 22: change → ta.change
  • Line 24: change → ta.change
  • Line 29: change → ta.change
  • Line 31: change → ta.change
⋯// © MarketShree -//@version=4+//@version=5strategy("Supertrend Strategy", overlay=true, default_qty_value=15)-closs_all=input(title="Close_all_Position", type=input.bool, defval=false)+closs_all=input.bool(title="Close_all_Position", defval=false)-cancel=input(title="Check To Cancel", type=input.bool, defval=false)+cancel=input.bool(title="Check To Cancel", defval=false)atrPeriod1 = input(7, "ATR Length-1")-factor1 = input(1.5,"Factor-1",type=input.float)+factor1 = input.float(1.5,"Factor-1")atrPeriod2 = input(10, "ATR Length-2")⋯factor3 = input(3, "Factor-3")-[superTrend1, direction1] = supertrend(factor1, atrPeriod1)+[superTrend1, direction1] = ta.supertrend(factor1, atrPeriod1)-[superTrend2, direction2] = supertrend(factor2, atrPeriod2)+[superTrend2, direction2] = ta.supertrend(factor2, atrPeriod2)-[superTrend3, direction3] = supertrend(factor3, atrPeriod3)+[superTrend3, direction3] = ta.supertrend(factor3, atrPeriod3)-if change(direction1) < 0+if ta.change(direction1) < 0    strategy.entry("LONG", strategy.long)-if change(direction1) > 0+if ta.change(direction1) > 0    strategy.entry("SHORT", strategy.short)⋯strategy.cancel_all(when=cancel)-if change(direction2) < 0+if ta.change(direction2) < 0    strategy.entry("LONG", strategy.long)-if change(direction2) > 0+if ta.change(direction2) > 0    strategy.entry("SHORT", strategy.short)⋯    -if change(direction3) < 0+if ta.change(direction3) < 0    strategy.entry("LONG", strategy.long)-if change(direction3) > 0+if ta.change(direction3) > 0    strategy.entry("SHORT", strategy.short)⋯

Clean v5

VerifiedDownload the v5 script

Same 57 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 7: input() → input.int()
  • Line 9: input() → input.int()
  • Line 10: input() → input.int()
  • Line 11: input() → input.int()
  • Line 12: input() → input.int()
  • Line 20: when = closs_all → if block
5 more edits
  • Line 21: when = cancel → if block
  • Line 26: when = closs_all → if block
  • Line 27: when = cancel → if block
  • Line 33: when = closs_all → if block
  • Line 34: when = cancel → if block
⋯cancel=input.bool(title="Check To Cancel", defval=false)-atrPeriod1 = input(7, "ATR Length-1")+atrPeriod1 = input.int(7, "ATR Length-1")factor1 = input.float(1.5,"Factor-1")-atrPeriod2 = input(10, "ATR Length-2")+atrPeriod2 = input.int(10, "ATR Length-2")-factor2 = input(2, "Factor-2")+factor2 = input.int(2, "Factor-2")-atrPeriod3 = input(20, "ATR Length-3")+atrPeriod3 = input.int(20, "ATR Length-3")-factor3 = input(3, "Factor-3")+factor3 = input.int(3, "Factor-3")[superTrend1, direction1] = ta.supertrend(factor1, atrPeriod1)⋯    strategy.entry("SHORT", strategy.short)-strategy.close_all(when=closs_all,comment ="All postion are closed")+if closs_all+    strategy.close_all(comment ="All postion are closed")-strategy.cancel_all(when=cancel)+if cancel+    strategy.cancel_all()if ta.change(direction2) < 0⋯    strategy.entry("SHORT", strategy.short)-strategy.close_all(when=closs_all,comment ="All postion are closed")+if closs_all+    strategy.close_all(comment ="All postion are closed")-strategy.cancel_all(when=cancel)+if cancel+    strategy.cancel_all()    ⋯    strategy.entry("SHORT", strategy.short)-strategy.close_all(when=closs_all,comment ="All postion are closed")+if closs_all+    strategy.close_all(comment ="All postion are closed")-strategy.cancel_all(when=cancel)+if cancel+    strategy.cancel_all()colResistance = direction1 == 1 and direction1 == direction1[1] ? color.new(color.red, 0) : color.new(color.red, 100)⋯

Does it run in Pine Script v6?

No

The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 57 before, 57 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.

⋯// © MarketShree -//@version=5+//@version=6strategy("Supertrend Strategy", overlay=true, default_qty_value=15)⋯

Settings

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

SettingDefaultType and rangeFeeds
Close_all_Positionfalseboolclose_all
Check To Cancelfalseboolcancel_all
ATR Length-17intsuperTrend1 direction1
Factor-11.5floatsuperTrend1 direction1
ATR Length-210intsuperTrend2 direction2
Factor-22intsuperTrend2 direction2
ATR Length-320intsuperTrend3 direction3
Factor-33intsuperTrend3 direction3

What it calculates

  • Supertrend (supertrend, ta.supertrend in v5)Factor-1 (1.5), ATR Length-1 (7)superTrend1 · line 13
  • Supertrend (supertrend, ta.supertrend in v5)Factor-1 (1.5), ATR Length-1 (7)direction1 · line 13
  • Supertrend (supertrend, ta.supertrend in v5)Factor-2 (2), ATR Length-2 (10)superTrend2 · line 14
  • Supertrend (supertrend, ta.supertrend in v5)Factor-2 (2), ATR Length-2 (10)direction2 · line 14
  • Supertrend (supertrend, ta.supertrend in v5)Factor-3 (3), ATR Length-3 (20)superTrend3 · line 15
  • Supertrend (supertrend, ta.supertrend in v5)Factor-3 (3), ATR Length-3 (20)direction3 · line 15

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 datafactor1Factor-1setting · 1.5atrPeriod1ATR Length-1setting · 7factor2Factor-2setting · 2atrPeriod2ATR Length-2setting · 10factor3Factor-3setting · 3atrPeriod3ATR Length-3setting · 20superTrend1Supertrend→ superTrend1direction1Supertrend→ direction1superTrend2Supertrend→ superTrend2direction2Supertrend→ direction2superTrend3Supertrend→ superTrend3direction3Supertrend→ direction3colResistance, colSupport, colResistance1, colSupport1, colResistance2, colSupport2ColourcolResistance · colSupport +4entry:LONGOpen LONGstrategy.entryentry:SHORTOpen SHORTstrategy.entryclose_all:close_all strategy.close_allcancel_all:cancel_all strategy.cancel_allplot:37plotplotplot:38plotplotplot:41plotplotplot:42plotplotplot:45plotplotplot:46plotplot

Order rules

OrderFires whenBy defaultLine
Open LONG longchange(direction1) < 0On17
Open SHORT shortchange(direction1) > 0On19
Close closs_allOn20
cancel_all cancelOn21
Open LONG longchange(direction2) < 0On23
Open SHORT shortchange(direction2) > 0On25
Close closs_allOn26
cancel_all cancelOn27
Open LONG longchange(direction3) < 0On30
Open SHORT shortchange(direction3) > 0On32
Close closs_allOn33
cancel_all cancelOn34

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

Does it repaint?

No

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

15/15trades 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+185.8%+102.5%5739%1.08163.4%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−65.9%+5.5%6431%0.9292.2%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+30.3%+9.8%5336%1.2637.2%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−6.1%+8.4%6433%0.8213.8%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+1.5%+16.7%5547%1.241.4%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.2%+21.5%6040%1.200.5%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−1.4%+148.3%5739%0.948.8%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+1.0%+17.1%6835%1.151.8%8 May 2026 – 21 Oct 2026

Backtests are simulations on historical data and are not investment advice.

The trades

By market direction

At entry, last 90 barsTradesWonP&L
Rising market2232%−$633,444.00
Sideways market2552%$905,754.00
Falling market1020%−$86,538.50

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

10,339.7%

The 95th percentile of the worst drawdown when the same 57 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 135.3% to 10,339.7%; the tick is what actually happened, 150.4%. Order luck alone moves it this much.

0%11,891%
All 57 trades
SideEntryExitBarsP&L
long9 Feb 2024 45,288.7017 Mar 2024 65,300.6037$300,180.00
short17 Mar 2024 65,300.601 Apr 2024 71,280.0015−$89,690.40
long1 Apr 2024 71,280.003 Apr 2024 65,464.002−$87,240.20
short3 Apr 2024 65,464.009 Apr 2024 71,620.006−$92,340.20
long9 Apr 2024 71,620.0014 Apr 2024 63,924.505−$115,432.00
short14 Apr 2024 63,924.505 May 2024 63,892.0021$487.35
long5 May 2024 63,892.0012 Jun 2024 67,314.2038$51,333.00
short12 Jun 2024 67,314.2015 Jul 2024 60,797.9033$97,744.80
long15 Jul 2024 60,797.903 Aug 2024 61,498.3019$10,506.40
short3 Aug 2024 61,498.309 Aug 2024 61,686.006−$2,814.90
long9 Aug 2024 61,686.0028 Aug 2024 59,415.0019−$34,065.00
short28 Aug 2024 59,415.0013 Sep 2024 58,132.3016$19,240.40
long13 Sep 2024 58,132.302 Oct 2024 60,804.9019$40,089.20
short2 Oct 2024 60,804.9013 Oct 2024 63,206.2011−$36,019.70
long13 Oct 2024 63,206.204 Nov 2024 68,776.0022$83,546.40
short4 Nov 2024 68,776.007 Nov 2024 75,572.003−$101,940.00
long7 Nov 2024 75,572.0027 Nov 2024 91,965.2020$245,898.00
short27 Nov 2024 91,965.207 Dec 2024 99,740.8010−$116,635.00
long7 Dec 2024 99,740.8019 Dec 2024 100,204.0012$6,947.55
short19 Dec 2024 100,204.007 Jan 2025 102,236.0019−$30,473.90
long7 Jan 2025 102,236.009 Jan 2025 95,060.602−$107,625.00
short9 Jan 2025 95,060.6016 Jan 2025 100,497.007−$81,551.10
long16 Jan 2025 100,497.003 Feb 2025 97,700.6018−$41,951.40
short3 Feb 2025 97,700.603 Mar 2025 94,270.0028$51,459.00
long3 Mar 2025 94,270.0010 Mar 2025 80,734.507−$203,033.00
short10 Mar 2025 80,734.5013 Apr 2025 85,276.9034−$68,136.50
long13 Apr 2025 85,276.9030 May 2025 105,590.0047$304,693.00
short30 May 2025 105,590.0010 Jun 2025 110,263.0011−$70,099.10
long10 Jun 2025 110,263.0018 Jun 2025 104,551.008−$85,677.80
short18 Jun 2025 104,551.0025 Jun 2025 106,083.007−$22,977.50
long25 Jun 2025 106,083.001 Aug 2025 115,764.0037$145,216.00
short1 Aug 2025 115,764.008 Aug 2025 117,472.007−$25,619.20
long8 Aug 2025 117,472.0019 Aug 2025 116,227.0011−$18,674.60
short19 Aug 2025 116,227.0011 Sep 2025 113,960.0023$34,005.80
long11 Sep 2025 113,960.0023 Sep 2025 112,651.0012−$19,635.10
short23 Sep 2025 112,651.0030 Sep 2025 114,312.007−$24,914.70
long30 Sep 2025 114,312.0011 Oct 2025 112,774.0011−$23,062.20
short11 Oct 2025 112,774.0027 Oct 2025 114,559.0016−$26,773.80
long27 Oct 2025 114,559.0031 Oct 2025 108,323.004−$93,548.10
short31 Oct 2025 108,323.004 Dec 2025 93,429.9034$223,394.00
long4 Dec 2025 93,429.9016 Dec 2025 86,432.1012−$104,968.00
short16 Dec 2025 86,432.105 Jan 2026 91,529.7020−$76,464.90
long5 Jan 2026 91,529.7021 Jan 2026 88,427.7016−$46,531.20
short21 Jan 2026 88,427.7026 Feb 2026 67,988.0036$306,594.00
long26 Feb 2026 67,988.009 Mar 2026 65,971.2011−$30,252.60
short9 Mar 2026 65,971.2016 Mar 2026 72,815.307−$102,661.00
long16 Mar 2026 72,815.3020 Mar 2026 69,930.004−$43,278.60
short20 Mar 2026 69,930.008 Apr 2026 71,924.2019−$29,913.20
long8 Apr 2026 71,924.2017 May 2026 78,148.1039$93,357.50
short17 May 2026 78,148.1015 Jun 2026 65,746.4029$186,024.00
long15 Jun 2026 65,746.4019 Jun 2026 62,958.004−$41,826.60
short19 Jun 2026 62,958.004 Jul 2026 62,583.3015$5,621.25
long4 Jul 2026 62,583.301 Aug 2026 62,887.9028$4,569.30
short1 Aug 2026 62,887.9019 Aug 2026 64,725.4018−$27,563.10
long19 Aug 2026 64,725.4016 Sep 2026 75,644.5028$163,786.00
short16 Sep 2026 75,644.5019 Sep 2026 80,883.903−$78,590.70
long19 Sep 2026 80,883.909 Oct 2026 81,754.5020$13,059.00

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 - Long & Short -Sachin Ughade this page—v4 strategy+185.8%57163.4%
Supertrend Strategy by Zeal Terminalsupertrendv5 strategy−4.0%269.2%
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

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 15 msYes 1,000 bars in 44 msNot measured
PineTSNo v5 and v6 only—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. PineTS runs Pine Script v5 and v6 only.

Source

Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © MarketShree //@version=4strategy("Supertrend Strategy", overlay=true, default_qty_value=15)closs_all=input(title="Close_all_Position", type=input.bool, defval=false)cancel=input(title="Check To Cancel", type=input.bool, defval=false)atrPeriod1 = input(7, "ATR Length-1")factor1 = input(1.5,"Factor-1",type=input.float)atrPeriod2 = input(10, "ATR Length-2")factor2 = input(2, "Factor-2")atrPeriod3 = input(20, "ATR Length-3")factor3 = input(3, "Factor-3")[superTrend1, direction1] = supertrend(factor1, atrPeriod1)[superTrend2, direction2] = supertrend(factor2, atrPeriod2)[superTrend3, direction3] = supertrend(factor3, atrPeriod3)if change(direction1) < 0    strategy.entry("LONG", strategy.long)if change(direction1) > 0    strategy.entry("SHORT", strategy.short)strategy.close_all(when=closs_all,comment ="All postion are closed")strategy.cancel_all(when=cancel)if change(direction2) < 0    strategy.entry("LONG", strategy.long)if change(direction2) > 0    strategy.entry("SHORT", strategy.short)strategy.close_all(when=closs_all,comment ="All postion are closed")strategy.cancel_all(when=cancel)    if change(direction3) < 0    strategy.entry("LONG", strategy.long)if change(direction3) > 0    strategy.entry("SHORT", strategy.short)strategy.close_all(when=closs_all,comment ="All postion are closed")strategy.cancel_all(when=cancel)colResistance = direction1 == 1 and direction1 == direction1[1] ? color.new(color.red, 0) : color.new(color.red, 100)colSupport = direction1 == -1 and direction1 == direction1[1] ? color.new(color.green, 0) : color.new(color.green, 100)plot(superTrend1, color = colResistance, linewidth=2)plot(superTrend1, color = colSupport, linewidth=2)    colResistance1 = direction2 == 1 and direction2 == direction2[1] ? color.new(color.red, 0) : color.new(color.red, 100)colSupport1 = direction2 == -1 and direction2 == direction2[1] ? color.new(color.green, 0) : color.new(color.green, 100)plot(superTrend2, color = colResistance, linewidth=2)plot(superTrend2, color = colSupport, linewidth=2)colResistance2 = direction3 == 1 and direction3 == direction3[1] ? color.new(color.red, 0) : color.new(color.red, 100)colSupport2 = direction3 == -1 and direction3 == direction3[1] ? color.new(color.green, 0) : color.new(color.green, 100)plot(superTrend3, color = colResistance1, linewidth=2)plot(superTrend3, color = colSupport1, linewidth=2)