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
- 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
VerifiedSame 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)////////////////////////////////////////////////////////////////////////////////////////////⋯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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Source | close | source | rsi_ fast_ma slow_ma BUY SELL line 118 line 119 line 120 line 121 line 122 line 123 line 124 |
| >=< >=< [STRATEGIES] >=< >=< | false | bool | unused |
| 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] >=< >=< | false | bool | unused |
| Pick your poison: | co | value · options [co, cla, rsi, mch, mch0, sgh0] | BUY xMA 1 xMA 2 |
| if RSI > | 0 | int | RSI |
| if RSI < | 100 | int | RSI |
| if RSI (HTF) > | 0 | int | RSI |
| if RSI (HTF) < | 100 | int | RSI |
| Extra argument | none | value · options [none, mch, mch0, sgh0, hisbl] | extra |
| Second argument | none | value · options [none, mch_HTF, mch0HTF, sgh0HTF, co_HTF, cla_HTF] | EXTRA xMA 1 HTF xMA 2 HTF |
| >=< [xMA settings (Buy/Long)] >=< | false | bool | unused |
| xMA 1 | SMA | string · options ["SMA", "EMA", "WMA", "HullMA", "VWMA", "RMA", "TEMA"] | _1 |
| Length | 50 | int | _1 |
| xMA 2 | SMA | string · options ["SMA", "EMA", "WMA", "HullMA", "VWMA", "RMA", "TEMA"] | _2 |
| Length | 100 | int | _2 |
| xMA 1 - HTF | SMA | string · options ["SMA", "EMA", "WMA", "HullMA", "VWMA", "RMA", "TEMA"] | _1b |
| Length | 50 | int | _1b |
| xMA 2 - HTF | SMA | string · options ["SMA", "EMA", "WMA", "HullMA", "VWMA", "RMA", "TEMA"] | _2b |
| Length | 100 | int | _2b |
| >=< >=< [SELL/SHORT] >=< >=< | false | bool | unused |
| Pick your poison: | cu | value · options [notBuy, cu, clu, rsi, mcl, mcl0, sgl0] | SELL xMA 3 xMA 4 |
| if RSI > | 0 | int | unused |
| if RSI < | 100 | int | unused |
| if RSI (HTF) > | 0 | int | unused |
| if RSI (HTF) < | 100 | int | unused |
| Extra argument | none | value · options [none, mcl, mcl0, sgl0, hisbr] | cxtra |
| Second argument | none | value · options [none, mcl_HTF, mcl0HTF, sgl0HTF, cu_HTF, clu_HTF] | CXTRA xMA 3 HTF xMA 4 HTF |
| >=< [xMA settings (Sell/Short)] >=< | false | bool | unused |
| xMA 3 | SMA | string · options ["SMA", "EMA", "WMA", "HullMA", "VWMA", "RMA", "TEMA"] | _3 |
| Length | 50 | int | _3 |
| xMA 4 | SMA | string · options ["SMA", "EMA", "WMA", "HullMA", "VWMA", "RMA", "TEMA"] | _4 |
| Length | 100 | int | _4 |
| xMA 3 - HTF | SMA | string · options ["SMA", "EMA", "WMA", "HullMA", "VWMA", "RMA", "TEMA"] | _3b |
| Length | 50 | int | _3b |
| xMA 4 - HTF | SMA | string · options ["SMA", "EMA", "WMA", "HullMA", "VWMA", "RMA", "TEMA"] | _4b |
| Length | 100 | int | _4b |
| >=< >=< [RSI] >=< >=< >=< | false | bool | unused |
| RSI Length | 20 | int | rsi_ |
| >=< >=< [MACD] >=< >=< >=< | false | bool | unused |
| Fast Length | 12 | int | fast_ma |
| Slow Length | 26 | int | slow_ma |
| Signal Smoothing | 9 | int | signal |
| Simple MA(Oscillator) | false | bool | fast_ma slow_ma |
| Simple MA(Signal Line) | false | bool | signal |
| >=< >=< [HTF settings] >=< >=< | false | bool | unused |
| xMA HTF | D | timeframe (written input.resolution) | _1_HTF _2_HTF _3_HTF _4_HTF cl_HTF |
| RSI HTF | D | timeframe (written input.resolution) | rsi_HTF |
| MACD HTF | D | timeframe (written input.resolution) | macd_HTF signal_HTF |
| >=< >=< [SL/TP] >=< >=< >=< | false | bool | unused |
| Stop Loss % | 10.0 | float | SL_B SL_S |
| Take Profit % | 20.0 | float | TP_B TP_S |
| >=< >=< [TIME] >=< >=< >=< | false | bool | unused |
| Since Year | 2010 | int | _Str1 |
| Till Year | 2099 | int | Stp1_ |
| Since Month | 1 | int | _Str1 |
| Till Month | 12 | int | Stp1_ |
| Since Day | 1 | int | _Str1 |
| Till Day | 31 | int | Stp1_ |
What it calculates
- RSI (
rsi,ta.rsiin v5)Source (close), RSI Length (20)rsi_ · line 151 - SMA / EMA (
sma,ta.smain v5)Source (close), Fast Length (12)fast_ma · line 155 - SMA / EMA (
sma,ta.smain v5)Source (close), Slow Length (26)slow_ma · line 156 - SMA / EMA (
sma,ta.smain 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
| Order | Fires when | By default | Line |
|---|---|---|---|
| Close [S] | (Type == _S_) | On | 217 |
| Open [B] long | (Type == _S_) | On | 219 |
| Close [B] | (Type == _L_) | On | 222 |
| Open [S] short | (Type == _L_) | On | 224 |
| Exit [SL/TP] stop and limit | SL_B | On | 226 |
| Exit [SL/TP] stop and limit | SL_S | On | 228 |
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.
- 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.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | +5.7% | +102.5% | 12 | 50% | 1.09 | 28.4% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −5.4% | +5.5% | 5 | 40% | 0.57 | 10.1% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −7.1% | +9.8% | 25 | 40% | 0.95 | 46.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +18.7% | +8.4% | 8 | 50% | 2.45 | 13.6% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +8.7% | +16.7% | 35 | 37% | 1.04 | 43.5% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +30.2% | +21.5% | 8 | 63% | 2.24 | 12.4% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −8.1% | +148.3% | 30 | 37% | 0.96 | 52.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −11.5% | +17.1% | 10 | 50% | 0.62 | 27.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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 3 | 67% | $15.08 |
| Sideways market | 8 | 38% | −$9.87 |
| Falling market | 1 | 100% | $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.
All 12 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 5 May 2024 63,892.00 | 30 May 2024 67,652.40 | 25 | $5.89 |
| long | 22 Jun 2024 64,143.60 | 4 Jul 2024 57,729.20 | 12 | −$10.59 |
| long | 5 Jul 2024 57,050.00 | 12 Jul 2024 57,339.90 | 7 | $0.48 |
| long | 23 Oct 2024 67,426.00 | 10 Nov 2024 80,911.20 | 18 | $19.16 |
| long | 11 Nov 2024 80,370.00 | 21 Nov 2024 96,444.00 | 10 | $22.99 |
| long | 22 Nov 2024 98,317.10 | 25 Feb 2025 88,485.40 | 95 | −$13.79 |
| long | 26 Feb 2025 88,680.40 | 28 Feb 2025 79,812.40 | 2 | −$12.41 |
| long | 1 Mar 2025 84,349.90 | 6 Mar 2025 90,606.00 | 5 | $8.29 |
| long | 16 May 2025 103,764.00 | 30 Sep 2025 114,312.00 | 137 | $12.20 |
| long | 3 May 2026 78,686.80 | 1 Jun 2026 70,818.10 | 29 | −$13.22 |
| long | 2 Jun 2026 71,408.90 | 3 Jun 2026 64,268.00 | 1 | −$11.90 |
| long | 4 Jun 2026 64,142.80 | 22 Jun 2026 63,312.00 | 18 | −$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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Strategy Tester EMA-SMA-RSI-MACD this page | — | v4 strategy | +5.7% | 12 | 28.4% |
| MACD, RSI, & RVOL Strategy by BobBarker42069 | rsi ema sma | v4 strategy | +32.6% | 1 | 1.5% |
| IFR2 - RSI2 by jocker.soad | rsi sma ema | v4 strategy | No trades on this market | ||
| Vin's Playzone Strategy by Vvaz_ | ema rsi sma | v5 strategy | −908.1% | 21 | 3,570.5% |
| Momentum Explosion 2CCI RSI by capam | ema sma rsi | v4 strategy | +24.1% | 6 | 42.3% |
| 3 x EMA + Stochastic RSI + ATR by tomimarson | ema rsi sma | v4 strategy | −42.3% | 18 | 44.8% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 43 ms | Yes 1,000 bars in 235 ms | Not measured |
| PineTS | No 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)