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
- 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
VerifiedSame 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)⋯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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Close_all_Position | false | bool | close_all |
| Check To Cancel | false | bool | cancel_all |
| ATR Length-1 | 7 | int | superTrend1 direction1 |
| Factor-1 | 1.5 | float | superTrend1 direction1 |
| ATR Length-2 | 10 | int | superTrend2 direction2 |
| Factor-2 | 2 | int | superTrend2 direction2 |
| ATR Length-3 | 20 | int | superTrend3 direction3 |
| Factor-3 | 3 | int | superTrend3 direction3 |
What it calculates
- Supertrend (
supertrend,ta.supertrendin v5)Factor-1 (1.5), ATR Length-1 (7)superTrend1 · line 13 - Supertrend (
supertrend,ta.supertrendin v5)Factor-1 (1.5), ATR Length-1 (7)direction1 · line 13 - Supertrend (
supertrend,ta.supertrendin v5)Factor-2 (2), ATR Length-2 (10)superTrend2 · line 14 - Supertrend (
supertrend,ta.supertrendin v5)Factor-2 (2), ATR Length-2 (10)direction2 · line 14 - Supertrend (
supertrend,ta.supertrendin v5)Factor-3 (3), ATR Length-3 (20)superTrend3 · line 15 - Supertrend (
supertrend,ta.supertrendin 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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open LONG long | change(direction1) < 0 | On | 17 |
| Open SHORT short | change(direction1) > 0 | On | 19 |
| Close | closs_all | On | 20 |
| cancel_all | cancel | On | 21 |
| Open LONG long | change(direction2) < 0 | On | 23 |
| Open SHORT short | change(direction2) > 0 | On | 25 |
| Close | closs_all | On | 26 |
| cancel_all | cancel | On | 27 |
| Open LONG long | change(direction3) < 0 | On | 30 |
| Open SHORT short | change(direction3) > 0 | On | 32 |
| Close | closs_all | On | 33 |
| cancel_all | cancel | On | 34 |
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.
- 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 | +185.8% | +102.5% | 57 | 39% | 1.08 | 163.4% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −65.9% | +5.5% | 64 | 31% | 0.92 | 92.2% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +30.3% | +9.8% | 53 | 36% | 1.26 | 37.2% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −6.1% | +8.4% | 64 | 33% | 0.82 | 13.8% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +1.5% | +16.7% | 55 | 47% | 1.24 | 1.4% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.2% | +21.5% | 60 | 40% | 1.20 | 0.5% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −1.4% | +148.3% | 57 | 39% | 0.94 | 8.8% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +1.0% | +17.1% | 68 | 35% | 1.15 | 1.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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 22 | 32% | −$633,444.00 |
| Sideways market | 25 | 52% | $905,754.00 |
| Falling market | 10 | 20% | −$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.
All 57 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 9 Feb 2024 45,288.70 | 17 Mar 2024 65,300.60 | 37 | $300,180.00 |
| short | 17 Mar 2024 65,300.60 | 1 Apr 2024 71,280.00 | 15 | −$89,690.40 |
| long | 1 Apr 2024 71,280.00 | 3 Apr 2024 65,464.00 | 2 | −$87,240.20 |
| short | 3 Apr 2024 65,464.00 | 9 Apr 2024 71,620.00 | 6 | −$92,340.20 |
| long | 9 Apr 2024 71,620.00 | 14 Apr 2024 63,924.50 | 5 | −$115,432.00 |
| short | 14 Apr 2024 63,924.50 | 5 May 2024 63,892.00 | 21 | $487.35 |
| long | 5 May 2024 63,892.00 | 12 Jun 2024 67,314.20 | 38 | $51,333.00 |
| short | 12 Jun 2024 67,314.20 | 15 Jul 2024 60,797.90 | 33 | $97,744.80 |
| long | 15 Jul 2024 60,797.90 | 3 Aug 2024 61,498.30 | 19 | $10,506.40 |
| short | 3 Aug 2024 61,498.30 | 9 Aug 2024 61,686.00 | 6 | −$2,814.90 |
| long | 9 Aug 2024 61,686.00 | 28 Aug 2024 59,415.00 | 19 | −$34,065.00 |
| short | 28 Aug 2024 59,415.00 | 13 Sep 2024 58,132.30 | 16 | $19,240.40 |
| long | 13 Sep 2024 58,132.30 | 2 Oct 2024 60,804.90 | 19 | $40,089.20 |
| short | 2 Oct 2024 60,804.90 | 13 Oct 2024 63,206.20 | 11 | −$36,019.70 |
| long | 13 Oct 2024 63,206.20 | 4 Nov 2024 68,776.00 | 22 | $83,546.40 |
| short | 4 Nov 2024 68,776.00 | 7 Nov 2024 75,572.00 | 3 | −$101,940.00 |
| long | 7 Nov 2024 75,572.00 | 27 Nov 2024 91,965.20 | 20 | $245,898.00 |
| short | 27 Nov 2024 91,965.20 | 7 Dec 2024 99,740.80 | 10 | −$116,635.00 |
| long | 7 Dec 2024 99,740.80 | 19 Dec 2024 100,204.00 | 12 | $6,947.55 |
| short | 19 Dec 2024 100,204.00 | 7 Jan 2025 102,236.00 | 19 | −$30,473.90 |
| long | 7 Jan 2025 102,236.00 | 9 Jan 2025 95,060.60 | 2 | −$107,625.00 |
| short | 9 Jan 2025 95,060.60 | 16 Jan 2025 100,497.00 | 7 | −$81,551.10 |
| long | 16 Jan 2025 100,497.00 | 3 Feb 2025 97,700.60 | 18 | −$41,951.40 |
| short | 3 Feb 2025 97,700.60 | 3 Mar 2025 94,270.00 | 28 | $51,459.00 |
| long | 3 Mar 2025 94,270.00 | 10 Mar 2025 80,734.50 | 7 | −$203,033.00 |
| short | 10 Mar 2025 80,734.50 | 13 Apr 2025 85,276.90 | 34 | −$68,136.50 |
| long | 13 Apr 2025 85,276.90 | 30 May 2025 105,590.00 | 47 | $304,693.00 |
| short | 30 May 2025 105,590.00 | 10 Jun 2025 110,263.00 | 11 | −$70,099.10 |
| long | 10 Jun 2025 110,263.00 | 18 Jun 2025 104,551.00 | 8 | −$85,677.80 |
| short | 18 Jun 2025 104,551.00 | 25 Jun 2025 106,083.00 | 7 | −$22,977.50 |
| long | 25 Jun 2025 106,083.00 | 1 Aug 2025 115,764.00 | 37 | $145,216.00 |
| short | 1 Aug 2025 115,764.00 | 8 Aug 2025 117,472.00 | 7 | −$25,619.20 |
| long | 8 Aug 2025 117,472.00 | 19 Aug 2025 116,227.00 | 11 | −$18,674.60 |
| short | 19 Aug 2025 116,227.00 | 11 Sep 2025 113,960.00 | 23 | $34,005.80 |
| long | 11 Sep 2025 113,960.00 | 23 Sep 2025 112,651.00 | 12 | −$19,635.10 |
| short | 23 Sep 2025 112,651.00 | 30 Sep 2025 114,312.00 | 7 | −$24,914.70 |
| long | 30 Sep 2025 114,312.00 | 11 Oct 2025 112,774.00 | 11 | −$23,062.20 |
| short | 11 Oct 2025 112,774.00 | 27 Oct 2025 114,559.00 | 16 | −$26,773.80 |
| long | 27 Oct 2025 114,559.00 | 31 Oct 2025 108,323.00 | 4 | −$93,548.10 |
| short | 31 Oct 2025 108,323.00 | 4 Dec 2025 93,429.90 | 34 | $223,394.00 |
| long | 4 Dec 2025 93,429.90 | 16 Dec 2025 86,432.10 | 12 | −$104,968.00 |
| short | 16 Dec 2025 86,432.10 | 5 Jan 2026 91,529.70 | 20 | −$76,464.90 |
| long | 5 Jan 2026 91,529.70 | 21 Jan 2026 88,427.70 | 16 | −$46,531.20 |
| short | 21 Jan 2026 88,427.70 | 26 Feb 2026 67,988.00 | 36 | $306,594.00 |
| long | 26 Feb 2026 67,988.00 | 9 Mar 2026 65,971.20 | 11 | −$30,252.60 |
| short | 9 Mar 2026 65,971.20 | 16 Mar 2026 72,815.30 | 7 | −$102,661.00 |
| long | 16 Mar 2026 72,815.30 | 20 Mar 2026 69,930.00 | 4 | −$43,278.60 |
| short | 20 Mar 2026 69,930.00 | 8 Apr 2026 71,924.20 | 19 | −$29,913.20 |
| long | 8 Apr 2026 71,924.20 | 17 May 2026 78,148.10 | 39 | $93,357.50 |
| short | 17 May 2026 78,148.10 | 15 Jun 2026 65,746.40 | 29 | $186,024.00 |
| long | 15 Jun 2026 65,746.40 | 19 Jun 2026 62,958.00 | 4 | −$41,826.60 |
| short | 19 Jun 2026 62,958.00 | 4 Jul 2026 62,583.30 | 15 | $5,621.25 |
| long | 4 Jul 2026 62,583.30 | 1 Aug 2026 62,887.90 | 28 | $4,569.30 |
| short | 1 Aug 2026 62,887.90 | 19 Aug 2026 64,725.40 | 18 | −$27,563.10 |
| long | 19 Aug 2026 64,725.40 | 16 Sep 2026 75,644.50 | 28 | $163,786.00 |
| short | 16 Sep 2026 75,644.50 | 19 Sep 2026 80,883.90 | 3 | −$78,590.70 |
| long | 19 Sep 2026 80,883.90 | 9 Oct 2026 81,754.50 | 20 | $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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Supertrend - Long & Short -Sachin Ughade this page | — | v4 strategy | +185.8% | 57 | 163.4% |
| Supertrend Strategy by Zeal Terminal | supertrend | v5 strategy | −4.0% | 26 | 9.2% |
| 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 | ||
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 15 ms | Yes 1,000 bars in 44 ms | Not measured |
| PineTS | No 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)