Advertisement
xmd79

Close Above 5 EMA for 7 Bars

Sep 17th, 2023
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. //@version=4
  2. study(title="Close Above 5 EMA for 7 Bars", shorttitle="CA5E7", overlay=true)
  3.  
  4. // Define the input for the EMA length
  5. ema_length = input(5, title="EMA Length")
  6.  
  7. // Calculate the 5 EMA
  8. ema5 = ema(close, ema_length)
  9.  
  10. // Initialize a variable to count consecutive bars above the EMA
  11. var consecutiveBarsAboveEMA = 0
  12.  
  13. // Check if the close is above the 5 EMA
  14. isAboveEMA = close > ema5
  15.  
  16. // Update the consecutiveBarsAboveEMA variable
  17. consecutiveBarsAboveEMA := isAboveEMA ? consecutiveBarsAboveEMA + 1 : 0
  18.  
  19. // Plot the 5 EMA on the chart
  20. plot(ema5, color=color.blue, title="5 EMA")
  21.  
  22. // Plot a shape above the bar when the condition is met for 7 bars
  23. plotshape(series=consecutiveBarsAboveEMA >= 7 ? 1 : na, location=location.abovebar, color=color.green, style=shape.triangleup, title="Above 5 EMA")
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement