Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

charl macd ema rsi

A Pine Script v4 strategy built on EMA (close, fast) and SMA (macd, 9). It has 6 order rules, 4 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. 2 settings; defaults include EMA 200 and RSI 14.

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

BTCUSDT · 1D · default settings

  • EMA
  • EMA
  • SMA
  • 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 (2)
0.0050,000100,000AprJulOct2025AprJulOct2026AprJulOct$49,484$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. The script plots nothing itself; the lines and the lower pane are its own calculations, drawn for reference. Lines, boxes and labels are the script's own drawings, the most recent ones its limits keep. Zeal Terminal's engine currently reads an order side written as true, false as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 21, 29, 41, 45) so the engine trades the way the script says.
Net profit
−49.47%
−$49,471.30
Buy and hold
+102.5%
same period
Closed trades
59
20 won · 39 lost
Profitable
33.9%
of closed trades
Profit factor
0.66
gross profit ÷ gross loss
Max drawdown
76.88%
−$80,307.20

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

    2 settings have no label

    In the settings dialog ema (line 11), rsi (line 12) 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.

  • Note

    Uses an argument v6 removed

    when = on line 21, 24, 29, 31, 41, 45. The upgraded version below moves each call inside an if block.

Upgrade and export

Written in Pine Script v4. The upgrade to v5 takes 1 step, one per version, each applied to the result of the one before. A last clean-v5 pass then types the settings and moves when = into if blocks, which v6 requires. Every step runs before and after on the same candles in Zeal Terminal's engine; a step whose results differ is shown but not offered as a download. Upgrades preserve behaviour: bugs are fixed in the Review, never silently here.

  • Upgrading to v5 renames ema → ta.ema, sma → ta.sma, rsi → ta.rsi.
  • 6 strategy calls use the when = argument (line 21, 24, 29, 31, 41, 45). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

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

  • Line 4: //@version=4 → //@version=5
  • Line 7: ema → ta.ema
  • Line 8: ema → ta.ema
  • Line 10: sma → ta.sma
  • Line 11: ema → ta.ema
  • Line 12: rsi → ta.rsi
4 more edits
  • Line 21: strategy.entry(…, true) → strategy.entry(…, strategy.long)
  • Line 29: strategy.entry(…, false) → strategy.entry(…, strategy.short)
  • Line 41: strategy.entry(…, false) → strategy.entry(…, strategy.short)
  • Line 45: strategy.entry(…, true) → strategy.entry(…, strategy.long)
⋯//Good with trending markets-//@version=4+//@version=5strategy("CHARL MACD EMA RSI")fast = 12, slow = 26-fastMA = ema(close, fast)+fastMA = ta.ema(close, fast)-slowMA = ema(close, slow)+slowMA = ta.ema(close, slow)macd = fastMA - slowMA-signal = sma(macd, 9)+signal = ta.sma(macd, 9)-ema = ema(close, input(200))+ema = ta.ema(close, input(200))-rsi = rsi(close, input(14))+rsi = ta.rsi(close, input(14))//when delta > 0  and close above ema buy⋯if (buy_entry and bought == false and rsi <= 70) -    strategy.entry("Buy",true , when=buy_entry)+    strategy.entry("Buy",strategy.long , when=buy_entry)    bought := true⋯if (sell_entry and sold == false and rsi >= 30)-    strategy.entry("Sell",false , when=sell_entry)+    strategy.entry("Sell",strategy.short , when=sell_entry)    sold := true⋯    if (rsi < 70 and sold == false and delta < 0)-        strategy.entry("Sell",false , when= delta < 0)+        strategy.entry("Sell",strategy.short , when= delta < 0)        sold := true⋯    else if (rsi > 30 and bought == false and delta > 0)-        strategy.entry("Buy",true , when= delta > 0)+        strategy.entry("Buy",strategy.long , when= delta > 0)        bought := true⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 11: input() → input.int()
  • Line 12: input() → input.int()
  • Line 21: when = buy_entry → if block
  • Line 24: when = delta<0 or rsi > 70 → if block
  • Line 29: when = sell_entry → if block
  • Line 31: when = delta>0 or rsi < 30 → if block
  • Line 41: when = delta < 0 → if block
  • Line 45: when = delta > 0 → if block
