Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Strategy Tester EMA-SMA-RSI-MACD

A Pine Script v4 strategy built on RSI (close, 20) and SMA or EMA (close, 12). It has 6 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade commits 100% of equity and pays no commission. 59 settings; defaults include Source close, Type Strategy _L_ and Pick your poison: co.

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 Strategy Tester EMA-SMA-RSI-MACD repaint?
Yes
At least one pattern in the source can repaint: higher-timeframe data.
How did Strategy Tester EMA-SMA-RSI-MACD do on BTCUSDT 1D with default settings?
+5.70%
From 26 Jan 2024 to 21 Oct 2026, over 12 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can Strategy Tester EMA-SMA-RSI-MACD 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 Strategy Tester EMA-SMA-RSI-MACD use a stop loss?
Yes
strategy.exit sets a stop on line 226, 228.
Does Strategy Tester EMA-SMA-RSI-MACD run in Zeal Terminal?
Yes
It compiles in 43 ms and runs 1,000 bars in 235 ms, in the browser.

BTCUSDT · 1D · default settings

  • xMA 1
  • xMA 2
  • xMA 3
  • xMA 4
  • Long
  • SL/TP Long
  • Close Long
  • 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 (59)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$112$203Equity from $100
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
+5.70%
$5.70
Buy and hold
+102.5%
same period
Closed trades
12
6 won · 6 lost
Profitable
50.0%
of closed trades
Profit factor
1.09
gross profit ÷ gross loss
Max drawdown
28.43%
−$39.21

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

    14 settings do nothing

    “>=< >=< [STRATEGIES] >=< >=<”, “>=< >=< [BUY/LONG] >=< >=<”, “>=< [xMA settings (Buy/Long)] >=<”, “>=< >=< [SELL/SHORT] >=< >=<”, “ if RSI >”, “ if RSI <”, “ if RSI (HTF) >”, “ if RSI (HTF) <”, “>=< [xMA settings (Sell/Short)] >=<”, “>=< >=< [RSI] >=< >=< >=<”, “>=< >=< [MACD] >=< >=< >=<”, “>=< >=< [HTF settings] >=< >=<”, “>=< >=< [SL/TP] >=< >=< >=<”, “>=< >=< [TIME] >=< >=< >=<” are declared but never read.

  • Check

    No commission

    The backtest assumes free trading. Results on any real exchange will be lower.

  • 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 sma → ta.sma, ema → ta.ema, wma → ta.wma, vwma → ta.vwma, rma → ta.rma, round → math.round, sqrt → math.sqrt, security → request.security, rsi → ta.rsi.

v4 → v5

Verified

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

  • Line 3: //@version=4 → //@version=5
  • Line 37: input(type = input.source) → input.source()
  • Line 92: input(type = input.resolution) → input.timeframe()
  • Line 93: input(type = input.resolution) → input.timeframe()
  • Line 94: input(type = input.resolution) → input.timeframe()
  • Line 117: type is reserved in v5: renamed type_
31 more edits
  • Line 118: sma → ta.sma
  • Line 119: ema → ta.ema
  • Line 120: wma → ta.wma
  • Line 121: vwma → ta.vwma
  • Line 122: rma → ta.rma
  • Line 123: wma → ta.wma
  • Line 123: wma → ta.wma
  • Line 123: wma → ta.wma
  • Line 123: round → math.round
  • Line 123: sqrt → math.sqrt
  • Line 124: ema → ta.ema
  • Line 124: ema → ta.ema
  • Line 124: ema → ta.ema
  • Line 124: ema → ta.ema
  • Line 124: ema → ta.ema
  • Line 124: ema → ta.ema
  • Line 133: security → request.security
  • Line 134: security → request.security
  • Line 135: security → request.security
  • Line 136: security → request.security
  • Line 137: security → request.security
  • Line 151: rsi → ta.rsi
  • Line 152: security → request.security
  • Line 155: sma → ta.sma
  • Line 155: ema → ta.ema
  • Line 156: sma → ta.sma
  • Line 156: ema → ta.ema
  • Line 158: sma → ta.sma
  • Line 158: ema → ta.ema
  • Line 160: security → request.security
  • Line 161: security → request.security
