Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

MACD Long Strat

A Pine Script v4 strategy built on EMA (close, fast) and SMA (macd, 9). It has 2 order rules, 1 entry among them, and trades long only with the default settings. Exits wait for a signal; there is no stop loss. Each trade is one contract and pays no commission. It has no settings.

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

BTCUSDT · 1D · default settings

  • 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 (0)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOctPlot$124,888$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
+23.95%
$23,954.80
Buy and hold
+102.5%
same period
Closed trades
79
39 won · 40 lost
Profitable
49.4%
of closed trades
Profit factor
1.24
gross profit ÷ gross loss
Max drawdown
20.12%
−$24,807.30

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

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, sma → ta.sma.

v4 → v5

VerifiedDownload the v5 script

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

  • Line 3: //@version=4 → //@version=5
  • Line 7: ema → ta.ema
  • Line 8: ema → ta.ema
  • Line 10: sma → ta.sma
⋯// © TheGrindToday-//@version=4+//@version=5strategy("MACD Long Strat", overlay=false)⋯fast = 6, slow = 26-fastMA = ema(close, fast)+fastMA = ta.ema(close, fast)-slowMA = ema(close, slow)+slowMA = ta.ema(close, slow)macd = fastMA - slowMA-signal = sma(macd, 9)+signal = ta.sma(macd, 9)histogram = macd-signal⋯

Clean v5

Verified

Nothing to change.

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: 79 before, 74 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.

⋯// © TheGrindToday-//@version=5+//@version=6strategy("MACD Long Strat", overlay=false)⋯

Settings

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

The script declares no settings.

What it calculates

  • EMA (ema, ta.ema in v5)close, fastfastMA · line 7
  • EMA (ema, ta.ema in v5)close, slowslowMA · line 8
  • SMA (sma, ta.sma in v5)macd, 9signal · line 10

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 datafastMAEMA→ fastMAslowMAEMA→ slowMAsignalSMA→ signalmacdmacdvaluehistogramhistogramvaluehistogram_reversing_negativehistogram_reversing_neg…conditionLongEntryConditionLongEntryConditionconditionexitConditionLongexitConditionLongconditionmacdpos, macdneg, ShortEntryConditionmacdpos · macdneg +13 conditionsentry:LongOpen Longstrategy.entryclose:LongClose Longstrategy.closeplot:23plotplot

Order rules

OrderFires whenBy defaultLine
Open Long long(LongEntryCondition and histogram_reversing_negative)On19
Close Long(exitConditionLong)On21

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.

23/23trades 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+24.0%+102.5%7949%1.2420.1%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+11.2%+5.5%8049%1.369.9%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−0.6%+9.8%7841%0.912.1%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+0.4%+8.4%8345%1.280.4%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−0.0%+16.7%8341%0.880.1%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.0%+21.5%7942%1.200.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+0.4%+148.3%8347%1.390.4%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+0.1%+17.1%8142%1.270.1%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 market2654%$12,907.80
Sideways market3352%$26,991.00
Falling market2040%−$15,944.00

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

How bad could the drawdown be?

31.6%

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