⋯signal = ta.sma(macd, 9)-ema = ta.ema(close, input(200))+ema = ta.ema(close, input.int(200))-rsi = ta.rsi(close, input(14))+rsi = ta.rsi(close, input.int(14))//when delta > 0  and close above ema buy⋯if (buy_entry and bought == false and rsi <= 70) -    strategy.entry("Buy",strategy.long , when=buy_entry)+    if buy_entry+        strategy.entry("Buy",strategy.long )    bought := true    -strategy.close("Buy",when= delta<0 or rsi > 70)+if delta<0 or rsi > 70+    strategy.close("Buy")if (delta<0 and bought==true)⋯if (sell_entry and sold == false and rsi >= 30)-    strategy.entry("Sell",strategy.short , when=sell_entry)+    if sell_entry+        strategy.entry("Sell",strategy.short )    sold := true-strategy.close("Sell",when= delta>0 or rsi < 30)+if delta>0 or rsi < 30+    strategy.close("Sell")if (delta>0 and sold==true)⋯    if (rsi < 70 and sold == false and delta < 0)-        strategy.entry("Sell",strategy.short , when= delta < 0)+        if delta < 0+            strategy.entry("Sell",strategy.short )        sold := true⋯    else if (rsi > 30 and bought == false and delta > 0)-        strategy.entry("Buy",strategy.long , when= delta > 0)+        if delta > 0+            strategy.entry("Buy",strategy.long )        bought := true⋯

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: 59 before, 48 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.

⋯//Good with trending markets-//@version=5+//@version=6strategy("CHARL MACD EMA RSI")⋯

Settings

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

SettingDefaultType and rangeFeeds
EMA (no label in the script)200intbuy_entry sell_entry
RSI (no label in the script)14intplacing entry Buy entry Sell entry Sell entry Buy line 20 close Buy line 28 close Sell line 35 line 40 line 44

What it calculates

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

Signal flow

How price data and settings reach the orders. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.

closecloseprice datalowlowprice datahighhighprice datarsiRSIsetting · 14emaEMAsetting · 200fastMAEMA→ fastMAslowMAEMA→ slowMAsignalSMA→ signalmacdmacdvaluedeltadeltavalueplacingplacingvaluebuy_entrybuy_entryconditionsell_entrysell_entryconditionentry:BuyOpen Buystrategy.entryclose:BuyClose Buystrategy.closeentry:SellOpen Sellstrategy.entryclose:SellClose Sellstrategy.close

Order rules

OrderFires whenBy defaultLine
Open Buy longbuy_entryclose>ema and delta > 0On21
Close Buydelta<0 or rsi > 70On24
Open Sell shortsell_entryclose<ema and delta<0On29
Close Selldelta>0 or rsi < 30On31
Open Sell shortdelta < 0On41
Open Buy longdelta > 0On45

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.

14/14trades 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−49.5%+102.5%5934%0.6676.9%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−19.5%+5.5%6734%0.5920.3%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−1.6%+9.8%5446%0.763.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−0.5%+8.4%6433%0.680.6%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.0%+16.7%4953%1.050.2%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−0.0%+21.5%5843%0.720.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−0.6%+148.3%6146%0.630.6%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+0.1%+17.1%5345%1.420.1%8 May 2026 – 21 Oct 2026

Backtests are simulations on historical data and are not investment advice.

The trades

By market direction

At entry, last 90 barsTradesWonP&L
Rising market1844%−$6,930.93
Sideways market3033%−$33,559.20
Falling market1118%−$8,981.19

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