⋯// © fikira-//@version=4+//@version=5strategy("Strategy Tester EMA-SMA-RSI-MACD", shorttitle="Strat-test", overlay=true, max_bars_back=5000, ⋯//s       = input(cl,   "Source" , options=[cl, op, hi, lo, c4, c3, hl])-src       = input(title="Source", type=input.source, defval=close)+src       = input.source(title="Source", defval=close)//src     =⋯__5_    = input(false, ">=< >=< [HTF settings] >=< >=<")-MA_HTF  = input("D", "  xMA HTF"  , type = input.resolution)+MA_HTF  = input.timeframe("D", "  xMA HTF"  )-RSI_HTF = input("D", "  RSI HTF"  , type = input.resolution)+RSI_HTF = input.timeframe("D", "  RSI HTF"  )-MACD_HTF= input("D", "  MACD HTF" , type = input.resolution)+MACD_HTF= input.timeframe("D", "  MACD HTF" )__6_    = input(false, ">=< >=< [SL/TP] >=< >=< >=<")⋯////////////////////////////////////////////////////////////////////////////////////////////-f_xma(type, len) => +f_xma(type_, len) => -  type == "SMA"    ?  sma(src,len) : +  type_ == "SMA"    ?  ta.sma(src,len) : -  type == "EMA"    ?  ema(src,len) : +  type_ == "EMA"    ?  ta.ema(src,len) : -  type == "WMA"    ?  wma(src,len) : +  type_ == "WMA"    ?  ta.wma(src,len) : -  type == "VWMA"   ? vwma(src,len) : +  type_ == "VWMA"   ? ta.vwma(src,len) : -  type == "RMA"    ?  rma(src,len) :  +  type_ == "RMA"    ?  ta.rma(src,len) :  -  type == "HullMA" ?  wma(2*wma(src, len/2)-wma(src, len), round(sqrt(len))) : +  type_ == "HullMA" ?  ta.wma(2*ta.wma(src, len/2)-ta.wma(src, len), math.round(math.sqrt(len))) : -  3 * (ema(src, len) - ema(ema(src, len), len)) + ema(ema(ema(src, len), len), len)+  3 * (ta.ema(src, len) - ta.ema(ta.ema(src, len), len)) + ta.ema(ta.ema(ta.ema(src, len), len), len)_1     = f_xma(ma1   , len1   )⋯_4b    = f_xma(ma4HTF, len4HTF)-_1_HTF = security(syminfo.tickerid, MA_HTF,  _1b  , lookahead = barmerge.lookahead_on)+_1_HTF = request.security(syminfo.tickerid, MA_HTF,  _1b  , lookahead = barmerge.lookahead_on)-_2_HTF = security(syminfo.tickerid, MA_HTF,  _2b  , lookahead = barmerge.lookahead_on)+_2_HTF = request.security(syminfo.tickerid, MA_HTF,  _2b  , lookahead = barmerge.lookahead_on)-_3_HTF = security(syminfo.tickerid, MA_HTF,  _3b  , lookahead = barmerge.lookahead_on)+_3_HTF = request.security(syminfo.tickerid, MA_HTF,  _3b  , lookahead = barmerge.lookahead_on)-_4_HTF = security(syminfo.tickerid, MA_HTF,  _4b  , lookahead = barmerge.lookahead_on)+_4_HTF = request.security(syminfo.tickerid, MA_HTF,  _4b  , lookahead = barmerge.lookahead_on)-cl_HTF = security(syminfo.tickerid, MA_HTF,  close, lookahead = barmerge.lookahead_on)+cl_HTF = request.security(syminfo.tickerid, MA_HTF,  close, lookahead = barmerge.lookahead_on)////////////////////////////////////////////////////////////////////////////////////////////⋯// RSI-rsi_       = rsi(src, ler)+rsi_       = ta.rsi(src, ler)-rsi_HTF    = security(syminfo.tickerid, RSI_HTF , rsi_  , lookahead = barmerge.lookahead_on)+rsi_HTF    = request.security(syminfo.tickerid, RSI_HTF , rsi_  , lookahead = barmerge.lookahead_on)////////////////////////////////////////////////////////////////////////////////////////////// MACD-fast_ma    = sma_source ? sma(src, fst)  : ema(src , fst)+fast_ma    = sma_source ? ta.sma(src, fst)  : ta.ema(src , fst)-slow_ma    = sma_source ? sma(src, slw)  : ema(src , slw)+slow_ma    = sma_source ? ta.sma(src, slw)  : ta.ema(src , slw)macd       = fast_ma - slow_ma-signal     = sma_signal ? sma(macd, sgn) : ema(macd, sgn)+signal     = sma_signal ? ta.sma(macd, sgn) : ta.ema(macd, sgn)hist       = macd - signal-macd_HTF   = security(syminfo.tickerid, MACD_HTF, macd  , lookahead = barmerge.lookahead_on)+macd_HTF   = request.security(syminfo.tickerid, MACD_HTF, macd  , lookahead = barmerge.lookahead_on)-signal_HTF = security(syminfo.tickerid, MACD_HTF, signal, lookahead = barmerge.lookahead_on)+signal_HTF = request.security(syminfo.tickerid, MACD_HTF, signal, lookahead = barmerge.lookahead_on)////////////////////////////////////////////////////////////////////////////////////////////⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 47: input() → input.bool()
  • Line 49: input() → input.bool()
  • Line 51: input() → input.int()
  • Line 52: input() → input.int()
  • Line 53: input() → input.int()
  • Line 54: input() → input.int()
42 more edits
  • Line 57: input() → input.bool()
  • Line 58: input() → input.string()
  • Line 59: input() → input.int()
  • Line 60: input() → input.string()
  • Line 61: input() → input.int()
  • Line 62: input() → input.string()
  • Line 63: input() → input.int()
  • Line 64: input() → input.string()
  • Line 65: input() → input.int()
  • Line 66: input() → input.bool()
  • Line 68: input() → input.int()
  • Line 69: input() → input.int()
  • Line 70: input() → input.int()
  • Line 71: input() → input.int()
  • Line 74: input() → input.bool()
  • Line 75: input() → input.string()
  • Line 76: input() → input.int()
  • Line 77: input() → input.string()
  • Line 78: input() → input.int()
  • Line 79: input() → input.string()
  • Line 80: input() → input.int()
  • Line 81: input() → input.string()
  • Line 82: input() → input.int()
  • Line 83: input() → input.bool()
  • Line 84: input() → input.int()
  • Line 85: input() → input.bool()
  • Line 86: input() → input.int()
  • Line 87: input() → input.int()
  • Line 88: input() → input.int()
  • Line 89: input() → input.bool()
  • Line 90: input() → input.bool()
  • Line 91: input() → input.bool()
  • Line 95: input() → input.bool()
  • Line 96: input() → input.float()
  • Line 97: input() → input.float()
  • Line 105: input() → input.bool()
  • Line 106: input() → input.int()
  • Line 107: input() → input.int()
  • Line 108: input() → input.int()
  • Line 109: input() → input.int()
  • Line 110: input() → input.int()
  • Line 111: input() → input.int()
