Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

MACD,RSI & EMA strategy with MA+PSAR by MAM

A Pine Script v4 strategy built on SAR (0.02, 0.02), EMA (close, 5) and RSI (close, 14). 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 is one contract and pays no commission. 16 settings; defaults include EMA1 length 5, EMA2 length 20 and MACD Fast 12.

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

BTCUSDT · 1D · default settings

  • SMA1
  • SMA2
  • SMA3
  • SMA4
  • 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 (16)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$63,447$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
−35.17%
−$35,170.90
Buy and hold
+102.5%
same period
Closed trades
40
15 won · 25 lost
Profitable
37.5%
of closed trades
Profit factor
0.77
gross profit ÷ gross loss
Max drawdown
65.96%
−$68,864.10

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

    3 settings have no label

    In the settings dialog PSAR_start (line 31), PSAR_increment (line 32), PSAR_maximum (line 33) show an empty name. The labels on this page come from the variable names.

  • 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 sma → ta.sma, sar → ta.sar, ema → ta.ema, rsi → ta.rsi.

v4 → v5

Verified

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

  • Line 3: //@version=4 → //@version=5
  • Line 19: sma → ta.sma
  • Line 21: sma → ta.sma
  • Line 23: sma → ta.sma
  • Line 25: sma → ta.sma
  • Line 34: sar → ta.sar
7 more edits
  • Line 36: ema → ta.ema
  • Line 37: ema → ta.ema
  • Line 43: ema → ta.ema
  • Line 43: ema → ta.ema
  • Line 44: ema → ta.ema
  • Line 45: rsi → ta.rsi
  • Line 46: ema → ta.ema
⋯// © maizirul959-//@version=4+//@version=5strategy("MACD,RSI & EMA strategy with MA+PSAR by MAM", overlay=true)⋯SMA1 = if _sma_len1 != 0-    sma(src, _sma_len1)+    ta.sma(src, _sma_len1)SMA2 = if _sma_len2 != 0-    sma(src, _sma_len2)+    ta.sma(src, _sma_len2)SMA3 = if _sma_len3 != 0-    sma(src, _sma_len3)+    ta.sma(src, _sma_len3)SMA4 = if _sma_len4 != 0-    sma(src, _sma_len4)+    ta.sma(src, _sma_len4)//__________________________________________________________________________⋯PSAR_maximum = input(0.2)-psar = sar(PSAR_start, PSAR_increment, PSAR_maximum)+psar = ta.sar(PSAR_start, PSAR_increment, PSAR_maximum)//_________________________________________________________________________-_ema1 = ema(close, _ema_len1)+_ema1 = ta.ema(close, _ema_len1)-_ema2 = ema(close, _ema_len2)+_ema2 = ta.ema(close, _ema_len2)//_________________________________________________________________________⋯//_________________________________________________________________________-_macd = ema(close, _macd_fast) - ema(close, _macd_slow)+_macd = ta.ema(close, _macd_fast) - ta.ema(close, _macd_slow)-_macd_signal = ema(_macd, _macd_signal_len)+_macd_signal = ta.ema(_macd, _macd_signal_len)-_rsi = rsi(close, _rsi_len)+_rsi = ta.rsi(close, _rsi_len)-_rsi_signal = ema(_rsi, _rsi_signal_len)+_rsi_signal = ta.ema(_rsi, _rsi_signal_len)//PLOT SMA⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 6: input() → input.int()
  • Line 7: input() → input.int()
  • Line 8: input() → input.int()
  • Line 9: input() → input.int()
  • Line 10: input() → input.int()
  • Line 12: input() → input.int()
10 more edits
  • Line 13: input() → input.int()
  • Line 14: input() → input.int()
  • Line 15: input() → input.int()
  • Line 16: input() → input.int()
  • Line 17: input() → input.source()
  • Line 27: input() → input.int()
  • Line 28: input() → input.int()
  • Line 31: input() → input.float()
  • Line 32: input() → input.float()
  • Line 33: input() → input.float()
⋯//Input Data-_ema_len1 = input(5, title="EMA1 length")+_ema_len1 = input.int(5, title="EMA1 length")-_ema_len2 = input(20, title="EMA2 length")+_ema_len2 = input.int(20, title="EMA2 length")-_macd_fast = input(12, title="MACD Fast")+_macd_fast = input.int(12, title="MACD Fast")-_macd_slow = input(26, title="MACD Slow")+_macd_slow = input.int(26, title="MACD Slow")-_macd_signal_len = input(20, title="MACD Signal length")+_macd_signal_len = input.int(20, title="MACD Signal length")//MAM add SMA-_sma_len1 = input(5, title="SMA1 Length")+_sma_len1 = input.int(5, title="SMA1 Length")-_sma_len2 = input(10, title="SMA2 Length")+_sma_len2 = input.int(10, title="SMA2 Length")-_sma_len3 = input(50, title="SMA3 Length")+_sma_len3 = input.int(50, title="SMA3 Length")-_sma_len4 = input(200, title="SMA4 Length")+_sma_len4 = input.int(200, title="SMA4 Length")-lineWidth = input(1, minval=1, title="Line width")+lineWidth = input.int(1, minval=1, title="Line width")-src = input(close, title="Source")+src = input.source(close, title="Source")SMA1 = if _sma_len1 != 0⋯//__________________________________________________________________________-_rsi_len = input(14, title="RSI length")+_rsi_len = input.int(14, title="RSI length")-_rsi_signal_len = input(20, title="RSI signal length")+_rsi_signal_len = input.int(20, title="RSI signal length")//_________________________________________________________________________//MAM Add PSAR-PSAR_start = input(0.02)+PSAR_start = input.float(0.02)-PSAR_increment = input(0.02)+PSAR_increment = input.float(0.02)-PSAR_maximum = input(0.2)+PSAR_maximum = input.float(0.2)psar = ta.sar(PSAR_start, PSAR_increment, PSAR_maximum)⋯

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: 40 before, 148 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.

⋯// © maizirul959-//@version=5+//@version=6strategy("MACD,RSI & EMA strategy with MA+PSAR by MAM", overlay=true)⋯

Settings

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

SettingDefaultType and rangeFeeds
EMA1 length5int_ema1
EMA2 length20int_ema2
MACD Fast12int_macd
MACD Slow26int_macd
MACD Signal length20int_macd_signal
SMA1 Length5intSMA1
SMA2 Length10intSMA2
SMA3 Length50intSMA3
SMA4 Length200intSMA4
Line width1int · min 1SMA1 SMA2 SMA3 SMA4
SourceclosesourceSMA1 SMA2 SMA3 SMA4
RSI length14int_rsi
RSI signal length20int_rsi_signal
PSAR start (no label in the script)0.02floatpsar
PSAR increment (no label in the script)0.02floatpsar
PSAR maximum (no label in the script)0.2floatpsar

What it calculates

  • SAR (sar, ta.sar in v5)PSAR start (0.02), PSAR increment (0.02), PSAR maximum (0.2)psar · line 34
  • EMA (ema, ta.ema in v5)close, EMA1 length (5)_ema1 · line 36
  • EMA (ema, ta.ema in v5)close, EMA2 length (20)_ema2 · line 37
  • EMA (ema, ta.ema in v5)close, MACD Fast (12)_macd · line 43
  • EMA (ema, ta.ema in v5)_macd, MACD Signal length (20)_macd_signal · line 44
  • RSI (rsi, ta.rsi in v5)close, RSI length (14)_rsi · line 45
  • EMA (ema, ta.ema in v5)_rsi, RSI signal length (20)_rsi_signal · line 46

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.

high · low · closehigh · low · closeprice dataPSAR_startPSAR startsetting · 0.02PSAR_incrementPSAR incrementsetting · 0.02PSAR_maximumPSAR maximumsetting · 0.2closecloseprice data_ema_len1EMA1 lengthsetting · 5_ema_len2EMA2 lengthsetting · 20_macd_fastMACD Fastsetting · 12_macd_slowMACD Slowsetting · 26_macd_signal_lenMACD Signal lengthsetting · 20_rsi_lenRSI lengthsetting · 14_rsi_signal_lenRSI signal lengthsetting · 20_sma_len1SMA1 Lengthsetting · 5_sma_len2SMA2 Lengthsetting · 10_sma_len3SMA3 Lengthsetting · 50_sma_len4SMA4 Lengthsetting · 200psarSAR→ psar_ema1EMA→ _ema1_ema2EMA→ _ema2_macdEMA→ _macd_macd_signalEMA→ _macd_signal_rsiRSI→ _rsi_rsi_signalEMA→ _rsi_signallongConditionlongConditionconditionshortConditionshortConditionconditionSMA1SMA1conditionSMA2SMA2conditionSMA3SMA3conditionSMA4SMA4conditionpcColourpcentry:BuyOpen Buystrategy.entryentry:SellOpen Sellstrategy.entryplot:48SMA1plotplot:49SMA2plotplot:50SMA3plotplot:51SMA4plotplot:55plotplot

Order rules

OrderFires whenBy defaultLine
Open Buy long(longCondition)On62
Open Sell short(shortCondition)On65

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.

