Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

MACD+ Strategy [SystemAlpha]

A Pine Script v4 strategy built on EMA (close, 12), Crossover (delta, 0) and Crossunder (delta, 0). It has 2 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 100% of equity and pays 0.04% commission. 10 settings; defaults include Fast Length 12, Slow Length 26 and MACD Length 9.

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 MACD+ Strategy [SystemAlpha] repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 22 of 22 trades.
How did MACD+ Strategy [SystemAlpha] do on BTCUSDT 1D with default settings?
+2.85%
From 26 Jan 2024 to 21 Oct 2026, over 76 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can MACD+ Strategy [SystemAlpha] 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 MACD+ Strategy [SystemAlpha] use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does MACD+ Strategy [SystemAlpha] run in Zeal Terminal?
Yes
It compiles in 9 ms and runs 1,000 bars in 33 ms, in the browser.

BTCUSDT · 1D · default settings

  • EMA
  • EMA
  • Crossover
  • Crossunder
  • 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)
0.0050,000100,000AprJulOct2025AprJulOct2026AprJulOct$10,157$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. The script plots nothing itself; the lines and the lower pane are its own calculations, drawn for reference.
Net profit
+2.85%
$285.32
Buy and hold
+102.5%
same period
Closed trades
76
25 won · 51 lost
Profitable
32.9%
of closed trades
Profit factor
1.01
gross profit ÷ gross loss
Max drawdown
48.01%
−$7,454.91

One run with the author's default settings, $10,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

    Every trade uses all the equity

    default_qty_value is 100% of equity.

  • Note

    No slippage

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

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 ema → ta.ema, crossover → ta.crossover, crossunder → ta.crossunder.

v4 → v5

Verified

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

  • Line 3: //@version=4 → //@version=5
  • Line 14: ema → ta.ema
  • Line 14: ema → ta.ema
  • Line 15: ema → ta.ema
  • Line 18: crossover → ta.crossover
  • Line 19: crossunder → ta.crossunder
⋯// © systemalphatrader-//@version=4+//@version=5strategy(title="MACD Strategy", shorttitle="MACD Strategy [PUBLIC]", overlay=true, initial_capital=10000, currency='USD', ⋯MACDLength = input(9, title="MACD Length")-MACD = ema(close, fastLength) - ema(close, slowlength)+MACD = ta.ema(close, fastLength) - ta.ema(close, slowlength)-aMACD = ema(MACD, MACDLength)+aMACD = ta.ema(MACD, MACDLength)delta = MACD - aMACD// Calc breakouts-buySignal        = crossover(delta, 0)+buySignal        = ta.crossover(delta, 0)-shortSignal      = crossunder(delta,0)+shortSignal      = ta.crossunder(delta,0)// == /MACD ==⋯

Clean v5

VerifiedDownload the v5 script

Same 76 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 25: input() → input.int()
  • Line 26: input() → input.int()
  • Line 27: input() → input.int()
4 more edits
  • Line 28: input() → input.int()
  • Line 29: input() → input.int()
  • Line 30: input() → input.int()
  • Line 38: input() → input.string()
⋯// == MACD ==-fastLength = input(12, title="Fast Length")+fastLength = input.int(12, title="Fast Length")-slowlength = input(26, title="Slow Length")+slowlength = input.int(26, title="Slow Length")-MACDLength = input(9, title="MACD Length")+MACDLength = input.int(9, title="MACD Length")MACD = ta.ema(close, fastLength) - ta.ema(close, slowlength)⋯// === BACKTEST RANGE ===-From_Year   = input(defval = 2017, title = "BACKTEST: From Year")+From_Year   = input.int(defval = 2017, title = "BACKTEST: From Year")-From_Month  = input(defval = 1, title = "BACKTEST: From Month", minval = 1, maxval = 12)+From_Month  = input.int(defval = 1, title = "BACKTEST: From Month", minval = 1, maxval = 12)-From_Day    = input(defval = 1, title = "BACKTEST: From Day", minval = 1, maxval = 31)+From_Day    = input.int(defval = 1, title = "BACKTEST: From Day", minval = 1, maxval = 31)-To_Year     = input(defval = 9999, title = "BACKTEST: To Year")+To_Year     = input.int(defval = 9999, title = "BACKTEST: To Year")-To_Month    = input(defval = 1, title = "BACKTEST: To Month", minval = 1, maxval = 12)+To_Month    = input.int(defval = 1, title = "BACKTEST: To Month", minval = 1, maxval = 12)-To_Day      = input(defval = 1, title = "BACKTEST: To Day", minval = 1, maxval = 31)+To_Day      = input.int(defval = 1, title = "BACKTEST: To Day", minval = 1, maxval = 31)Start       = timestamp(From_Year, From_Month, From_Day, 00, 00)  // backtest start window⋯// Make input option to configure trade direction-tradeDirection = input(title="Trade Direction", defval="Both", options=["Long", "Short", "Both"]) +tradeDirection = input.string(title="Trade Direction", defval="Both", options=["Long", "Short", "Both"]) // Translate input into trading conditions⋯

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: 76 before, 77 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.

