Advertisement
GevinMG

Untitled

Apr 5th, 2024
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. //Copyrights belong to TopG Professor Michael from The Real World.
  2.  
  3. //@version=5
  4. indicator("Michael's EMA", overlay=true)
  5. src = close
  6.  
  7. // Input options for EMAs
  8. emaS_value = input.int(12, minval=1, title="EMA Small - Value")
  9. emaS = ta.ema(close, emaS_value)
  10. emaB_value = input.int(21, minval=1, title="EMA Big - Value")
  11. emaB = ta.ema(close, emaB_value)
  12.  
  13. EMA_UpTrend_color = input(color.green, title="EMA UpTrend Color")
  14. EMA_DownTrend_color = input(#ff0000, title="EMA DownTrend Color")
  15.  
  16. // Input options for Arrows
  17. arrowColorUp = input(color.green, title="Arrow Up Color")
  18. arrowColorDown = input(#ff0000, title="Arrow Down Color")
  19. arrowSize = input.int(50, minval=1, title="Arrow Size")
  20.  
  21. // Rules For Up and Down EMA trends
  22. EMA_UpTrend = emaS >= emaB
  23. EMA_DownTrend = emaS < emaB
  24.  
  25. // Rules for Arrows by using EMAs Crossover state
  26. var float crossover = na
  27. // Determine crossover state
  28. if (crossover == 1)
  29. crossover := na
  30. else if (EMA_UpTrend[1] and EMA_DownTrend)
  31. crossover := -1
  32. else if (crossover == -1)
  33. crossover := na
  34. else if (EMA_DownTrend[1] and EMA_UpTrend)
  35. crossover := 1
  36.  
  37.  
  38. // Plot EMAs on chart:
  39. plot(emaS, color=color.new(EMA_UpTrend ? EMA_UpTrend_color : EMA_DownTrend_color, 0), title="EMA Small", style=plot.style_line, linewidth=1, offset=0)
  40. plot(emaB, color=color.new(EMA_UpTrend ? EMA_UpTrend_color : EMA_DownTrend_color, 0), title="EMA Big", style=plot.style_line, linewidth=2, offset=0)
  41.  
  42. // Plot arrow when EMAs cross:
  43. plotarrow(crossover == 1 ? 1 : crossover == -1 ? -1 : na, title="Show Arrow on EMAs Cross", colorup=arrowColorUp, colordown=arrowColorDown, maxheight=arrowSize, offset=+1, display=display.none)
  44.  
  45. // Alerts
  46. alertcondition(crossover == 1, title="EMA Trend Up", message="EMA Trend Up - {{ticker}} - {{interval}}")
  47. alertcondition(crossover == -1, title="EMA Trend Down", message="EMA Trend Down - {{ticker}} - {{interval}}")
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement