9/21 EMA crossover with a 3R target
The 9-bar EMA crossing above the 21-bar EMA enters long at the next bar's open and crossing below enters short. 1R is the 14-bar ATR at the cross. The stop sits 1R away and the target 3R. An opposite cross turns the trade around. Its inputs set the two EMAs, 1R, the target and New York hours.
- Trades
- 6,171
- Won
- 26.5%
- Profit factor
- 0.91
- Net
- −38.1%
- Worst drawdown
- −45.8%
- Worst trade
- −$621
MNQ1! · 5-minute · 4 Nov 2024 → 22 Oct 2026 · $2.50 a contract each side and a tick of slippage · one contract on a $50,000 account
−$18,583 from 4 November 2024 to 23 February 2026, −$489.50 from 24 February 2026 to 22 October 2026.
//@version=6
// Suggested timeframe: 5-minute
strategy("9/21 EMA crossover with a 3R target", overlay=true, initial_capital=50000, default_qty_type=strategy.fixed, default_qty_value=1,
commission_type=strategy.commission.cash_per_contract, commission_value=2.5, slippage=1, margin_long=0, margin_short=0)
// Inputs: the two EMAs, the risk (1R is the 14-bar ATR at the cross), the target and the hours
fastLen = input.int(9, "Fast EMA", minval=1)
slowLen = input.int(21, "Slow EMA", minval=2)
atrLen = input.int(14, "ATR length", minval=1)
riskAtr = input.float(1.0, "Stop: ATR multiple (1R)", minval=0.1, step=0.1)
rMult = input.float(3.0, "Target (R)", minval=0.5, step=0.5)
nyOnly = input.bool(false, "New York hours only (9:30 to 16:00 and flat by the close)")
fast = ta.ema(close, fastLen)
slow = ta.ema(close, slowLen)
atr = ta.atr(atrLen)
inNY = not na(time(timeframe.period, "0930-1600", "America/New_York"))
lastNY = not na(time(timeframe.period, "1555-1600", "America/New_York"))
canEnter = not nyOnly or (inNY and not lastNY and not session.islastbar)
// A cross enters at the next bar's open, and an opposite cross turns the trade around. The stop sits
// 1R from the cross bar's close and the target 3R the other way
var float stopLevel = na
var float targetLevel = na
risk = atr * riskAtr
if ta.crossover(fast, slow) and canEnter
stopLevel := close - risk
targetLevel := close + risk * rMult
strategy.entry("Long", strategy.long)
strategy.exit("Long exit", from_entry="Long", stop=stopLevel, limit=targetLevel)
if ta.crossunder(fast, slow) and canEnter
stopLevel := close + risk
targetLevel := close - risk * rMult
strategy.entry("Short", strategy.short)
strategy.exit("Short exit", from_entry="Short", stop=stopLevel, limit=targetLevel)
// With New York hours only, a trade still open closes at 16:00, or on the session's last bar when the
// market closes early (a holiday half day) or halts for a long weekend
if nyOnly and (lastNY or session.islastbar)
strategy.close_all("Close", immediately=true)
plot(fast, "Fast EMA", color=color.new(#3D69A8, 0))
plot(slow, "Slow EMA", color=color.new(#E5A50A, 0))
