Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

Fast EMA above Slow EMA with MACD (by Coinrule)

A Pine Script v5 strategy built on EMA (close, 8), MACD (close, 12) and Crossover (macd, macd_signal). It has 2 order rules, 1 entry among them, and trades long only with the default settings. Exits use a stop loss and a profit target. Each trade commits 30% of equity and pays 0.1% commission. 3 settings; defaults include Trail Long Loss (%) 3 and Trail Short Loss (%) 1.

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 Fast EMA above Slow EMA with MACD (by Coinrule) repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 5 of 5 trades.
How did Fast EMA above Slow EMA with MACD (by Coinrule) do on BTCUSDT 1D with default settings?
−4.52%
From 26 Jan 2024 to 21 Oct 2026, over 18 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Does Fast EMA above Slow EMA with MACD (by Coinrule) 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: 18 before, 18 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download.
Does Fast EMA above Slow EMA with MACD (by Coinrule) use a stop loss?
Yes
strategy.exit sets a stop on line 44.
Does Fast EMA above Slow EMA with MACD (by Coinrule) run in Zeal Terminal?
Yes
It compiles in 12 ms and runs 1,000 bars in 24 ms, in the browser.

BTCUSDT · 1D · default settings

  • Plot
  • Plot
  • Winning trade
  • Losing trade
  • Equity
  • Buy and hold
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (3)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$955$2,025Equity from $1,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots. Zeal Terminal's engine currently reads an order side written as direction = strategy.long as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 43) so the engine trades the way the script says.
Net profit
−4.52%
−$45.24
Buy and hold
+102.5%
same period
Closed trades
18
8 won · 10 lost
Profitable
44.4%
of closed trades
Profit factor
0.58
gross profit ÷ gross loss
Max drawdown
7.74%
−$80.10

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

    1 setting does nothing

    “Show Date Range” is declared but never read.

  • Note

    No slippage

    Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.

Settings

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

SettingDefaultType and rangeFeeds
Show Date Rangetrueboolunused
Trail Long Loss (%)3float · min 0.0 · step 0.1longStopPrice stopValue
Trail Short Loss (%)1float · min 0.0 · step 0.1shortStopPrice stopValue

What it calculates

  • EMAclose, 8fastEMA · line 16
  • EMAclose, 26slowEMA · line 17
  • MACDclose, 12, 26, 9macd · line 23
  • MACDclose, 12, 26, 9macd_signal · line 23
  • MACDclose, 12, 26, 9macd_histogram · line 23
  • Crossovermacd, macd_signalbuyCondition2 · line 24

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 datashortTrailPercTrail Short Loss (%)setting · 1timetimeprice datalongTrailPercTrail Long Loss (%)setting · 3fastEMAEMA→ fastEMAslowEMAEMA→ slowEMAmacdMACD→ macdmacd_signalMACD→ macd_signalmacd_histogramMACD→ macd_histogrambuyCondition2Crossover→ buyCondition2stopValuestopValuevaluetimePeriodtimePeriodconditionnotInTradenotInTradeconditionbuyCondition1buyCondition1conditionlongStopPricelongStopPriceconditionshortStopPriceshortStopPriceconditionentry:LongOpen Longstrategy.entryexit:Exitexit Exitstrategy.exitplot:18plotplotplot:19plotplot

Order rules

OrderFires whenBy defaultLine
Open Long long(buyCondition1 and buyCondition2 and notInTrade and timePeriod)On43
Exit Exit stop and limitevery barOn44

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.

5/5trades 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 timingprocess_orders_on_close = true: orders fill at the signal bar's close.

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−4.5%+102.5%1844%0.587.7%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−4.3%+5.5%80%0.004.7%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−0.5%+9.8%1145%0.954.4%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−4.9%+8.4%1225%0.265.9%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+8.2%+16.7%1164%3.281.7%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−0.1%+21.5%944%0.962.6%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+12.1%+148.3%2050%2.812.7%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+1.7%+17.1%933%1.452.7%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 market933%−$21.22
Sideways market771%$5.25
Falling market20%−$29.27

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

How bad could the drawdown be?

9.1%

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