0%36%
All 79 trades
SideEntryExitBarsP&L
long2 Mar 2024 62,387.904 Mar 2024 63,114.002$726.07
long22 Mar 2024 65,501.3031 Mar 2024 69,582.209$4,080.89
long6 Apr 2024 67,820.6013 Apr 2024 67,116.507−$704.11
long20 Apr 2024 63,818.0026 Apr 2024 64,498.306$680.32
long5 May 2024 63,892.009 May 2024 61,193.004−$2,699.00
long17 May 2024 65,235.2020 May 2024 66,274.003$1,038.79
long3 Jun 2024 67,765.608 Jun 2024 69,355.605$1,589.98
long17 Jun 2024 66,676.9025 Jun 2024 60,293.308−$6,383.56
long27 Jun 2024 60,865.004 Jul 2024 60,208.607−$656.41
long10 Jul 2024 58,050.0019 Jul 2024 63,987.909$5,937.92
long8 Aug 2024 55,133.8016 Aug 2024 57,541.108$2,407.29
long21 Aug 2024 59,013.8027 Aug 2024 62,834.006$3,820.20
long4 Sep 2024 57,487.707 Sep 2024 53,963.003−$3,524.77
long10 Sep 2024 57,042.0017 Sep 2024 58,214.007$1,171.98
long20 Sep 2024 62,948.0022 Sep 2024 63,349.002$400.97
long28 Sep 2024 65,769.9029 Sep 2024 65,858.001$88.05
long6 Oct 2024 62,058.0011 Oct 2024 60,326.405−$1,731.61
long13 Oct 2024 63,206.2019 Oct 2024 68,428.006$5,221.76
long29 Oct 2024 69,962.202 Nov 2024 69,496.004−$466.21
long8 Nov 2024 75,857.9015 Nov 2024 87,325.607$11,467.70
long23 Nov 2024 98,892.0024 Nov 2024 97,672.401−$1,219.60
long1 Dec 2024 96,408.0010 Dec 2024 97,276.509$868.49
long13 Dec 2024 100,004.0019 Dec 2024 100,204.006$199.72
long26 Dec 2024 99,429.6031 Dec 2024 92,792.105−$6,637.56
long2 Jan 2025 94,591.809 Jan 2025 95,060.607$468.83
long15 Jan 2025 96,560.9020 Jan 2025 101,332.005$4,770.72
long31 Jan 2025 104,723.002 Feb 2025 100,636.002−$4,087.28
long9 Feb 2025 96,444.8017 Feb 2025 96,118.108−$326.63
long21 Feb 2025 98,305.0023 Feb 2025 96,551.002−$1,754.00
long3 Mar 2025 94,270.009 Mar 2025 86,222.506−$8,047.53
long13 Mar 2025 83,680.1022 Mar 2025 84,088.809$408.67
long25 Mar 2025 87,498.2027 Mar 2025 86,909.202−$588.99
long5 Apr 2025 83,889.907 Apr 2025 78,430.002−$5,459.87
long11 Apr 2025 79,607.3017 Apr 2025 84,030.406$4,423.08
long23 Apr 2025 93,443.0027 Apr 2025 94,628.004$1,185.01
long8 May 2025 97,030.5013 May 2025 102,791.005$5,760.82
long20 May 2025 105,574.0025 May 2025 107,762.005$2,188.17
long3 Jun 2025 105,858.006 Jun 2025 101,509.003−$4,349.31
long8 Jun 2025 105,552.0013 Jun 2025 105,672.005$119.59
long25 Jun 2025 106,083.001 Jul 2025 107,147.006$1,063.51
long4 Jul 2025 109,585.005 Jul 2025 107,984.001−$1,600.52
long11 Jul 2025 116,010.0016 Jul 2025 117,758.005$1,748.07
long24 Jul 2025 118,756.0025 Jul 2025 118,341.001−$415.02
long28 Jul 2025 119,416.0030 Jul 2025 117,951.002−$1,464.81
long5 Aug 2025 115,055.0015 Aug 2025 118,295.0010$3,240.06
long24 Aug 2025 115,438.0026 Aug 2025 110,112.002−$5,326.08
long28 Aug 2025 111,262.0030 Aug 2025 108,377.002−$2,884.61
long2 Sep 2025 109,237.0015 Sep 2025 115,268.0013$6,030.58
long29 Sep 2025 112,164.007 Oct 2025 124,659.008$12,494.60
long15 Oct 2025 113,028.0017 Oct 2025 108,194.002−$4,833.86
long20 Oct 2025 108,643.0029 Oct 2025 112,898.009$4,255.67
long9 Nov 2025 102,313.0014 Nov 2025 99,692.005−$2,620.92
long20 Nov 2025 91,555.0021 Nov 2025 86,637.201−$4,917.74
long24 Nov 2025 86,830.001 Dec 2025 90,360.007$3,530.01
long4 Dec 2025 93,429.906 Dec 2025 89,330.002−$4,099.91
long21 Dec 2025 88,360.9025 Dec 2025 87,669.404−$691.47
long3 Jan 2026 89,995.108 Jan 2026 91,364.205$1,369.02
long15 Jan 2026 96,951.8018 Jan 2026 95,147.803−$1,804.01
long25 Jan 2026 89,225.3030 Jan 2026 84,650.205−$4,575.18
long8 Feb 2026 69,289.4018 Feb 2026 67,503.5010−$1,785.85
long27 Feb 2026 67,485.201 Mar 2026 66,973.302−$511.93
long4 Mar 2026 68,338.007 Mar 2026 68,114.003−$223.99
long12 Mar 2026 70,191.9019 Mar 2026 71,246.607$1,054.69
long25 Mar 2026 70,556.7028 Mar 2026 66,407.303−$4,149.46
long1 Apr 2026 68,284.5013 Apr 2026 70,741.6012$2,457.07
long24 Apr 2026 78,257.5025 Apr 2026 77,437.101−$820.35
long3 May 2026 78,686.809 May 2026 80,193.206$1,506.34
long21 May 2026 77,552.2028 May 2026 74,449.307−$3,102.93
long1 Jun 2026 73,674.402 Jun 2026 71,408.901−$2,265.49
long8 Jun 2026 63,332.0018 Jun 2026 64,509.4010$1,177.39
long29 Jun 2026 59,577.008 Jul 2026 63,364.009$3,786.99
long16 Jul 2026 64,756.3017 Jul 2026 63,830.201−$926.08
long22 Jul 2026 66,556.1024 Jul 2026 65,099.002−$1,457.17
long4 Aug 2026 63,520.0011 Aug 2026 63,970.007$450.01
long19 Aug 2026 64,725.4025 Aug 2026 78,992.806$14,267.30
long5 Sep 2026 79,660.808 Sep 2026 79,112.003−$548.77
long14 Sep 2026 76,842.0017 Sep 2026 76,206.003−$636.01
long18 Sep 2026 76,417.0025 Sep 2026 84,410.207$7,993.23
long3 Oct 2026 84,518.008 Oct 2026 83,321.805−$1,196.19

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 Long Strat this page—v4 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%
Simple Momentum Strategy Based on SMA, EMA and Volume by slip_streamsma emav4 strategy+7.4%1827.4%
BTC WaveTrend R-R=1-1.5 by TrendCrypto2022ema smav5 strategy+0.2%282.7%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 6 msYes 1,000 bars in 19 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/// © TheGrindToday//@version=4strategy("MACD Long Strat", overlay=false)//fast = 12, slow = 26fast = 6, slow = 26fastMA = ema(close, fast)slowMA = ema(close, slow)macd = fastMA - slowMAsignal = sma(macd, 9)histogram = macd-signalmacdpos = histogram[0] > 0macdneg = histogram[0] < 0histogram_reversing_negative = histogram[1] > histogram[2]LongEntryCondition =  histogram > histogram[1] ShortEntryCondition =  histogram < histogram[1]exitConditionLong = histogram[0] < histogram[2]if (LongEntryCondition and histogram_reversing_negative)    strategy.entry("Long", strategy.long)if (exitConditionLong)    strategy.close("Long")    plot(histogram)