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
- 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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Show Date Range | true | bool | unused |
| Trail Long Loss (%) | 3 | float · min 0.0 · step 0.1 | longStopPrice stopValue |
| Trail Short Loss (%) | 1 | float · min 0.0 · step 0.1 | shortStopPrice stopValue |
What it calculates
- EMAclose, 8
fastEMA · line 16 - EMAclose, 26
slowEMA · line 17 - MACDclose, 12, 26, 9
macd · line 23 - MACDclose, 12, 26, 9
macd_signal · line 23 - MACDclose, 12, 26, 9
macd_histogram · line 23 - Crossovermacd, macd_signal
buyCondition2 · 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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Long long | (buyCondition1 and buyCondition2 and notInTrade and timePeriod) | On | 43 |
| Exit Exit stop and limit | every bar | On | 44 |
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.
- 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.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | −4.5% | +102.5% | 18 | 44% | 0.58 | 7.7% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −4.3% | +5.5% | 8 | 0% | 0.00 | 4.7% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −0.5% | +9.8% | 11 | 45% | 0.95 | 4.4% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −4.9% | +8.4% | 12 | 25% | 0.26 | 5.9% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +8.2% | +16.7% | 11 | 64% | 3.28 | 1.7% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −0.1% | +21.5% | 9 | 44% | 0.96 | 2.6% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +12.1% | +148.3% | 20 | 50% | 2.81 | 2.7% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +1.7% | +17.1% | 9 | 33% | 1.45 | 2.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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 9 | 33% | −$21.22 |
| Sideways market | 7 | 71% | $5.25 |
| Falling market | 2 | 0% | −$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.
All 18 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 5 Jun 2024 71,108.00 | 7 Jun 2024 68,675.10 | 2 | −$10.84 |
| long | 14 Oct 2024 66,084.00 | 21 Oct 2024 66,961.00 | 7 | $3.34 |
| long | 28 Oct 2024 69,962.20 | 31 Oct 2024 70,554.30 | 3 | $1.92 |
| long | 6 Nov 2024 75,572.00 | 12 Nov 2024 85,988.60 | 6 | $40.44 |
| long | 16 Dec 2024 106,059.00 | 18 Dec 2024 102,950.00 | 2 | −$9.70 |
| long | 5 Jan 2025 98,363.60 | 7 Jan 2025 99,168.50 | 2 | $1.90 |
| long | 15 Jan 2025 100,497.00 | 19 Jan 2025 101,420.00 | 4 | $2.21 |
| long | 18 May 2025 106,454.00 | 23 May 2025 108,345.00 | 5 | $4.86 |
| long | 10 Jun 2025 110,274.00 | 13 Jun 2025 105,386.00 | 3 | −$14.35 |
| long | 26 Jun 2025 106,947.00 | 2 Jul 2025 105,106.00 | 6 | −$5.87 |
| long | 22 Jul 2025 119,954.00 | 25 Jul 2025 115,193.00 | 3 | −$12.66 |
| long | 11 Aug 2025 118,686.00 | 14 Aug 2025 119,607.00 | 3 | $1.73 |
| long | 1 Oct 2025 118,595.00 | 7 Oct 2025 120,919.00 | 6 | $5.28 |
| long | 25 Mar 2026 71,336.50 | 27 Mar 2026 66,755.70 | 2 | −$19.99 |
| long | 4 May 2026 79,861.00 | 13 May 2026 79,743.80 | 9 | −$1.03 |
| long | 7 Aug 2026 64,923.20 | 13 Aug 2026 63,013.70 | 6 | −$9.29 |
| long | 3 Sep 2026 81,270.40 | 8 Sep 2026 77,931.60 | 5 | −$12.62 |
| long | 21 Sep 2026 86,620.00 | 23 Sep 2026 83,622.30 | 2 | −$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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Fast EMA above Slow EMA with MACD (by Coinrule) this page | — | v5 strategy | −4.5% | 18 | 7.7% |
| Short Swing Bearish MACD Cross (By Coinrule) by Coinrule | ema macd | v5 strategy | −6.9% | 8 | 6.9% |
| MACD Trend Strategy by Zeal Terminal | macd ema | v5 strategy | −1.0% | 21 | 3.5% |
| EMA and MACD with Trailing Stop Loss (by Coinrule) by Coinrule | ema macd | v5 strategy | +3.3% | 22 | 4.6% |
| RSI of MACD Strategy [Long only] by mohanee | macd ema | v4 strategy | No trades on this market | ||
| Macd Divergence + MTF EMA by Trading_Solutions_ | macd ema | v5 strategy | No 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.
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
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 12 ms | With a workaround 1,000 bars in 24 ms | Not measured |
| PineTS | Not tested | Not tested | Not 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)