Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=4
- strategy("EMA Savy by olistr", overlay=true, initial_capital=20000, commission_type=strategy.commission.percent, commission_value=0.05)
- //plot(ema(close, 8), color=#FFFF00, linewidth=2, title='8 Day EMA')
- //plot(ema(close, 13), color=#CCFF66, linewidth=2, title='13 Day EMA')
- plot(ema(close, 21), color=color.orange, linewidth=2, title='21 Day EMA')
- plot(ema(close, 55), color=color.white, linewidth=2, title='55 Day EMA')
- plot(ema(close, 200), color=color.red, linewidth=2, title='200 Day EMA')
- // Calculate moving averages
- ema_8 = ema(close, 8)
- ema_13 = ema(close, 13)
- ema_21 = ema(close, 21)
- ema_55 = ema(close, 55)
- ema_200 = ema(close, 200)
- buycond1= ema_8>ema_13 and ema_13 >ema_21 and ema_21>ema_55 and ema_55>ema_200
- buycond2= crossover(ema_21[1], ema_55[1])
- buycond3= open > ema_8 and close > ema_8
- buycond = buycond1 and buycond2 and buycond3
- buyclosecond1 = crossunder(ema_21[1], ema_55[1])
- buyclosecond2 = open < ema_8 and close < ema_8
- buyclosecond = buyclosecond1 and buyclosecond2
- sellcond1= ema_8<ema_13 and ema_13 <ema_21 and ema_21<ema_55 and ema_55<ema_200
- sellcond2= crossunder(ema_21[1], ema_55[1])
- sellcond3= open < ema_8 and close < ema_8
- sellcond = sellcond1 and sellcond2 and sellcond3
- sellclosecond1 = crossover(ema_21[1], ema_55[1])
- sellclosecond2 = open > ema_8 and close > ema_8
- sellclosecond = sellclosecond1 and sellclosecond2
- strategy.entry(id="long_entry", long=strategy.long, when=buycond)
- strategy.exit(id="exit_long", from_entry="long_entry", stop= strategy.position_avg_price-1*atr(14))
- strategy.close(id="long_entry", when=buyclosecond)
- strategy.entry(id="short_entry", long=strategy.short, when=sellcond)
- strategy.exit(id="exit_short", from_entry="short_entry", stop= strategy.position_avg_price+1*atr(14))
- strategy.close(id="short_entry", when=sellclosecond)
- // Crossover Function buy
- // plotshape(buycond, color=color.green, style = shape.labeldown, location=location.belowbar, offset=0,textcolor = color.white, text = "Buy Signal")
- // Crossunder Function sell
- // plotshape(sellcond, color=color.red, style = shape.labelup, location=location.abovebar, offset=0, textcolor = color.white, text = "Sell Signal")
Advertisement
Add Comment
Please, Sign In to add comment