⋯// source-__1_    = input(false, ">=< >=< [STRATEGIES] >=< >=<")+__1_    = input.bool(false, ">=< >=< [STRATEGIES] >=< >=<")Type    = input(_L_,  "Type Strategy", options=[L_S, _L_, _S_])-_1a_    = input(false, ">=< >=< [BUY/LONG] >=< >=<")+_1a_    = input.bool(false, ">=< >=< [BUY/LONG] >=< >=<")ENT     = input(co,   "Pick your poison:", options=[co, cla, rsi, mch, mch0, sgh0])-EH      = input(0,    " if RSI >")+EH      = input.int(0,    " if RSI >")-EL      = input(100,  " if RSI <")+EL      = input.int(100,  " if RSI <")-EH_HTF  = input(0,    " if RSI (HTF) >")+EH_HTF  = input.int(0,    " if RSI (HTF) >")-EL_HTF  = input(100,  " if RSI (HTF) <")+EL_HTF  = input.int(100,  " if RSI (HTF) <")EX      = input(none, " Extra argument", options=[none, mch, mch0, sgh0, hisbl])EX2     = input(none, " Second argument", options=[none, mch_HTF, mch0HTF, sgh0HTF, co_HTF, cla_HTF])-_1b_    = input(false, ">=< [xMA settings (Buy/Long)] >=<")+_1b_    = input.bool(false, ">=< [xMA settings (Buy/Long)] >=<")-ma1     = input(defval="SMA", title="  xMA 1"       , options=["SMA", "EMA", "WMA", "HullMA", "VWMA", "RMA", "TEMA"])+ma1     = input.string(defval="SMA", title="  xMA 1"       , options=["SMA", "EMA", "WMA", "HullMA", "VWMA", "RMA", "TEMA"])-len1    = input(50,   "     Length"  )+len1    = input.int(50,   "     Length"  )-ma2     = input(defval="SMA", title="  xMA 2"       , options=["SMA", "EMA", "WMA", "HullMA", "VWMA", "RMA", "TEMA"])+ma2     = input.string(defval="SMA", title="  xMA 2"       , options=["SMA", "EMA", "WMA", "HullMA", "VWMA", "RMA", "TEMA"])-len2    = input(100,  "     Length"  )+len2    = input.int(100,  "     Length"  )-ma1HTF  = input(defval="SMA", title="  xMA 1 - HTF" , options=["SMA", "EMA", "WMA", "HullMA", "VWMA", "RMA", "TEMA"])+ma1HTF  = input.string(defval="SMA", title="  xMA 1 - HTF" , options=["SMA", "EMA", "WMA", "HullMA", "VWMA", "RMA", "TEMA"])-len1HTF = input(50,   "     Length"  )+len1HTF = input.int(50,   "     Length"  )-ma2HTF  = input(defval="SMA", title="  xMA 2 - HTF" , options=["SMA", "EMA", "WMA", "HullMA", "VWMA", "RMA", "TEMA"])+ma2HTF  = input.string(defval="SMA", title="  xMA 2 - HTF" , options=["SMA", "EMA", "WMA", "HullMA", "VWMA", "RMA", "TEMA"])-len2HTF = input(100,  "     Length"  )+len2HTF = input.int(100,  "     Length"  )-_2a_    = input(false, ">=< >=< [SELL/SHORT] >=< >=<")+_2a_    = input.bool(false, ">=< >=< [SELL/SHORT] >=< >=<")CLO     = input(cu,   "Pick your poison:", options=[notBuy, cu, clu, rsi, mcl, mcl0, sgl0])-CH      = input(0,    " if RSI >")+CH      = input.int(0,    " if RSI >")-CL      = input(100,  " if RSI <")+CL      = input.int(100,  " if RSI <")-CH_HTF  = input(0,    " if RSI (HTF) >")+CH_HTF  = input.int(0,    " if RSI (HTF) >")-CL_HTF  = input(100,  " if RSI (HTF) <")+CL_HTF  = input.int(100,  " if RSI (HTF) <")CX      = input(none, " Extra argument", options=[none, mcl, mcl0, sgl0, hisbr])CX2     = input(none, " Second argument", options=[none, mcl_HTF, mcl0HTF, sgl0HTF, cu_HTF, clu_HTF])-_2b_    = input(false, ">=< [xMA settings (Sell/Short)] >=<")+_2b_    = input.bool(false, ">=< [xMA settings (Sell/Short)] >=<")-ma3     = input(defval="SMA", title="  xMA 3"       , options=["SMA", "EMA", "WMA", "HullMA", "VWMA", "RMA", "TEMA"])+ma3     = input.string(defval="SMA", title="  xMA 3"       , options=["SMA", "EMA", "WMA", "HullMA", "VWMA", "RMA", "TEMA"])-len3    = input(50,   "     Length"  )+len3    = input.int(50,   "     Length"  )-ma4     = input(defval="SMA", title="  xMA 4"       , options=["SMA", "EMA", "WMA", "HullMA", "VWMA", "RMA", "TEMA"])+ma4     = input.string(defval="SMA", title="  xMA 4"       , options=["SMA", "EMA", "WMA", "HullMA", "VWMA", "RMA", "TEMA"])-len4    = input(100,  "     Length"  )+len4    = input.int(100,  "     Length"  )-ma3HTF  = input(defval="SMA", title="  xMA 3 - HTF" , options=["SMA", "EMA", "WMA", "HullMA", "VWMA", "RMA", "TEMA"])+ma3HTF  = input.string(defval="SMA", title="  xMA 3 - HTF" , options=["SMA", "EMA", "WMA", "HullMA", "VWMA", "RMA", "TEMA"])-len3HTF = input(50,   "     Length"  )+len3HTF = input.int(50,   "     Length"  )-ma4HTF  = input(defval="SMA", title="  xMA 4 - HTF" , options=["SMA", "EMA", "WMA", "HullMA", "VWMA", "RMA", "TEMA"])+ma4HTF  = input.string(defval="SMA", title="  xMA 4 - HTF" , options=["SMA", "EMA", "WMA", "HullMA", "VWMA", "RMA", "TEMA"])-len4HTF = input(100,  "     Length"  )+len4HTF = input.int(100,  "     Length"  )-__3_    = input(false, ">=< >=< [RSI]  >=< >=< >=<")+__3_    = input.bool(false, ">=< >=< [RSI]  >=< >=< >=<")-ler     = input(20 , "  RSI Length")+ler     = input.int(20 , "  RSI Length")-__4_    = input(false, ">=< >=< [MACD] >=< >=< >=<")+__4_    = input.bool(false, ">=< >=< [MACD] >=< >=< >=<")-fst     = input(12, "  Fast Length")+fst     = input.int(12, "  Fast Length")-slw     = input(26, "  Slow Length")+slw     = input.int(26, "  Slow Length")-sgn     = input(9 , "  Signal Smoothing")+sgn     = input.int(9 , "  Signal Smoothing")-sma_source = input(false, "Simple MA(Oscillator)")+sma_source = input.bool(false, "Simple MA(Oscillator)")-sma_signal = input(false, "Simple MA(Signal Line)")+sma_signal = input.bool(false, "Simple MA(Signal Line)")-__5_    = input(false, ">=< >=< [HTF settings] >=< >=<")+__5_    = input.bool(false, ">=< >=< [HTF settings] >=< >=<")MA_HTF  = input.timeframe("D", "  xMA HTF"  )⋯MACD_HTF= input.timeframe("D", "  MACD HTF" )-__6_    = input(false, ">=< >=< [SL/TP] >=< >=< >=<")+__6_    = input.bool(false, ">=< >=< [SL/TP] >=< >=< >=<")-SL      = input(10.0, title="  Stop Loss %"  ) / 100+SL      = input.float(10.0, title="  Stop Loss %"  ) / 100-TP      = input(20.0, title="  Take Profit %") / 100+TP      = input.float(20.0, title="  Take Profit %") / 100 ⋯// (= inspired from a script of "Che_Trader")-xox     = input(false, ">=< >=< [TIME] >=< >=< >=<")+xox     = input.bool(false, ">=< >=< [TIME] >=< >=< >=<")-ystr1   = input(2010, "  Since Year" )+ystr1   = input.int(2010, "  Since Year" )-ystp1   = input(2099, "  Till Year"  )+ystp1   = input.int(2099, "  Till Year"  )-mstr1   = input(1   , "  Since Month")+mstr1   = input.int(1   , "  Since Month")-mstp1   = input(12  , "  Till Month" )+mstp1   = input.int(12  , "  Till Month" )-dstr1   = input(1   , "  Since Day"  )+dstr1   = input.int(1   , "  Since Day"  )-dstp1   = input(31  , "  Till Day"   )+dstp1   = input.int(31  , "  Till Day"   ) ⋯

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: 12 before, 13 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.