0%10%
All 18 trades
SideEntryExitBarsP&L
long5 Jun 2024 71,108.007 Jun 2024 68,675.102−$10.84
long14 Oct 2024 66,084.0021 Oct 2024 66,961.007$3.34
long28 Oct 2024 69,962.2031 Oct 2024 70,554.303$1.92
long6 Nov 2024 75,572.0012 Nov 2024 85,988.606$40.44
long16 Dec 2024 106,059.0018 Dec 2024 102,950.002−$9.70
long5 Jan 2025 98,363.607 Jan 2025 99,168.502$1.90
long15 Jan 2025 100,497.0019 Jan 2025 101,420.004$2.21
long18 May 2025 106,454.0023 May 2025 108,345.005$4.86
long10 Jun 2025 110,274.0013 Jun 2025 105,386.003−$14.35
long26 Jun 2025 106,947.002 Jul 2025 105,106.006−$5.87
long22 Jul 2025 119,954.0025 Jul 2025 115,193.003−$12.66
long11 Aug 2025 118,686.0014 Aug 2025 119,607.003$1.73
long1 Oct 2025 118,595.007 Oct 2025 120,919.006$5.28
long25 Mar 2026 71,336.5027 Mar 2026 66,755.702−$19.99
long4 May 2026 79,861.0013 May 2026 79,743.809−$1.03
long7 Aug 2026 64,923.2013 Aug 2026 63,013.706−$9.29
long3 Sep 2026 81,270.408 Sep 2026 77,931.605−$12.62
long21 Sep 2026 86,620.0023 Sep 2026 83,622.302−$10.58

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
Fast EMA above Slow EMA with MACD (by Coinrule) this page—v5 strategy−4.5%187.7%
Short Swing Bearish MACD Cross (By Coinrule) by Coinruleema macdv5 strategy−6.9%86.9%
MACD Trend Strategy by Zeal Terminalmacd emav5 strategy−1.0%213.5%
EMA and MACD with Trailing Stop Loss (by Coinrule) by Coinruleema macdv5 strategy+3.3%224.6%
RSI of MACD Strategy [Long only] by mohaneemacd emav4 strategyNo trades on this market
Macd Divergence + MTF EMA by Trading_Solutions_macd emav5 strategyNo trades on this market

Upgrade and export

Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.

  • 1 setting uses the untyped input() (line 12). It still compiles in v6; input.int, input.float or input.source state the type.
  • No v6-only features. v6 is not needed to run this script.

Clean v5

VerifiedDownload the v5 script

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

  • Line 12: input() → input.bool()
⋯         commission_value=0.1)-showDate = input(defval=true, title='Show Date Range')+showDate = input.bool(defval=true, title='Show Date Range')timePeriod = time >= timestamp(syminfo.timezone, 2022, 1, 1, 0, 0)⋯

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

⋯// © Coinrule-//@version=5+//@version=6strategy('Fast EMA above Slow EMA with MACD (by Coinrule)',⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 12 msWith a workaround 1,000 bars in 24 msNot measured
PineTSNot testedNot testedNot measured

Zeal Terminal's engine currently reads an order side written as direction = strategy.long as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 43) 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.

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/// © Coinrule//@version=5strategy('Fast EMA above Slow EMA with MACD (by Coinrule)',         overlay=true,         initial_capital=1000,         process_orders_on_close=true,         default_qty_type=strategy.percent_of_equity,         default_qty_value=30,         commission_type=strategy.commission.percent,         commission_value=0.1)showDate = input(defval=true, title='Show Date Range')timePeriod = time >= timestamp(syminfo.timezone, 2022, 1, 1, 0, 0)notInTrade = strategy.position_size <= 0// EMAs fastEMA = ta.ema(close, 8)slowEMA = ta.ema(close, 26)plot(fastEMA, color = color.blue)plot(slowEMA, color = color.green)//buyCondition1 = ta.crossover(fastEMA, slowEMA)buyCondition1 = fastEMA > slowEMA// DMI and MACD inputs and calculations[macd, macd_signal, macd_histogram] = ta.macd(close, 12, 26, 9)buyCondition2 = ta.crossover(macd, macd_signal)// Configure trail stop level with input optionslongTrailPerc = input.float(title='Trail Long Loss (%)', minval=0.0, step=0.1, defval=3) * 0.01shortTrailPerc = input.float(title='Trail Short Loss (%)', minval=0.0, step=0.1, defval=1) * 0.01// Determine trail stop loss priceslongStopPrice = 0.0shortStopPrice = 0.0longStopPrice := if strategy.position_size > 0    stopValue = close * (1 - longTrailPerc)    math.max(stopValue, longStopPrice[1])else    0shortStopPrice := if strategy.position_size < 0    stopValue = close * (1 + shortTrailPerc)    math.min(stopValue, shortStopPrice[1])else    999999    if (buyCondition1 and buyCondition2 and notInTrade and timePeriod)    strategy.entry(id="Long", direction = strategy.long)strategy.exit(id="Exit", stop = longStopPrice, limit = shortStopPrice)//if (sellCondition1 and sellCondition2 and notInTrade and timePeriod)//strategy.close(id="Close", when = sellCondition1 or sellCondition2)