Pine Script v5 · Strategy
Dual-Supertrend with MACD - Strategy [presentTrading]
A Pine Script v5 strategy built on SMA or EMA (close, 12) and Supertrend (3.0, 10). It has 4 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.1% commission. 10 settings; defaults include Trading Direction both, Fast Length 12 and Slow Length 26.
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 Dual-Supertrend with MACD - Strategy [presentTrading] repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 9 of 9 trades.
- How did Dual-Supertrend with MACD - Strategy [presentTrading] do on BTCUSDT 1D with default settings?
- −0.94%
- From 26 Jan 2024 to 21 Oct 2026, over 36 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does Dual-Supertrend with MACD - Strategy [presentTrading] run in Pine Script v6?
- No
- The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L7:C25: the argument 'default_qty_type' is specified more than once. The v6 version is shown for reference and is not offered as a download.
- Does Dual-Supertrend with MACD - Strategy [presentTrading] use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Dual-Supertrend with MACD - Strategy [presentTrading] run in Zeal Terminal?
- Yes
- It compiles in 17 ms and runs 1,000 bars in 54 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Up Trend
- Down Trend
- Plot
- Up Trend
- Down Trend
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −0.94%
- −$94.34
- Buy and hold
- +102.5%
- same period
- Closed trades
- 36
- 10 won · 26 lost
- Profitable
- 27.8%
- of closed trades
- Profit factor
- 0.91
- gross profit ÷ gross loss
- Max drawdown
- 5.35%
- −$540.66
One run with the author's default settings, $10,000 starting capital, commission as the script sets it. 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.
-
Note
Uses an argument v6 removed
when = on line 39, 40, 42, 43. The upgraded version below moves each call inside an if block.
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 |
|---|---|---|---|
| Trading Direction | both | string · options ["long", "short", "both"] | entry Buy close Buy entry Sell close Sell line 38 line 41 |
| Fast Length | 12 | int | fast_ma |
| Slow Length | 26 | int | slow_ma |
| Signal Smoothing | 9 | int | signal |
| Oscillator MA Type | EMA | string · options ["SMA", "EMA"] | fast_ma slow_ma |
| Signal Line MA Type | EMA | string · options ["SMA", "EMA"] | signal |
| ATR Length for Supertrend 1 | 10 | int | supertrend1 direction1 |
| Factor for Supertrend 1 | 3.0 | float · step 0.01 | supertrend1 direction1 |
| ATR Length for Supertrend 2 | 20 | int | supertrend2 direction2 |
| Factor for Supertrend 2 | 5.0 | float · step 0.01 | supertrend2 direction2 |
What it calculates
- SMA / EMAclose, Fast Length (12) · chosen by Oscillator MA Type
fast_ma · line 17 - SMA / EMAclose, Slow Length (26) · chosen by Oscillator MA Type
slow_ma · line 18 - SMA / EMAmacd, Signal Smoothing (9) · chosen by Signal Line MA Type
signal · line 20 - SupertrendFactor for Supertrend 1 (3.0), ATR Length for Supertrend 1 (10)
supertrend1 · line 26 - SupertrendFactor for Supertrend 1 (3.0), ATR Length for Supertrend 1 (10)
direction1 · line 26 - SupertrendFactor for Supertrend 2 (5.0), ATR Length for Supertrend 2 (20)
supertrend2 · line 31 - SupertrendFactor for Supertrend 2 (5.0), ATR Length for Supertrend 2 (20)
direction2 · line 31
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 Buy long | isBullishdirection1 < 0 and direction2 < 0 and hist > 0 | On | 39 |
| Close Buy | exitLongdirection1 > 0 or direction2 > 0 or hist < 0 | On | 40 |
| Open Sell short | isBearishdirection1 > 0 and direction2 > 0 and hist < 0 | On | 42 |
| Close Sell | exitShortdirection1 < 0 or direction2 < 0 or hist > 0 | On | 43 |
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 | −0.9% | +102.5% | 36 | 28% | 0.91 | 5.3% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +1.2% | +5.5% | 33 | 33% | 1.35 | 1.3% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +7.5% | +9.8% | 32 | 44% | 1.62 | 4.5% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +0.5% | +8.4% | 35 | 26% | 1.12 | 1.3% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +3.7% | +16.7% | 32 | 34% | 1.28 | 8.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +1.9% | +21.5% | 30 | 40% | 1.40 | 1.8% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −2.9% | +148.3% | 36 | 31% | 0.74 | 5.9% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −0.2% | +17.1% | 35 | 29% | 0.95 | 1.4% | 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 (ATR Length for Supertrend 1 7, Factor for Supertrend 1 4.2) made −0.0% before 26 Dec 2025 and +0.9% after it, worse than the defaults' +1.7% after. Tuning on the past did not carry forward. 0% of the 64 combinations made money in-sample and 100% out-of-sample.
| Factor for Supertrend 1 ↓ · ATR Length for Supertrend 1 → | 5 | 6 | 7 | 9 | 10 | 12 | 14 | 17 |
|---|---|---|---|---|---|---|---|---|
| 1.5 | −1% | −2% | −2% | −2% | −2% | −2% | −2% | −2% |
| 1.8 | −2% | −2% | −2% | −2% | −2% | −2% | −2% | −3% |
| 2.1 | −3% | −2% | −3% | −3% | −3% | −3% | −3% | −3% |
| 2.55 | −4% | −3% | −3% | −3% | −3% | −3% | −3% | −4% |
| 3 | −1% | −1% | −2% | −2% | −3% | −3% | −3% | −3% |
| 3.6 | −1% | −1% | −1% | −1% | −1% | −1% | −2% | −1% |
| 4.2 | −1% | −1% | −0% | −0% | −1% | −0% | −0% | −0% |
| 5.1 | −1% | −1% | −1% | −2% | −2% | −2% | −2% | −2% |
| Factor for Supertrend 1 ↓ · ATR Length for Supertrend 1 → | 5 | 6 | 7 | 9 | 10 | 12 | 14 | 17 |
|---|---|---|---|---|---|---|---|---|
| 1.5 | +1% | +1% | +1% | +1% | +1% | +1% | +1% | +1% |
| 1.8 | +1% | +1% | +1% | +1% | +1% | +1% | +1% | +1% |
| 2.1 | +1% | +2% | +2% | +2% | +2% | +2% | +2% | +2% |
| 2.55 | +2% | +2% | +2% | +2% | +2% | +2% | +2% | +2% |
| 3 | +2% | +2% | +2% | +2% | +2% | +2% | +2% | +2% |
| 3.6 | +2% | +2% | +2% | +2% | +2% | +2% | +1% | +1% |
| 4.2 | +1% | +1% | +1% | +1% | +1% | +1% | +1% | +1% |
| 5.1 | +1% | +1% | +1% | +1% | +1% | +1% | +1% | +1% |
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 | 13 | 23% | $33.16 |
| Sideways market | 17 | 35% | −$96.05 |
| Falling market | 6 | 17% | −$31.45 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
6.7%
The 95th percentile of the worst drawdown when the same 36 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 3.0% to 6.7%; the tick is what actually happened, 4.8%. Order luck alone moves it this much.
All 36 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 29 Feb 2024 62,432.10 | 16 Mar 2024 69,499.80 | 16 | $110.98 |
| short | 2 May 2024 58,365.00 | 6 May 2024 64,012.00 | 4 | −$99.85 |
| short | 12 May 2024 60,826.00 | 13 May 2024 61,484.00 | 1 | −$12.83 |
| short | 22 Jun 2024 64,143.60 | 13 Jul 2024 57,889.10 | 21 | $95.49 |
| long | 20 Jul 2024 66,660.00 | 1 Aug 2024 64,628.00 | 12 | −$32.72 |
| short | 6 Aug 2024 54,018.80 | 20 Aug 2024 59,438.50 | 14 | −$102.95 |
| short | 6 Sep 2024 56,180.00 | 13 Sep 2024 58,132.30 | 7 | −$36.60 |
| long | 17 Oct 2024 67,620.00 | 27 Oct 2024 67,092.80 | 10 | −$9.70 |
| long | 29 Oct 2024 69,962.20 | 4 Nov 2024 68,776.00 | 6 | −$18.75 |
| long | 7 Nov 2024 75,572.00 | 27 Nov 2024 91,965.10 | 20 | $212.20 |
| long | 17 Dec 2024 106,059.00 | 19 Dec 2024 100,204.00 | 2 | −$57.69 |
| long | 18 Jan 2025 104,077.00 | 29 Jan 2025 101,336.00 | 11 | −$28.43 |
| long | 21 Feb 2025 98,305.00 | 25 Feb 2025 91,552.90 | 4 | −$70.68 |
| short | 27 Feb 2025 84,250.10 | 3 Mar 2025 94,270.00 | 4 | −$120.31 |
| short | 11 Mar 2025 78,595.90 | 16 Mar 2025 84,338.40 | 5 | −$73.77 |
| short | 7 Apr 2025 78,430.00 | 12 Apr 2025 83,423.80 | 5 | −$64.06 |
| long | 3 May 2025 96,887.10 | 18 May 2025 103,127.00 | 15 | $60.34 |
| long | 19 May 2025 106,454.00 | 20 May 2025 105,574.00 | 1 | −$10.00 |
| long | 22 May 2025 109,644.00 | 25 May 2025 107,762.00 | 3 | −$18.63 |
| long | 11 Jun 2025 110,274.00 | 13 Jun 2025 105,672.00 | 2 | −$42.44 |
| long | 10 Jul 2025 111,234.00 | 22 Jul 2025 117,380.00 | 12 | $51.44 |
| long | 23 Jul 2025 119,954.00 | 24 Jul 2025 118,756.00 | 1 | −$11.65 |
| long | 12 Aug 2025 118,686.00 | 18 Aug 2025 117,405.00 | 6 | −$12.41 |
| long | 2 Oct 2025 118,595.00 | 11 Oct 2025 112,774.00 | 9 | −$49.49 |
| short | 12 Oct 2025 110,644.00 | 27 Oct 2025 114,559.00 | 15 | −$36.10 |
| short | 4 Nov 2025 106,583.00 | 28 Nov 2025 91,333.90 | 24 | $135.73 |
| short | 18 Dec 2025 86,243.20 | 21 Dec 2025 88,360.90 | 3 | −$25.91 |
| short | 21 Jan 2026 88,427.60 | 16 Feb 2026 68,832.60 | 26 | $213.69 |
| short | 30 Mar 2026 66,010.90 | 7 Apr 2026 68,853.70 | 8 | −$44.81 |
| long | 5 May 2026 79,861.00 | 13 May 2026 80,504.50 | 8 | $5.98 |
| short | 3 Jun 2026 66,760.80 | 14 Jun 2026 64,458.00 | 11 | $32.19 |
| short | 28 Jun 2026 60,029.00 | 30 Jun 2026 60,260.20 | 2 | −$5.81 |
| short | 1 Jul 2026 58,624.70 | 2 Jul 2026 60,024.00 | 1 | −$25.69 |
| long | 21 Aug 2026 73,027.00 | 3 Sep 2026 77,340.00 | 13 | $56.41 |
| long | 4 Sep 2026 81,270.40 | 5 Sep 2026 79,660.80 | 1 | −$21.68 |
| long | 22 Sep 2026 86,620.00 | 30 Sep 2026 83,663.60 | 8 | −$35.85 |
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 |
|---|---|---|---|---|---|
| Dual-Supertrend with MACD - Strategy [presentTrading] this page | — | v5 strategy | −0.9% | 36 | 5.3% |
| [VJ] Mega Supertrend for Intraday by vikris | sma ema supertrend | v4 strategy | No trades on this market | ||
| MACD Long Strat by TheGrindToday | ema sma | v4 strategy | +24.0% | 79 | 20.1% |
| Stock trending strategy by exlux99 | ema sma | v4 strategy | +35.3% | 21 | 14.7% |
| 4-Hour Stochastic EMA Trend by slymnturkoglu | ema sma | v4 strategy | No trades on this market | ||
| 4X EMA and volume strategy by SoftKill21 | ema sma | v4 strategy | +1.8% | 3 | 25.8% |
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.
- 4 strategy calls use the when = argument (line 39, 40, 42, 43). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
- 5 settings use the untyped input() (line 11, 12, 13, 23, 28). It still compiles in v6; input.int, input.float or input.source state the type.
- No v6-only features. v6 is not needed to run this script.
Same 36 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 11: input() → input.int()
- Line 12: input() → input.int()
- Line 13: input() → input.int()
- Line 23: input() → input.int()
- Line 28: input() → input.int()
- Line 39: when = isBullish → if block
3 more edits
- Line 40: when = exitLong → if block
- Line 42: when = isBearish → if block
- Line 43: when = exitShort → if block
⋯// MACD Inputs-fast_length = input(12, "Fast Length")+fast_length = input.int(12, "Fast Length")-slow_length = input(26, "Slow Length")+slow_length = input.int(26, "Slow Length")-signal_length = input(9, "Signal Smoothing")+signal_length = input.int(9, "Signal Smoothing")sma_source = input.string("EMA", "Oscillator MA Type", options=["SMA", "EMA"])⋯// Input Parameters for Supertrend 1-atrPeriod1 = input(10, "ATR Length for Supertrend 1")+atrPeriod1 = input.int(10, "ATR Length for Supertrend 1")factor1 = input.float(3.0, "Factor for Supertrend 1", step=0.01)⋯// Input Parameters for Supertrend 2-atrPeriod2 = input(20, "ATR Length for Supertrend 2")+atrPeriod2 = input.int(20, "ATR Length for Supertrend 2")factor2 = input.float(5.0, "Factor for Supertrend 2", step=0.01)⋯if (tradeDirection == "both" or tradeDirection == "long")- strategy.entry("Buy", strategy.long, when=isBullish)+ if isBullish+ strategy.entry("Buy", strategy.long)- strategy.close("Buy", when=exitLong)+ if exitLong+ strategy.close("Buy")if (tradeDirection == "both" or tradeDirection == "short")- strategy.entry("Sell", strategy.short, when=isBearish)+ if isBearish+ strategy.entry("Sell", strategy.short)- strategy.close("Sell", when=exitShort)+ if exitShort+ strategy.close("Sell")bodyMiddle1 = plot((open + close) / 2, display=display.none)⋯Does it run in Pine Script v6?
No
The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L7:C25: the argument 'default_qty_type' is specified more than once. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © PresentTrading-//@version=5+//@version=6// Define the strategy settings⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 17 ms | Yes 1,000 bars in 54 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
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/// © PresentTrading//@version=5// Define the strategy settingsstrategy("Dual-Supertrend with MACD - Strategy [presentTrading]", overlay=true, precision=3, default_qty_type=strategy.cash, commission_value= 0.1, commission_type=strategy.commission.percent, slippage= 1, currency=currency.USD, default_qty_type = strategy.percent_of_equity, default_qty_value = 10, initial_capital= 10000)// Trading Direction DropdowntradeDirection = input.string("both", "Trading Direction", options=["long", "short", "both"])// MACD Inputsfast_length = input(12, "Fast Length")slow_length = input(26, "Slow Length")signal_length = input(9, "Signal Smoothing")sma_source = input.string("EMA", "Oscillator MA Type", options=["SMA", "EMA"])sma_signal = input.string("EMA", "Signal Line MA Type", options=["SMA", "EMA"])// MACD Calculationfast_ma = sma_source == "SMA" ? ta.sma(close, fast_length) : ta.ema(close, fast_length)slow_ma = sma_source == "SMA" ? ta.sma(close, slow_length) : ta.ema(close, slow_length)macd = fast_ma - slow_masignal = sma_signal == "SMA" ? ta.sma(macd, signal_length) : ta.ema(macd, signal_length)hist = macd - signal// Input Parameters for Supertrend 1atrPeriod1 = input(10, "ATR Length for Supertrend 1")factor1 = input.float(3.0, "Factor for Supertrend 1", step=0.01)// Supertrend Calculation for 1[supertrend1, direction1] = ta.supertrend(factor1, atrPeriod1)// Input Parameters for Supertrend 2atrPeriod2 = input(20, "ATR Length for Supertrend 2")factor2 = input.float(5.0, "Factor for Supertrend 2", step=0.01)// Supertrend Calculation for 2[supertrend2, direction2] = ta.supertrend(factor2, atrPeriod2)// Combined ConditionsisBullish = direction1 < 0 and direction2 < 0 and hist > 0isBearish = direction1 > 0 and direction2 > 0 and hist < 0exitLong = direction1 > 0 or direction2 > 0 or hist < 0exitShort = direction1 < 0 or direction2 < 0 or hist > 0// Strategy Entry and Exit based on Trading Directionif (tradeDirection == "both" or tradeDirection == "long") strategy.entry("Buy", strategy.long, when=isBullish) strategy.close("Buy", when=exitLong)if (tradeDirection == "both" or tradeDirection == "short") strategy.entry("Sell", strategy.short, when=isBearish) strategy.close("Sell", when=exitShort)bodyMiddle1 = plot((open + close) / 2, display=display.none)upTrend1 = plot(direction1 < 0 ? supertrend1 : na, "Up Trend", color = color.green, style=plot.style_linebr)downTrend1 = plot(direction1 < 0? na : supertrend1, "Down Trend", color = color.red, style=plot.style_linebr)fill(bodyMiddle1, upTrend1, color.new(color.green, 90), fillgaps=false)fill(bodyMiddle1, downTrend1, color.new(color.red, 90), fillgaps=false)bodyMiddle2 = plot((open + close) / 2, display=display.none)upTrend2 = plot(direction2 < 0 ? supertrend2 : na, "Up Trend", color = color.green, style=plot.style_linebr)downTrend2 = plot(direction2 < 0? na : supertrend2, "Down Trend", color = color.red, style=plot.style_linebr)fill(bodyMiddle2, upTrend2, color.new(color.green, 90), fillgaps=false)fill(bodyMiddle2, downTrend2, color.new(color.red, 90), fillgaps=false)