Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=4
- study(title="Close Above 5 EMA for 7 Bars", shorttitle="CA5E7", overlay=true)
- // Define the input for the EMA length
- ema_length = input(5, title="EMA Length")
- // Calculate the 5 EMA
- ema5 = ema(close, ema_length)
- // Initialize a variable to count consecutive bars above the EMA
- var consecutiveBarsAboveEMA = 0
- // Check if the close is above the 5 EMA
- isAboveEMA = close > ema5
- // Update the consecutiveBarsAboveEMA variable
- consecutiveBarsAboveEMA := isAboveEMA ? consecutiveBarsAboveEMA + 1 : 0
- // Plot the 5 EMA on the chart
- plot(ema5, color=color.blue, title="5 EMA")
- // Plot a shape above the bar when the condition is met for 7 bars
- plotshape(series=consecutiveBarsAboveEMA >= 7 ? 1 : na, location=location.abovebar, color=color.green, style=shape.triangleup, title="Above 5 EMA")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement