This has positive expected value on /NQ if anyone wants to mess with this:
// spiritedDog12914
//
@version=4strategy("EMA Moving Averages Strategy", shorttitle="EMA_MA", overlay=true)
// Input Parameters
ema9_len = input(9, title="9 EMA Length", type=input.integer)
sma200_len = input(200, title="200 SMA Length", type=input.integer)
sma50_len = input(50, title="50 SMA Length", type=input.integer)
sl_bars = input(2, title="Stop Loss: Consecutive Bars Away from 9 EMA", type=input.integer)
// Indicators
ema9 = ema(close, ema9_len)
sma200 = sma(close, sma200_len)
sma50 = sma(close, sma50_len)
// Entry Conditions
longCondition = crossover(ema9, sma50) and close > sma200
shortCondition = crossunder(ema9, sma50) and close < sma200
if (longCondition)
strategy.entry("Long", strategy.long)
if (shortCondition)
strategy.entry("Short", strategy.short)
// Exit Conditions
exitLongCondition = barssince(close > ema9) >= sl_bars
exitShortCondition = barssince(close < ema9) >= sl_bars
if (exitLongCondition)
strategy.close("Long")
if (exitShortCondition)
strategy.close("Short")
// Profit Target
profitTargetLongCondition = abs(ema9[0] - ema9[1]) <= abs(ema9[1] - ema9[2])
profitTargetShortCondition = abs(ema9[0] - ema9[1]) >= abs(ema9[1] - ema9[2])
if (profitTargetLongCondition)
strategy.close("Long")
if (profitTargetShortCondition)
strategy.close("Short")
// Plotting
plot(ema9, title="9 EMA", color=color.blue, linewidth=2)
plot(sma200, title="200 SMA", color=color.red, linewidth=2)
plot(sma50, title="50 SMA", color=color.green, linewidth=2)
bgcolor(longCondition ? color.green : na, transp=80)
bgcolor(shortCondition ? color.red : na, transp=80)
bgcolor(exitLongCondition ? color.yellow : na, transp=80)
bgcolor(exitShortCondition ? color.yellow : na, transp=80)
You don’t trade for money, you trade for freedom.