⋯// © fikira-//@version=5+//@version=6strategy("Strategy Tester EMA-SMA-RSI-MACD", shorttitle="Strat-test", overlay=true, max_bars_back=5000, ⋯

Settings

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

SettingDefaultType and rangeFeeds
Sourceclosesourcersi_ fast_ma slow_ma BUY SELL line 118 line 119 line 120 line 121 line 122 line 123 line 124
>=< >=< [STRATEGIES] >=< >=<falseboolunused
Type Strategy_L_value · options [L_S, _L_, _S_]SLTP_long SLTP_short TP_long TP_short close_long close_short Long Short close [S] entry [B] close [B] entry [S] line 216 line 221
>=< >=< [BUY/LONG] >=< >=<falseboolunused
Pick your poison:covalue · options [co, cla, rsi, mch, mch0, sgh0]BUY xMA 1 xMA 2
if RSI >0intRSI
if RSI <100intRSI
if RSI (HTF) >0intRSI
if RSI (HTF) <100intRSI
Extra argumentnonevalue · options [none, mch, mch0, sgh0, hisbl]extra
Second argumentnonevalue · options [none, mch_HTF, mch0HTF, sgh0HTF, co_HTF, cla_HTF]EXTRA xMA 1 HTF xMA 2 HTF
>=< [xMA settings (Buy/Long)] >=<falseboolunused
xMA 1SMAstring · options ["SMA", "EMA", "WMA", "HullMA", "VWMA", "RMA", "TEMA"]_1
Length50int_1
xMA 2SMAstring · options ["SMA", "EMA", "WMA", "HullMA", "VWMA", "RMA", "TEMA"]_2
Length100int_2
xMA 1 - HTFSMAstring · options ["SMA", "EMA", "WMA", "HullMA", "VWMA", "RMA", "TEMA"]_1b
Length50int_1b
xMA 2 - HTFSMAstring · options ["SMA", "EMA", "WMA", "HullMA", "VWMA", "RMA", "TEMA"]_2b
Length100int_2b
>=< >=< [SELL/SHORT] >=< >=<falseboolunused
Pick your poison:cuvalue · options [notBuy, cu, clu, rsi, mcl, mcl0, sgl0]SELL xMA 3 xMA 4
if RSI >0intunused
if RSI <100intunused
if RSI (HTF) >0intunused
if RSI (HTF) <100intunused
Extra argumentnonevalue · options [none, mcl, mcl0, sgl0, hisbr]cxtra
Second argumentnonevalue · options [none, mcl_HTF, mcl0HTF, sgl0HTF, cu_HTF, clu_HTF]CXTRA xMA 3 HTF xMA 4 HTF
>=< [xMA settings (Sell/Short)] >=<falseboolunused
xMA 3SMAstring · options ["SMA", "EMA", "WMA", "HullMA", "VWMA", "RMA", "TEMA"]_3
Length50int_3
xMA 4SMAstring · options ["SMA", "EMA", "WMA", "HullMA", "VWMA", "RMA", "TEMA"]_4
Length100int_4
xMA 3 - HTFSMAstring · options ["SMA", "EMA", "WMA", "HullMA", "VWMA", "RMA", "TEMA"]_3b
Length50int_3b
xMA 4 - HTFSMAstring · options ["SMA", "EMA", "WMA", "HullMA", "VWMA", "RMA", "TEMA"]_4b
Length100int_4b
>=< >=< [RSI] >=< >=< >=<falseboolunused
RSI Length20intrsi_
>=< >=< [MACD] >=< >=< >=<falseboolunused
Fast Length12intfast_ma
Slow Length26intslow_ma
Signal Smoothing9intsignal
Simple MA(Oscillator)falseboolfast_ma slow_ma
Simple MA(Signal Line)falseboolsignal
>=< >=< [HTF settings] >=< >=<falseboolunused
xMA HTFDtimeframe (written input.resolution)_1_HTF _2_HTF _3_HTF _4_HTF cl_HTF
RSI HTFDtimeframe (written input.resolution)rsi_HTF
MACD HTFDtimeframe (written input.resolution)macd_HTF signal_HTF
>=< >=< [SL/TP] >=< >=< >=<falseboolunused
Stop Loss %10.0floatSL_B SL_S
Take Profit %20.0floatTP_B TP_S
>=< >=< [TIME] >=< >=< >=<falseboolunused
Since Year2010int_Str1
Till Year2099intStp1_
Since Month1int_Str1
Till Month12intStp1_
Since Day1int_Str1
Till Day31intStp1_

