xmd79

EMA Savy by olistr

Oct 2nd, 2021
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. //@version=4
  2.  
  3. strategy("EMA Savy by olistr", overlay=true, initial_capital=20000, commission_type=strategy.commission.percent, commission_value=0.05)
  4. //plot(ema(close, 8), color=#FFFF00, linewidth=2, title='8 Day EMA')
  5. //plot(ema(close, 13), color=#CCFF66, linewidth=2, title='13 Day EMA')
  6. plot(ema(close, 21), color=color.orange, linewidth=2, title='21 Day EMA')
  7. plot(ema(close, 55), color=color.white, linewidth=2, title='55 Day EMA')
  8. plot(ema(close, 200), color=color.red, linewidth=2, title='200 Day EMA')
  9.  
  10. // Calculate moving averages
  11. ema_8 = ema(close, 8)
  12. ema_13 = ema(close, 13)
  13. ema_21 = ema(close, 21)
  14. ema_55 = ema(close, 55)
  15. ema_200 = ema(close, 200)
  16.  
  17. buycond1= ema_8>ema_13 and ema_13 >ema_21 and ema_21>ema_55 and ema_55>ema_200
  18. buycond2= crossover(ema_21[1], ema_55[1])
  19. buycond3= open > ema_8 and close > ema_8
  20. buycond = buycond1 and buycond2 and buycond3
  21. buyclosecond1 = crossunder(ema_21[1], ema_55[1])
  22. buyclosecond2 = open < ema_8 and close < ema_8
  23. buyclosecond = buyclosecond1 and buyclosecond2
  24. sellcond1= ema_8<ema_13 and ema_13 <ema_21 and ema_21<ema_55 and ema_55<ema_200
  25. sellcond2= crossunder(ema_21[1], ema_55[1])
  26. sellcond3= open < ema_8 and close < ema_8
  27. sellcond = sellcond1 and sellcond2 and sellcond3
  28. sellclosecond1 = crossover(ema_21[1], ema_55[1])
  29. sellclosecond2 = open > ema_8 and close > ema_8
  30. sellclosecond = sellclosecond1 and sellclosecond2
  31.  
  32. strategy.entry(id="long_entry", long=strategy.long, when=buycond)
  33. strategy.exit(id="exit_long", from_entry="long_entry", stop= strategy.position_avg_price-1*atr(14))
  34. strategy.close(id="long_entry", when=buyclosecond)
  35. strategy.entry(id="short_entry", long=strategy.short, when=sellcond)
  36. strategy.exit(id="exit_short", from_entry="short_entry", stop= strategy.position_avg_price+1*atr(14))
  37. strategy.close(id="short_entry", when=sellclosecond)
  38.  
  39. // Crossover Function buy
  40. // plotshape(buycond, color=color.green, style = shape.labeldown, location=location.belowbar, offset=0,textcolor = color.white, text = "Buy Signal")
  41. // Crossunder Function sell
  42. // plotshape(sellcond, color=color.red, style = shape.labelup, location=location.abovebar, offset=0, textcolor = color.white, text = "Sell Signal")
  43.  
  44.  
  45.  
Advertisement
Add Comment
Please, Sign In to add comment