11/11trades 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−35.2%+102.5%4038%0.7766.0%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+8.7%+5.5%4730%1.2313.7%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+0.0%+9.8%3834%1.003.1%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+0.3%+8.4%4335%1.210.7%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.1%+16.7%4045%1.330.1%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.0%+21.5%4333%1.080.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+0.1%+148.3%4033%1.140.5%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+0.1%+17.1%4943%1.550.1%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 (EMA1 length 3, EMA2 length 24) made +13.8% before 26 Dec 2025 and +4.5% after it, worse than the defaults' +8.0% after. Tuning on the past did not carry forward. 25% of the 48 combinations made money in-sample and 90% out-of-sample.

Before 26 Dec 2025 · in-sample
EMA2 length ↓ · EMA1 length →345679
10−28%−28%−28%−28%−28%−28%
12−32%−32%−32%−32%−32%−32%
14−37%−37%−37%−37%−37%−37%
17−37%−37%−37%−37%−37%−37%
20−43%−43%−43%−43%−43%−43%
24+14%+14%+14%+14%+14%+14%
28+4%+4%+4%+4%+4%+4%
34−10%−10%−10%−10%−10%−10%
From 26 Dec 2025 · out-of-sample
EMA2 length ↓ · EMA1 length →345679
10+8%+8%+8%+8%+8%+10%
12+8%+8%+8%+8%+8%+10%
14+8%+8%+8%+8%+8%+6%
17+8%+8%+8%+8%+8%+6%
20+8%+8%+8%+8%+8%+6%
24+4%+5%+5%+5%+5%+0%
28+4%+5%+5%+5%+5%+0%
34−4%−4%−4%−4%−4%+10%

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 market1040%−$29,060.70
Sideways market2045%$6,867.09
Falling market1020%−$12,977.30

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

How bad could the drawdown be?

77.1%

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