How bad could the drawdown be?

81.6%

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

0%94%
All 59 trades
SideEntryExitBarsP&L
long29 Feb 2024 62,432.101 Mar 2024 61,131.001−$1,301.12
short16 Mar 2024 69,499.8030 Mar 2024 69,850.5014−$350.69
short25 Jun 2024 60,293.302 Jul 2024 62,900.007−$2,606.70
short5 Jul 2024 57,050.006 Jul 2024 56,628.801$421.23
long13 Jul 2024 57,889.1031 Jul 2024 66,188.0018$8,298.91
short6 Aug 2024 54,018.8014 Aug 2024 60,587.208−$6,568.34
long24 Aug 2024 64,037.2030 Aug 2024 59,359.006−$4,678.24
short30 Aug 2024 59,359.0012 Sep 2024 57,338.0013$2,021.00
long19 Sep 2024 61,760.002 Oct 2024 60,804.9013−$955.06
short2 Oct 2024 60,804.9015 Oct 2024 66,084.0013−$5,279.08
long15 Oct 2024 66,084.0021 Oct 2024 69,032.006$2,948.00
short26 Oct 2024 66,698.3030 Oct 2024 72,736.404−$6,038.09
long30 Oct 2024 72,736.4031 Oct 2024 72,344.801−$391.66
short4 Nov 2024 68,776.007 Nov 2024 75,572.003−$6,796.00
long7 Nov 2024 75,572.008 Nov 2024 75,857.901$285.90
short26 Nov 2024 93,010.0017 Dec 2024 106,059.0021−$13,048.60
long17 Dec 2024 106,059.0018 Dec 2024 106,134.001$75.09
short19 Dec 2024 100,204.005 Jan 2025 98,220.5017$1,983.50
long5 Jan 2025 98,220.5010 Jan 2025 92,552.505−$5,668.02
long16 Jan 2025 100,497.0028 Jan 2025 102,083.0012$1,585.48
long16 Feb 2025 97,569.7017 Feb 2025 96,118.101−$1,451.55
long21 Feb 2025 98,305.0025 Feb 2025 91,552.904−$6,752.13
short26 Feb 2025 88,680.4027 Feb 2025 84,250.101$4,430.30
long6 Mar 2025 90,606.0010 Mar 2025 80,734.504−$9,871.52
short10 Mar 2025 80,734.5016 Mar 2025 84,338.406−$3,603.96
long16 Mar 2025 84,338.401 Apr 2025 82,550.0016−$1,788.44
short1 Apr 2025 82,550.006 Apr 2025 83,538.005−$987.99
short7 Apr 2025 78,430.0013 Apr 2025 85,276.906−$6,846.91
long22 Apr 2025 87,516.203 May 2025 96,887.1011$9,370.91
short5 May 2025 94,277.609 May 2025 103,262.004−$8,984.00
long9 May 2025 103,262.0010 May 2025 102,972.001−$289.62
short17 May 2025 103,464.0022 May 2025 109,644.005−$6,180.09
long22 May 2025 109,644.0023 May 2025 111,696.001$2,052.23
short26 May 2025 109,004.0011 Jun 2025 110,274.0016−$1,270.19
long11 Jun 2025 110,274.0015 Jun 2025 105,415.004−$4,859.76
long26 Jun 2025 107,341.0011 Jul 2025 116,010.0015$8,669.42
short21 Jul 2025 117,265.0011 Aug 2025 119,294.0021−$2,029.16
long11 Aug 2025 119,294.0018 Aug 2025 117,405.007−$1,889.26
long5 Sep 2025 110,731.0023 Sep 2025 112,651.0018$1,920.12
long2 Oct 2025 118,595.006 Oct 2025 123,482.004$4,887.33
short11 Oct 2025 112,774.0026 Oct 2025 111,646.0015$1,128.22
long26 Oct 2025 111,646.004 Nov 2025 106,583.009−$5,063.22
short4 Nov 2025 106,583.0018 Nov 2025 92,215.1014$14,367.90
long27 Nov 2025 90,484.0017 Dec 2025 87,863.4020−$2,620.58
short17 Dec 2025 87,863.4022 Dec 2025 88,658.905−$795.44
long15 Jan 2026 96,951.8021 Jan 2026 88,427.706−$8,524.12
short21 Jan 2026 88,427.701 Feb 2026 78,741.1011$9,686.56
long15 Feb 2026 69,822.9022 Mar 2026 68,918.1035−$904.82
short22 Mar 2026 68,918.106 Apr 2026 69,034.2015−$116.06
short29 Apr 2026 76,342.806 May 2026 80,905.507−$4,562.75
long11 May 2026 82,210.1013 May 2026 80,504.502−$1,705.60
short13 May 2026 80,504.503 Jun 2026 66,760.8021$13,743.60
long13 Jun 2026 63,580.0026 Jun 2026 59,794.6013−$3,785.36
short26 Jun 2026 59,794.603 Jul 2026 61,560.007−$1,765.36
short28 Jul 2026 63,755.908 Aug 2026 64,923.2011−$1,167.34
short13 Aug 2026 63,480.0019 Aug 2026 64,725.406−$1,245.43
long20 Aug 2026 69,334.8021 Aug 2026 73,027.001$3,692.24
short2 Sep 2026 77,439.0021 Sep 2026 81,178.0019−$3,739.00
long21 Sep 2026 81,178.0022 Sep 2026 86,620.001$5,442.00

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
charl macd ema rsi this page—v4 strategy−49.5%5976.9%
MACD Long Strat by TheGrindTodayema smav4 strategy+24.0%7920.1%
Stock trending strategy by exlux99ema smav4 strategy+35.3%2114.7%
4-Hour Stochastic EMA Trend by slymnturkogluema smav4 strategyNo trades on this market
4X EMA and volume strategy by SoftKill21ema smav4 strategy+1.8%325.8%
Simple Momentum Strategy Based on SMA, EMA and Volume by slip_streamsma emav4 strategy+7.4%1827.4%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 15 msWith a workaround 1,000 bars in 21 msNot measured
PineTSNo v5 and v6 only—Not measured