What it calculates

  • RSI (rsi, ta.rsi in v5)Source (close), RSI Length (20)rsi_ · line 151
  • SMA / EMA (sma, ta.sma in v5)Source (close), Fast Length (12)fast_ma · line 155
  • SMA / EMA (sma, ta.sma in v5)Source (close), Slow Length (26)slow_ma · line 156
  • SMA / EMA (sma, ta.sma in v5)macd, Signal Smoothing (9)signal · line 158

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.

The script has 109 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.

Order rules

OrderFires whenBy defaultLine
Close [S](Type == _S_)On217
Open [B] long(Type == _S_)On219
Close [B](Type == _L_)On222
Open [S] short(Type == _L_)On224
Exit [SL/TP] stop and limitSL_BOn226
Exit [SL/TP] stop and limitSL_SOn228

Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.

Does it repaint?

Yes

At least one pattern in the source can repaint; it is marked Check below.

3/3trades 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.
  • CheckHigher-timeframe data8 security call(s) use lookahead_on (line 133, 134, 135, 136, 137, 152, 160, 161). Without a [1] offset this reads future bars in history.
  • 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+5.7%+102.5%1250%1.0928.4%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−5.4%+5.5%540%0.5710.1%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−7.1%+9.8%2540%0.9546.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+18.7%+8.4%850%2.4513.6%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+8.7%+16.7%3537%1.0443.5%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+30.2%+21.5%863%2.2412.4%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−8.1%+148.3%3037%0.9652.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−11.5%+17.1%1050%0.6227.6%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 market367%$15.08
Sideways market838%−$9.87
Falling market1100%$0.48

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

How bad could the drawdown be?

35.8%

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