0%89%
All 40 trades
SideEntryExitBarsP&L
short20 Mar 2024 61,937.4016 May 2024 66,206.5057−$4,269.10
long16 May 2024 66,206.5012 Jun 2024 67,314.2027$1,107.72
short12 Jun 2024 67,314.2015 Jul 2024 60,797.9033$6,516.32
long15 Jul 2024 60,797.903 Aug 2024 61,498.3019$700.43
short3 Aug 2024 61,498.3022 Aug 2024 61,156.0019$342.31
long22 Aug 2024 61,156.002 Sep 2024 57,301.8011−$3,854.26
short2 Sep 2024 57,301.8014 Sep 2024 60,498.0012−$3,196.22
long14 Sep 2024 60,498.004 Oct 2024 60,752.7020$254.73
short4 Oct 2024 60,752.7015 Oct 2024 66,084.0011−$5,331.28
long15 Oct 2024 66,084.005 Nov 2024 67,850.0021$1,766.01
short5 Nov 2024 67,850.0017 Jan 2025 99,987.3073−$32,137.30
long17 Jan 2025 99,987.302 Feb 2025 100,636.0016$648.36
short2 Feb 2025 100,636.0025 Mar 2025 87,498.2051$13,137.50
long25 Mar 2025 87,498.208 Apr 2025 79,163.2014−$8,334.92
short8 Apr 2025 79,163.2012 Apr 2025 83,423.804−$4,260.59
long12 Apr 2025 83,423.8031 May 2025 103,985.0049$20,561.60
short31 May 2025 103,985.0030 Jun 2025 108,357.0030−$4,371.46
long30 Jun 2025 108,357.002 Jul 2025 105,681.002−$2,675.80
short2 Jul 2025 105,681.003 Jul 2025 108,850.001−$3,168.46
long3 Jul 2025 108,850.001 Aug 2025 115,764.0029$6,914.48
short1 Aug 2025 115,764.0014 Aug 2025 123,306.0013−$7,542.37
long14 Aug 2025 123,306.0016 Aug 2025 117,342.002−$5,964.40
short16 Aug 2025 117,342.0011 Sep 2025 113,960.0026$3,382.04
long11 Sep 2025 113,960.0026 Sep 2025 108,994.0015−$4,965.51
short26 Sep 2025 108,994.002 Oct 2025 118,595.006−$9,600.50
long2 Oct 2025 118,595.0012 Oct 2025 110,644.0010−$7,950.59
short12 Oct 2025 110,644.0028 Oct 2025 114,108.0016−$3,463.25
long28 Oct 2025 114,108.0031 Oct 2025 108,323.003−$5,784.78
short31 Oct 2025 108,323.003 Jan 2026 89,995.1064$18,327.70
long3 Jan 2026 89,995.1022 Jan 2026 89,454.7019−$540.41
short22 Jan 2026 89,454.705 Mar 2026 72,666.8042$16,788.00
long5 Mar 2026 72,666.8029 Mar 2026 66,377.0024−$6,289.73
short29 Mar 2026 66,377.007 Apr 2026 68,853.709−$2,476.62
long7 Apr 2026 68,853.7016 May 2026 79,113.2039$10,259.50
short16 May 2026 79,113.206 Jul 2026 63,650.0051$15,463.20
long6 Jul 2026 63,650.002 Aug 2026 62,823.7027−$826.36
short2 Aug 2026 62,823.707 Aug 2026 64,323.605−$1,499.96
long7 Aug 2026 64,323.6013 Aug 2026 63,480.006−$843.62
short13 Aug 2026 63,480.0024 Sep 2026 84,397.6042−$20,917.60
long24 Sep 2026 84,397.608 Oct 2026 83,321.8014−$1,075.79

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,RSI & EMA strategy with MA+PSAR by MAM this page—v4 strategy−35.2%4066.0%
PSAR + EMA-TEMA-RSI-OBV by UnknownUnicorn19826629ema sar rsiv4 strategyNo trades on this market
RSI Cross [xaurr] by livetrendrsi emav4 strategy+24.4%5335.3%
Bitpanda Coinrule Template by joshuajcoop01rsi emav5 strategy−2.8%44.6%
RSI with Slow and Fast MA Crossing Strategy (by Coinrule) by Coinrulersi emav5 strategy−2.8%44.6%
RSI of VWAP by mohaneersi emav4 strategyNo trades on this market

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 13 msYes 1,000 bars in 53 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/// © maizirul959//@version=4strategy("MACD,RSI & EMA strategy with MA+PSAR by MAM", overlay=true)//Input Data_ema_len1 = input(5, title="EMA1 length")_ema_len2 = input(20, title="EMA2 length")_macd_fast = input(12, title="MACD Fast")_macd_slow = input(26, title="MACD Slow")_macd_signal_len = input(20, title="MACD Signal length")//MAM add SMA_sma_len1 = input(5, title="SMA1 Length")_sma_len2 = input(10, title="SMA2 Length")_sma_len3 = input(50, title="SMA3 Length")_sma_len4 = input(200, title="SMA4 Length")lineWidth = input(1, minval=1, title="Line width")src = input(close, title="Source")SMA1 = if _sma_len1 != 0    sma(src, _sma_len1)SMA2 = if _sma_len2 != 0    sma(src, _sma_len2)SMA3 = if _sma_len3 != 0    sma(src, _sma_len3)SMA4 = if _sma_len4 != 0    sma(src, _sma_len4)//___________________________________________________________________________rsi_len = input(14, title="RSI length")_rsi_signal_len = input(20, title="RSI signal length")//_________________________________________________________________________//MAM Add PSARPSAR_start = input(0.02)PSAR_increment = input(0.02)PSAR_maximum = input(0.2)psar = sar(PSAR_start, PSAR_increment, PSAR_maximum)//__________________________________________________________________________ema1 = ema(close, _ema_len1)_ema2 = ema(close, _ema_len2)//_________________________________________________________________________//MAM add SMA//_sma1 = sma(close, _sma_len1)//_sma2 = sma(close, _sma_len2)//__________________________________________________________________________macd = ema(close, _macd_fast) - ema(close, _macd_slow)_macd_signal = ema(_macd, _macd_signal_len)_rsi = rsi(close, _rsi_len)_rsi_signal = ema(_rsi, _rsi_signal_len)//PLOT SMAplot(SMA1, color=#B71C1C, title="SMA1", linewidth=lineWidth)plot(SMA2, color=#FFFF00, title="SMA2", linewidth=lineWidth)plot(SMA3, color=#5b34ff, title="SMA3", linewidth=lineWidth)plot(SMA4, color=#d7d7d7, title="SMA4", linewidth=lineWidth)//PLOT PSAR//plot(psar, "ParabolicSAR", style=plot.style_cross, color=#3A6CA8)pc = close < psar ? color.red : color.greenplot(psar, style=plot.style_cross, color=pc)//plot(_rsi, color=color.yellow)//plot(_rsi_signal, color=color.green)//plot(_macd, color=color.blue)//plot(_macd_signal, color=color.red)longCondition = close > _ema1 and close > _ema2 and _macd > _macd_signal and _rsi > _rsi_signal and _rsi > 50 and _rsi < 70if (longCondition)    strategy.entry("Buy",strategy.long)shortCondition = close < _ema1 and close <_ema2 and _macd < _macd_signal and _rsi < _rsi_signal if (shortCondition)    strategy.entry("Sell",strategy.short)    //bcol = longCondition ? color.green : shortCondition ? color.orange : na//bgcolor(bcol)