Zeal Terminal's engine currently reads an order side written as true, false as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 21, 29, 41, 45) so the engine trades the way the script says.

“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/// © mbuthiacharles4//Good with trending markets//@version=4strategy("CHARL MACD EMA RSI")fast = 12, slow = 26fastMA = ema(close, fast)slowMA = ema(close, slow)macd = fastMA - slowMAsignal = sma(macd, 9)ema = ema(close, input(200))rsi = rsi(close, input(14))//when delta > 0  and close above ema buydelta = macd - signalbuy_entry= close>ema and delta > 0sell_entry = close<ema and delta<0 var bought = falsevar sold = falsevar reversal = falseif (buy_entry and bought == false and rsi <= 70)     strategy.entry("Buy",true , when=buy_entry)    bought := true    strategy.close("Buy",when= delta<0 or rsi > 70)if (delta<0 and bought==true)    bought := false//handle sellsif (sell_entry and sold == false and rsi >= 30)    strategy.entry("Sell",false , when=sell_entry)    sold := truestrategy.close("Sell",when= delta>0 or rsi < 30)if (delta>0 and sold==true)    sold := false    if (rsi > 70 or rsi < 30)    reversal := true    placing = rsi > 70 ? high :low    label.new(bar_index, placing, style=label.style_flag, color=color.blue, size=size.tiny)if (reversal == true)    if (rsi < 70 and sold == false and delta < 0)        strategy.entry("Sell",false , when= delta < 0)        sold := true        reversal := false    else if (rsi > 30 and bought == false and delta > 0)        strategy.entry("Buy",true , when= delta > 0)        bought := true        reversal := false