Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (10)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$9,906$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
−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.

SettingDefaultType and rangeFeeds
Trading Directionbothstring · options ["long", "short", "both"]entry Buy close Buy entry Sell close Sell line 38 line 41
Fast Length12intfast_ma
Slow Length26intslow_ma
Signal Smoothing9intsignal
Oscillator MA TypeEMAstring · options ["SMA", "EMA"]fast_ma slow_ma
Signal Line MA TypeEMAstring · options ["SMA", "EMA"]signal
ATR Length for Supertrend 110intsupertrend1 direction1
Factor for Supertrend 13.0float · step 0.01supertrend1 direction1
ATR Length for Supertrend 220intsupertrend2 direction2
Factor for Supertrend 25.0float · step 0.01supertrend2 direction2

What it calculates

  • SMA / EMAclose, Fast Length (12) · chosen by Oscillator MA Typefast_ma · line 17
  • SMA / EMAclose, Slow Length (26) · chosen by Oscillator MA Typeslow_ma · line 18
  • SMA / EMAmacd, Signal Smoothing (9) · chosen by Signal Line MA Typesignal · 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.

closecloseprice datasma_sourceOscillator MA Typesetting · EMAfast_lengthFast Lengthsetting · 12slow_lengthSlow Lengthsetting · 26sma_signalSignal Line MA Typesetting · EMAsignal_lengthSignal Smoothingsetting · 9high · low · closehigh · low · closeprice datafactor1Factor for Supertrend 1setting · 3.0atrPeriod1ATR Length for Supertre…setting · 10factor2Factor for Supertrend 2setting · 5.0atrPeriod2ATR Length for Supertre…setting · 20openopenprice datafast_maSMA / EMA→ fast_ma · by Oscillator MA …slow_maSMA / EMA→ slow_ma · by Oscillator MA …signalSMA / EMA→ signal · by Signal Line MA …supertrend1Supertrend→ supertrend1direction1Supertrend→ direction1supertrend2Supertrend→ supertrend2direction2Supertrend→ direction2macdmacdvaluehisthistvalueisBullishisBullishconditionisBearishisBearishconditionexitLongexitLongconditionexitShortexitShortconditionentry:BuyOpen Buystrategy.entryclose:BuyClose Buystrategy.closeentry:SellOpen Sellstrategy.entryclose:SellClose Sellstrategy.closeplot:44plotplotplot:45Up Trendplotplot:46Down Trendplotfill:47Fillfill × 4fill:48Fillfill × 4plot:49plotplotplot:50Up Trendplotplot:51Down Trendplotfill:52Fillfill × 4fill:53Fillfill × 4

Order rules

OrderFires whenBy defaultLine
Open Buy longisBullishdirection1 < 0 and direction2 < 0 and hist > 0On39
Close BuyexitLongdirection1 > 0 or direction2 > 0 or hist < 0On40
Open Sell shortisBearishdirection1 > 0 and direction2 > 0 and hist < 0On42
Close SellexitShortdirection1 < 0 or direction2 < 0 or hist > 0On43

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.

9/9trades 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−0.9%+102.5%3628%0.915.3%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+1.2%+5.5%3333%1.351.3%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+7.5%+9.8%3244%1.624.5%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+0.5%+8.4%3526%1.121.3%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+3.7%+16.7%3234%1.288.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+1.9%+21.5%3040%1.401.8%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−2.9%+148.3%3631%0.745.9%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−0.2%+17.1%3529%0.951.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.

Before 26 Dec 2025 · in-sample
Factor for Supertrend 1 ↓ · ATR Length for Supertrend 1 →567910121417
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%
From 26 Dec 2025 · out-of-sample
Factor for Supertrend 1 ↓ · ATR Length for Supertrend 1 →567910121417
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 barsTradesWonP&L
Rising market1323%$33.16
Sideways market1735%−$96.05
Falling market617%−$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.