0%41%
All 12 trades
SideEntryExitBarsP&L
long5 May 2024 63,892.0030 May 2024 67,652.4025$5.89
long22 Jun 2024 64,143.604 Jul 2024 57,729.2012−$10.59
long5 Jul 2024 57,050.0012 Jul 2024 57,339.907$0.48
long23 Oct 2024 67,426.0010 Nov 2024 80,911.2018$19.16
long11 Nov 2024 80,370.0021 Nov 2024 96,444.0010$22.99
long22 Nov 2024 98,317.1025 Feb 2025 88,485.4095−$13.79
long26 Feb 2025 88,680.4028 Feb 2025 79,812.402−$12.41
long1 Mar 2025 84,349.906 Mar 2025 90,606.005$8.29
long16 May 2025 103,764.0030 Sep 2025 114,312.00137$12.20
long3 May 2026 78,686.801 Jun 2026 70,818.1029−$13.22
long2 Jun 2026 71,408.903 Jun 2026 64,268.001−$11.90
long4 Jun 2026 64,142.8022 Jun 2026 63,312.0018−$1.39

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
Strategy Tester EMA-SMA-RSI-MACD this page—v4 strategy+5.7%1228.4%
MACD, RSI, & RVOL Strategy by BobBarker42069rsi ema smav4 strategy+32.6%11.5%
IFR2 - RSI2 by jocker.soadrsi sma emav4 strategyNo trades on this market
Vin's Playzone Strategy by Vvaz_ema rsi smav5 strategy−908.1%213,570.5%
Momentum Explosion 2CCI RSI by capamema sma rsiv4 strategy+24.1%642.3%
3 x EMA + Stochastic RSI + ATR by tomimarsonema rsi smav4 strategy−42.3%1844.8%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 43 msYes 1,000 bars in 235 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/// © fikira//@version=4strategy("Strategy Tester EMA-SMA-RSI-MACD", shorttitle="Strat-test", overlay=true, max_bars_back=5000,  default_qty_type= strategy.percent_of_equity, calc_on_order_fills=false, calc_on_every_tick=false,  pyramiding=0, default_qty_value=100, initial_capital=100)//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////                                      "&" issue when added to _L_ : //L_S     = "Long & Short"                , _L_  = "Long & Only"                , _S_ = "Short Only"//                               no issue (initial correct working version) : L_S     = "Long & Short"                , _L_  = "Long Only"                , _S_ = "Short Only"////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Tiny     = "Tiny"Small    = "Small"Normal   = "Normal"Large    = "Large"cl      = "close" , op  = "open" , hi  = "high" , lo  = "low"c4      = "ohlc4" , c3  = "hlc3" , hl  = "hl2"co      = "xMA 1 > xMA 2" cu      = "xMA 3 < xMA 4"co_HTF  = "xMA 1 (HTF) > xMA 2 (HTF)" cu_HTF  = "xMA 3 (HTF) < xMA 4 (HTF)"cla     = "Close above xMA 1"         clu     = "Close under xMA 3"cla_HTF = "Close above xMA 1 (HTF)"clu_HTF = "Close under xMA 3 (HTF)"rsi     = "RSI strategy"notBuy  = "BUY = false"                 , none    = "NONE"mch     = "macd > signal"               , mcl     = "macd < signal"mch0    = "macd > 0"                    , mcl0    = "macd < 0"sgh0    = "signal > 0"                  , sgl0    = "signal < 0"hisbl   = "hist > hist[1]"              , hisbr   = "hist < hist[1]"mch_HTF = "macd (HTF) > signal (HTF)"   , mcl_HTF = "macd (HTF) < signal (HTF)"mch0HTF = "macd (HTF) > 0"              , mcl0HTF = "macd (HTF) < 0"sgh0HTF = "signal (HTF) > 0"            , sgl0HTF = "signal (HTF) < 0"//s       = input(cl,   "Source" , options=[cl, op, hi, lo, c4, c3, hl])src       = input(title="Source", type=input.source, defval=close)//src     =// s  == cl ? close :// s  == op ? open  :// s  == hi ? high  :// s  == lo ? low   :// s  == c4 ? ohlc4 :// s  == c3 ? hlc3  : // s  == hl ? hl2   :// source__1_    = input(false, ">=< >=< [STRATEGIES] >=< >=<")Type    = input(_L_,  "Type Strategy", options=[L_S, _L_, _S_])_1a_    = input(false, ">=< >=< [BUY/LONG] >=< >=<")ENT     = input(co,   "Pick your poison:", options=[co, cla, rsi, mch, mch0, sgh0])EH      = input(0,    " if RSI >")EL      = input(100,  " if RSI <")EH_HTF  = input(0,    " if RSI (HTF) >")EL_HTF  = input(100,  " if RSI (HTF) <")EX      = input(none, " Extra argument", options=[none, mch, mch0, sgh0, hisbl])EX2     = input(none, " Second argument", options=[none, mch_HTF, mch0HTF, sgh0HTF, co_HTF, cla_HTF])_1b_    = input(false, ">=< [xMA settings (Buy/Long)] >=<")ma1     = input(defval="SMA", title="  xMA 1"       , options=["SMA", "EMA", "WMA", "HullMA", "VWMA", "RMA", "TEMA"])len1    = input(50,   "     Length"  )ma2     = input(defval="SMA", title="  xMA 2"       , options=["SMA", "EMA", "WMA", "HullMA", "VWMA", "RMA", "TEMA"])len2    = input(100,  "     Length"  )ma1HTF  = input(defval="SMA", title="  xMA 1 - HTF" , options=["SMA", "EMA", "WMA", "HullMA", "VWMA", "RMA", "TEMA"])len1HTF = input(50,   "     Length"  )ma2HTF  = input(defval="SMA", title="  xMA 2 - HTF" , options=["SMA", "EMA", "WMA", "HullMA", "VWMA", "RMA", "TEMA"])len2HTF = input(100,  "     Length"  )_2a_    = input(false, ">=< >=< [SELL/SHORT] >=< >=<")CLO     = input(cu,   "Pick your poison:", options=[notBuy, cu, clu, rsi, mcl, mcl0, sgl0])CH      = input(0,    " if RSI >")CL      = input(100,  " if RSI <")CH_HTF  = input(0,    " if RSI (HTF) >")CL_HTF  = input(100,  " if RSI (HTF) <")CX      = input(none, " Extra argument", options=[none, mcl, mcl0, sgl0, hisbr])CX2     = input(none, " Second argument", options=[none, mcl_HTF, mcl0HTF, sgl0HTF, cu_HTF, clu_HTF])_2b_    = input(false, ">=< [xMA settings (Sell/Short)] >=<")ma3     = input(defval="SMA", title="  xMA 3"       , options=["SMA", "EMA", "WMA", "HullMA", "VWMA", "RMA", "TEMA"])len3    = input(50,   "     Length"  )ma4     = input(defval="SMA", title="  xMA 4"       , options=["SMA", "EMA", "WMA", "HullMA", "VWMA", "RMA", "TEMA"])len4    = input(100,  "     Length"  )ma3HTF  = input(defval="SMA", title="  xMA 3 - HTF" , options=["SMA", "EMA", "WMA", "HullMA", "VWMA", "RMA", "TEMA"])len3HTF = input(50,   "     Length"  )ma4HTF  = input(defval="SMA", title="  xMA 4 - HTF" , options=["SMA", "EMA", "WMA", "HullMA", "VWMA", "RMA", "TEMA"])len4HTF = input(100,  "     Length"  )__3_    = input(false, ">=< >=< [RSI]  >=< >=< >=<")ler     = input(20 , "  RSI Length")__4_    = input(false, ">=< >=< [MACD] >=< >=< >=<")fst     = input(12, "  Fast Length")slw     = input(26, "  Slow Length")sgn     = input(9 , "  Signal Smoothing")sma_source = input(false, "Simple MA(Oscillator)")sma_signal = input(false, "Simple MA(Signal Line)")__5_    = input(false, ">=< >=< [HTF settings] >=< >=<")MA_HTF  = input("D", "  xMA HTF"  , type = input.resolution)RSI_HTF = input("D", "  RSI HTF"  , type = input.resolution)MACD_HTF= input("D", "  MACD HTF" , type = input.resolution)__6_    = input(false, ">=< >=< [SL/TP] >=< >=< >=<")SL      = input(10.0, title="  Stop Loss %"  ) / 100TP      = input(20.0, title="  Take Profit %") / 100 SL_B    = strategy.position_avg_price * (1 - SL)TP_B    = strategy.position_avg_price * (1 + TP)SL_S    = strategy.position_avg_price * (1 + SL)TP_S    = strategy.position_avg_price * (1 - TP)// Limitation in time// (= inspired from a script of "Che_Trader")xox     = input(false, ">=< >=< [TIME] >=< >=< >=<")ystr1   = input(2010, "  Since Year" )ystp1   = input(2099, "  Till Year"  )mstr1   = input(1   , "  Since Month")mstp1   = input(12  , "  Till Month" )dstr1   = input(1   , "  Since Day"  )dstp1   = input(31  , "  Till Day"   ) _Str1   = timestamp(ystr1, mstr1, dstr1,  1,  1)Stp1_   = timestamp(ystp1, mstp1, dstp1, 23, 59)TIME    = time >= _Str1 and time <= Stp1_ ? true : false////////////////////////////////////////////////////////////////////////////////////////////f_xma(type, len) =>   type == "SMA"    ?  sma(src,len) :   type == "EMA"    ?  ema(src,len) :   type == "WMA"    ?  wma(src,len) :   type == "VWMA"   ? vwma(src,len) :   type == "RMA"    ?  rma(src,len) :    type == "HullMA" ?  wma(2*wma(src, len/2)-wma(src, len), round(sqrt(len))) :   3 * (ema(src, len) - ema(ema(src, len), len)) + ema(ema(ema(src, len), len), len)_1     = f_xma(ma1   , len1   )_2     = f_xma(ma2   , len2   )_3     = f_xma(ma3   , len3   )_4     = f_xma(ma4   , len4   )_1b    = f_xma(ma1HTF, len1HTF)_2b    = f_xma(ma2HTF, len2HTF)_3b    = f_xma(ma3HTF, len3HTF)_4b    = f_xma(ma4HTF, len4HTF)_1_HTF = security(syminfo.tickerid, MA_HTF,  _1b  , lookahead = barmerge.lookahead_on)_2_HTF = security(syminfo.tickerid, MA_HTF,  _2b  , lookahead = barmerge.lookahead_on)_3_HTF = security(syminfo.tickerid, MA_HTF,  _3b  , lookahead = barmerge.lookahead_on)_4_HTF = security(syminfo.tickerid, MA_HTF,  _4b  , lookahead = barmerge.lookahead_on)cl_HTF = security(syminfo.tickerid, MA_HTF,  close, lookahead = barmerge.lookahead_on)////////////////////////////////////////////////////////////////////////////////////////////plot(ENT == co or ENT == cla ? _1 : na            , "xMA 1"    ,                    color.lime                                              )plot(ENT == co               ? _2 : na            , "xMA 2"    ,                    color.red                                               )plot(CLO == cu or CLO == clu ? _3 : na            , "xMA 3"    ,     _3 == _1     ? color.lime : color.yellow                               )plot(CLO == cu               ? _4 : na            , "xMA 4"    ,     _4 == _2     ? color.red  : color.blue  , 2, plot.style_line           )plot(EX2 == co_HTF or EX2 == cla_HTF ? _1_HTF : na, "xMA 1 HTF",                    color.lime               , 2, plot.style_line, false, 50)plot(EX2 == co_HTF                   ? _2_HTF : na, "xMA 2 HTF",                    color.red                , 2, plot.style_line, false, 50)plot(CX2 == cu_HTF or CX2 == clu_HTF ? _3_HTF : na, "xMA 3 HTF", _3_HTF == _1_HTF ? color.lime : color.yellow, 2, plot.style_line, false, 50)plot(CX2 == cu_HTF or CX2 == clu_HTF ? _3_HTF : na, "xMA 3 HTF", _3_HTF == _1_HTF ? color.lime : color.yellow, 2, plot.style_line, false, 50)plot(CX2 == cu_HTF                   ? _4_HTF : na, "xMA 4 HTF", _4_HTF == _2_HTF ? color.red  : color.blue  , 2, plot.style_line, false, 50)//plot(series, title, color, linewidth, style, trackprice, transp, histbase, offset, join, editable, show_last, display) → plot////////////////////////////////////////////////////////////////////////////////////////////// RSIrsi_       = rsi(src, ler)rsi_HTF    = security(syminfo.tickerid, RSI_HTF , rsi_  , lookahead = barmerge.lookahead_on)////////////////////////////////////////////////////////////////////////////////////////////// MACDfast_ma    = sma_source ? sma(src, fst)  : ema(src , fst)slow_ma    = sma_source ? sma(src, slw)  : ema(src , slw)macd       = fast_ma - slow_masignal     = sma_signal ? sma(macd, sgn) : ema(macd, sgn)hist       = macd - signalmacd_HTF   = security(syminfo.tickerid, MACD_HTF, macd  , lookahead = barmerge.lookahead_on)signal_HTF = security(syminfo.tickerid, MACD_HTF, signal, lookahead = barmerge.lookahead_on)////////////////////////////////////////////////////////////////////////////////////////////extra =  EX  == none    ? true                   : EX  == mch     ? macd >  signal         : EX  == mch0    ? macd >  0              : EX  == sgh0    ? signal >  0            : EX  == hisbl   ? hist[1] < 0  and    hist    > hist[1]                : falsecxtra =  CX  == none    ? true                   : CX  == mcl     ? macd   <= signal       : CX  == mcl0    ? macd   <= 0            : CX  == sgl0    ? signal <= 0            : CX  == hisbr   ? hist[1] > 0  and    hist    < hist[1]                : falseEXTRA =  EX2 == none    ? true                   : EX2 == mch_HTF ? macd_HTF >  signal_HTF : EX2 == mch0HTF ? macd_HTF >  0          : EX2 == sgh0HTF ? signal_HTF >  0        : EX2 == co_HTF  ? _1_HTF >  _2_HTF       : EX2 == cla_HTF ? cl_HTF >  _1_HTF       :  false CXTRA = CX2 == none    ? true                   : CX2 == mcl_HTF ? macd_HTF <= signal_HTF : CX2 == mcl0HTF ? macd_HTF <= 0          : CX2 == sgl0HTF ? signal_HTF <= 0        : CX2 == cu_HTF  ? _3_HTF <= _4_HTF       : CX2 == clu_HTF ? cl_HTF <= _3_HTF       :  falseRSI = rsi_ > EH and rsi_ <= EL and rsi_HTF > EH_HTF and rsi_HTF <= EL_HTF/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////BUY =  ENT == co    and TIME and extra and EXTRA and RSI ? _1     > _2      :  ENT == cla   and TIME and extra and EXTRA and RSI ? src    > _1      :  ENT == rsi   and TIME and extra and EXTRA         ? RSI              :  ENT == mch   and TIME and extra and EXTRA and RSI ? macd   > signal  :  ENT == mch0  and TIME and extra and EXTRA and RSI ? macd   > 0       :  ENT == sgh0  and TIME and extra and EXTRA and RSI ? signal > 0       :  naSELL =  CLO == notBuy                                     ? not BUY          :                               CLO == cu    and TIME and cxtra and CXTRA and RSI ? _3     <= _4     :  CLO == clu   and TIME and cxtra and CXTRA and RSI ? src    <= _3     :  CLO == rsi   and TIME and cxtra and CXTRA         ? RSI              : CLO == mcl   and TIME and cxtra and CXTRA and RSI ? macd   <= signal :  CLO == mcl0  and TIME and cxtra and CXTRA and RSI ? macd   <= 0      :  CLO == sgl0  and TIME and cxtra and CXTRA and RSI ? signal <= 0      :  naif BUY    if (Type == _S_)        strategy.close("[S]")    else        strategy.entry("[B]", strategy.long)if SELL    if (Type == _L_)        strategy.close("[B]")    else        strategy.entry("[S]", strategy.short)if SL_B    strategy.exit("[SL/TP]" , "[B]", stop= SL_B, limit= TP_B)if SL_S    strategy.exit("[SL/TP]" , "[S]", stop= SL_S, limit= TP_S)SLTP_long   = Type != _S_    and BUY [1]     and (low  <= SL_B [1] or high >= TP_B[1])SLTP_short  = Type != _L_    and SELL[1]     and (high >= SL_S [1] or low  <= TP_S[1])TP_long     = Type != _S_    and BUY [1]     and  high >= TP_B [1]TP_short    = Type != _L_    and SELL[1]     and  low  <= TP_S [1]close_long  = not SLTP_long  and Type == _L_ and  SELL and BUY [1]close_short = not SLTP_short and Type == _S_ and  BUY  and SELL[1]SLTP        = SLTP_long[1] or SLTP_short[1] Long        = Type != _S_    and ((BUY       and not BUY[1] ) or (BUY  and SLTP)) and not close_shortShort       = Type != _L_    and ((SELL      and not SELL[1]) or (SELL and SLTP)) and not close_longplotshape(series=Short           , title="Short"      , style=shape.triangledown, location=location.abovebar, color=color.orange, size=size.tiny )plotshape(series=Long            , title="Long"       , style=shape.triangleup  , location=location.belowbar, color=color.lime  , size=size.tiny )plotshape(series=SLTP_long       , title="SL/TP Long" , style=shape.xcross      , location=location.abovebar, color=color.lime  , size=size.tiny )plotshape(series=SLTP_short      , title="SL/TP Short", style=shape.xcross      , location=location.belowbar, color=color.red   , size=size.tiny )plotshape(series=close_long      , title="Close Long" , style=shape.square      , location=location.abovebar, color=color.lime  , size=size.tiny )plotshape(series=close_short     , title="Close Short", style=shape.square      , location=location.belowbar, color=color.red   , size=size.tiny )//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////                                                        Debugging                                                       ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////plot = Type == _S_ and BUY ? 1 : Type != _S_ and BUY ? 2 : Type == _L_ and SELL ? -1 : Type != _L_ and SELL ? -2 :na//plot(plot)//plotchar(BUY, "", color=na)//plotchar(SL_B, "", color=na)//plotchar(SELL, "", color=na)//plotchar(SL_S, "", color=na)