⋯// © systemalphatrader-//@version=5+//@version=6strategy(title="MACD Strategy", shorttitle="MACD Strategy [PUBLIC]", overlay=true, initial_capital=10000, currency='USD', ⋯

Settings

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

SettingDefaultType and rangeFeeds
Fast Length12intMACD
Slow Length26intMACD
MACD Length9intaMACD
BACKTEST: From Year2017intStart
BACKTEST: From Month1int · min 1 · max 12Start
BACKTEST: From Day1int · min 1 · max 31Start
BACKTEST: To Year9999intFinish
BACKTEST: To Month1int · min 1 · max 12Finish
BACKTEST: To Day1int · min 1 · max 31Finish
Trade DirectionBothstring · options ["Long", "Short", "Both"]longOK shortOK

What it calculates

  • EMA (ema, ta.ema in v5)close, Fast Length (12)MACD · line 14
  • EMA (ema, ta.ema in v5)MACD, MACD Length (9)aMACD · line 15
  • Crossover (crossover, ta.crossover in v5)delta, 0buySignal · line 18
  • Crossunder (crossunder, ta.crossunder in v5)delta, 0shortSignal · line 19

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 datafastLengthFast Lengthsetting · 12slowlengthSlow Lengthsetting · 26MACDLengthMACD Lengthsetting · 9From_YearBACKTEST: From Yearsetting · 2017From_MonthBACKTEST: From Monthsetting · 1From_DayBACKTEST: From Daysetting · 1To_YearBACKTEST: To Yearsetting · 9999To_MonthBACKTEST: To Monthsetting · 1To_DayBACKTEST: To Daysetting · 1tradeDirectionTrade Directionsetting · BothMACDEMA→ MACDaMACDEMA→ aMACDbuySignalCrossover→ buySignalshortSignalCrossunder→ shortSignaldeltadeltavalueStartStartvalueFinishFinishvaluelongConditionlongConditionconditionshortconditionshortconditionconditionlongOK, shortOKlongOK · shortOK2 conditionsentry:LongOpen Longstrategy.entryentry:ShortOpen Shortstrategy.entry

Order rules

OrderFires whenBy defaultLine
Open Long longlongConditionOn47
Open Short shortshortconditionOn50

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.

22/22trades 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+2.9%+102.5%7633%1.0148.0%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+20.4%+5.5%6835%1.2813.9%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−54.6%+9.8%7232%0.7877.4%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−2.8%+8.4%7626%0.9831.8%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+45.2%+16.7%6349%1.1173.7%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−10.5%+21.5%7033%0.9136.7%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−58.0%+148.3%6843%0.6063.7%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−2.8%+17.1%7732%0.9722.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 market2730%−$2,377.42
Sideways market3441%$3,300.10
Falling market1520%−$633.25

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

How bad could the drawdown be?

61.6%

The 95th percentile of the worst drawdown when the same 76 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 33.7% to 61.6%; the tick is what actually happened, 47.4%. Order luck alone moves it this much.