0%8%
All 36 trades
SideEntryExitBarsP&L
long29 Feb 2024 62,432.1016 Mar 2024 69,499.8016$110.98
short2 May 2024 58,365.006 May 2024 64,012.004−$99.85
short12 May 2024 60,826.0013 May 2024 61,484.001−$12.83
short22 Jun 2024 64,143.6013 Jul 2024 57,889.1021$95.49
long20 Jul 2024 66,660.001 Aug 2024 64,628.0012−$32.72
short6 Aug 2024 54,018.8020 Aug 2024 59,438.5014−$102.95
short6 Sep 2024 56,180.0013 Sep 2024 58,132.307−$36.60
long17 Oct 2024 67,620.0027 Oct 2024 67,092.8010−$9.70
long29 Oct 2024 69,962.204 Nov 2024 68,776.006−$18.75
long7 Nov 2024 75,572.0027 Nov 2024 91,965.1020$212.20
long17 Dec 2024 106,059.0019 Dec 2024 100,204.002−$57.69
long18 Jan 2025 104,077.0029 Jan 2025 101,336.0011−$28.43
long21 Feb 2025 98,305.0025 Feb 2025 91,552.904−$70.68
short27 Feb 2025 84,250.103 Mar 2025 94,270.004−$120.31
short11 Mar 2025 78,595.9016 Mar 2025 84,338.405−$73.77
short7 Apr 2025 78,430.0012 Apr 2025 83,423.805−$64.06
long3 May 2025 96,887.1018 May 2025 103,127.0015$60.34
long19 May 2025 106,454.0020 May 2025 105,574.001−$10.00
long22 May 2025 109,644.0025 May 2025 107,762.003−$18.63
long11 Jun 2025 110,274.0013 Jun 2025 105,672.002−$42.44
long10 Jul 2025 111,234.0022 Jul 2025 117,380.0012$51.44
long23 Jul 2025 119,954.0024 Jul 2025 118,756.001−$11.65
long12 Aug 2025 118,686.0018 Aug 2025 117,405.006−$12.41
long2 Oct 2025 118,595.0011 Oct 2025 112,774.009−$49.49
short12 Oct 2025 110,644.0027 Oct 2025 114,559.0015−$36.10
short4 Nov 2025 106,583.0028 Nov 2025 91,333.9024$135.73
short18 Dec 2025 86,243.2021 Dec 2025 88,360.903−$25.91
short21 Jan 2026 88,427.6016 Feb 2026 68,832.6026$213.69
short30 Mar 2026 66,010.907 Apr 2026 68,853.708−$44.81
long5 May 2026 79,861.0013 May 2026 80,504.508$5.98
short3 Jun 2026 66,760.8014 Jun 2026 64,458.0011$32.19
short28 Jun 2026 60,029.0030 Jun 2026 60,260.202−$5.81
short1 Jul 2026 58,624.702 Jul 2026 60,024.001−$25.69
long21 Aug 2026 73,027.003 Sep 2026 77,340.0013$56.41
long4 Sep 2026 81,270.405 Sep 2026 79,660.801−$21.68
long22 Sep 2026 86,620.0030 Sep 2026 83,663.608−$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.

ScriptSharesTypeNetTradesMax drawdown
Dual-Supertrend with MACD - Strategy [presentTrading] this page—v5 strategy−0.9%365.3%
[VJ] Mega Supertrend for Intraday by vikrissma ema supertrendv4 strategyNo trades on this market
MACD Long Strat by TheGrindTodayema smav4 strategy+24.0%7920.1%
Stock trending strategy by exlux99ema smav4 strategy+35.3%2114.7%
4-Hour Stochastic EMA Trend by slymnturkogluema smav4 strategyNo trades on this market
4X EMA and volume strategy by SoftKill21ema smav4 strategy+1.8%325.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.

Clean v5

VerifiedDownload the v5 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

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 17 msYes 1,000 bars in 54 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

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)