0%71%
All 76 trades
SideEntryExitBarsP&L
short16 Mar 2024 69,499.806 May 2024 64,012.0051$781.62
long6 May 2024 64,012.0012 May 2024 60,826.006−$545.00
short12 May 2024 60,826.0013 May 2024 61,484.001−$118.97
long13 May 2024 61,484.0031 May 2024 68,352.2018$1,121.67
short31 May 2024 68,352.206 Jun 2024 71,108.006−$462.32
long6 Jun 2024 71,108.009 Jun 2024 69,310.503−$280.95
short9 Jun 2024 69,310.5013 Jul 2024 57,889.1034$1,721.89
long13 Jul 2024 57,889.101 Aug 2024 64,628.0019$1,411.80
short1 Aug 2024 64,628.0020 Aug 2024 59,438.5019$1,083.98
long20 Aug 2024 59,438.5031 Aug 2024 59,124.0011−$89.59
short31 Aug 2024 59,124.0013 Sep 2024 58,132.3013$233.69
long13 Sep 2024 58,132.302 Oct 2024 60,804.9019$670.91
short2 Oct 2024 60,804.9015 Oct 2024 66,084.0013−$1,361.17
long15 Oct 2024 66,084.0027 Oct 2024 67,092.8012$204.86
short27 Oct 2024 67,092.8029 Oct 2024 69,962.202−$626.43
long29 Oct 2024 69,962.204 Nov 2024 68,776.006−$243.98
short4 Nov 2024 68,776.007 Nov 2024 75,572.003−$1,345.52
long7 Nov 2024 75,572.0027 Nov 2024 91,965.2020$2,626.45
short27 Nov 2024 91,965.2017 Dec 2024 106,059.0020−$2,278.19
long17 Dec 2024 106,059.0019 Dec 2024 100,204.002−$700.12
short19 Dec 2024 100,204.006 Jan 2025 98,363.6018$207.45
long6 Jan 2025 98,363.6010 Jan 2025 92,552.504−$718.97
short10 Jan 2025 92,552.5016 Jan 2025 100,497.006−$978.84
long16 Jan 2025 100,497.0029 Jan 2025 101,336.0013$77.74
short29 Jan 2025 101,336.0021 Feb 2025 98,305.0023$302.59
long21 Feb 2025 98,305.0025 Feb 2025 91,552.904−$742.81
short25 Feb 2025 91,552.907 Mar 2025 89,931.9010$168.31
long7 Mar 2025 89,931.909 Mar 2025 86,222.502−$425.35
short9 Mar 2025 86,222.5016 Mar 2025 84,338.407$204.17
long16 Mar 2025 84,338.407 Apr 2025 78,430.0022−$701.11
short7 Apr 2025 78,430.0012 Apr 2025 83,423.805−$593.24
long12 Apr 2025 83,423.8018 May 2025 103,127.0036$2,024.62
short18 May 2025 103,127.0019 May 2025 106,454.001−$351.62
long19 May 2025 106,454.0020 May 2025 105,574.001−$93.20
short20 May 2025 105,574.0022 May 2025 109,644.002−$400.95
long22 May 2025 109,644.0025 May 2025 107,762.003−$175.70
short25 May 2025 107,762.0011 Jun 2025 110,274.0017−$231.78
long11 Jun 2025 110,274.0013 Jun 2025 105,672.002−$398.69
short13 Jun 2025 105,672.0027 Jun 2025 106,947.0014−$115.57
long27 Jun 2025 106,947.0022 Jul 2025 117,380.0025$857.08
short22 Jul 2025 117,380.0023 Jul 2025 119,954.001−$220.99
long23 Jul 2025 119,954.0024 Jul 2025 118,756.001−$102.45
short24 Jul 2025 118,756.0012 Aug 2025 118,686.0019−$1.98
long12 Aug 2025 118,686.0018 Aug 2025 117,405.006−$108.86
short18 Aug 2025 117,405.007 Sep 2025 110,188.0020$563.53
long7 Sep 2025 110,188.0024 Sep 2025 111,999.0017$153.89
short24 Sep 2025 111,999.002 Oct 2025 118,595.008−$597.30
long2 Oct 2025 118,595.0011 Oct 2025 112,774.009−$468.93
short11 Oct 2025 112,774.0027 Oct 2025 114,559.0016−$148.63
long27 Oct 2025 114,559.004 Nov 2025 106,583.008−$618.61
short4 Nov 2025 106,583.0028 Nov 2025 91,333.9024$1,162.62
long28 Nov 2025 91,333.9018 Dec 2025 86,243.2020−$527.29
short18 Dec 2025 86,243.2021 Dec 2025 88,360.903−$223.30
long21 Dec 2025 88,360.9021 Jan 2026 88,427.7031−$0.39
short21 Jan 2026 88,427.7016 Feb 2026 68,832.6026$1,895.20
long16 Feb 2026 68,832.6023 Mar 2026 67,859.0035−$156.46
short23 Mar 2026 67,859.0026 Mar 2026 71,336.503−$537.27
long26 Mar 2026 71,336.5027 Mar 2026 68,820.301−$352.72
short27 Mar 2026 68,820.307 Apr 2026 68,853.7011−$12.11
long7 Apr 2026 68,853.7029 Apr 2026 76,342.8022$1,016.30
short29 Apr 2026 76,342.805 May 2026 79,861.006−$489.34
long5 May 2026 79,861.0013 May 2026 80,504.508$72.13
short13 May 2026 80,504.5014 Jun 2026 64,458.0032$1,989.18
long14 Jun 2026 64,458.0028 Jun 2026 60,029.0014−$834.04
short28 Jun 2026 60,029.0030 Jun 2026 60,260.202−$51.98
long30 Jun 2026 60,260.201 Jul 2026 58,624.701−$310.55
short1 Jul 2026 58,624.702 Jul 2026 60,024.001−$266.73
long2 Jul 2026 60,024.0028 Jul 2026 63,755.9026$646.72
short28 Jul 2026 63,755.908 Aug 2026 64,923.2011−$213.89
long8 Aug 2026 64,923.2012 Aug 2026 63,600.004−$232.36
short12 Aug 2026 63,600.0019 Aug 2026 64,725.407−$198.75
long19 Aug 2026 64,725.403 Sep 2026 77,340.0015$2,045.62
short3 Sep 2026 77,340.004 Sep 2026 81,270.401−$650.09
long4 Sep 2026 81,270.405 Sep 2026 79,660.801−$245.92
short5 Sep 2026 79,660.8022 Sep 2026 86,620.0017−$1,031.28
long22 Sep 2026 86,620.0030 Sep 2026 83,663.708−$372.30

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
MACD+ Strategy [SystemAlpha] this page—v4 strategy+2.9%7648.0%
EMA Slope AyE by fajardoarelysemav4 strategyNo trades on this market
ROoT by realisticDove62527emav5 strategy−4.7%2259.4%
sachin5986 by mohitesachin78emav4 strategy+32.1%3517.6%
sonu1997 by Sonu1997emav4 strategy+960.7%21,103.8%
Moving Average Crossover by Muh4mm4demav4 strategy+19,990.1%301,274.2%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 9 msYes 1,000 bars in 33 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/// © systemalphatrader//@version=4strategy(title="MACD Strategy", shorttitle="MACD Strategy [PUBLIC]", overlay=true, initial_capital=10000, currency='USD',    default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.04)// == /MAIN INPUT  ==///////////////////////////////////////*STRATEGY LOGIC                 *///////////////////////////////////////// == MACD ==fastLength = input(12, title="Fast Length")slowlength = input(26, title="Slow Length")MACDLength = input(9, title="MACD Length")MACD = ema(close, fastLength) - ema(close, slowlength)aMACD = ema(MACD, MACDLength)delta = MACD - aMACD// Calc breakoutsbuySignal        = crossover(delta, 0)shortSignal      = crossunder(delta,0)// == /MACD ==////////////////////////////* STRATEGY COMPONENT *////////////////////////////// === BACKTEST RANGE ===From_Year   = input(defval = 2017, title = "BACKTEST: From Year")From_Month  = input(defval = 1, title = "BACKTEST: From Month", minval = 1, maxval = 12)From_Day    = input(defval = 1, title = "BACKTEST: From Day", minval = 1, maxval = 31)To_Year     = input(defval = 9999, title = "BACKTEST: To Year")To_Month    = input(defval = 1, title = "BACKTEST: To Month", minval = 1, maxval = 12)To_Day      = input(defval = 1, title = "BACKTEST: To Day", minval = 1, maxval = 31)Start       = timestamp(From_Year, From_Month, From_Day, 00, 00)  // backtest start windowFinish      = timestamp(To_Year, To_Month, To_Day, 23, 59)        // backtest finish windowtestPeriod() =>    time >= Start and time <= Finish ? true : false// === /BACKTEST RANGE ===// === STRATEGY ===// Make input option to configure trade directiontradeDirection = input(title="Trade Direction", defval="Both", options=["Long", "Short", "Both"]) // Translate input into trading conditionslongOK  = (tradeDirection == "Long") or (tradeDirection == "Both")shortOK = (tradeDirection == "Short") or (tradeDirection == "Both")// == STRATEGY ENTRIES/EXITS ==longCondition = longOK and buySignal and testPeriod()shortcondition = shortOK and shortSignal and testPeriod()// === STRATEGY - LONG POSITION EXECUTION ===if longCondition    strategy.entry("Long", strategy.long)// === STRATEGY - SHORT POSITION EXECUTION ===if shortcondition    strategy.entry("Short", strategy.short)// === /STRATEGY ===//EOF