Trying to write a pine script for showing the 10ema crossing above the 21ema within the past 3 days. If a script already exist for this or is close to this please provide links.
Below is the script I wrote which did not work.
//@version=5
indicator("EMA Cross", overlay=true)
length1 = 10
length2 = 21
ema1 = ta.ema(close, length1)
ema2 = ta.ema(close, length2)
crossedAbove = ta.crossover(ema1, ema2)
// Check if crossover occurred within the past 3 days
within3Days = ta.change(crossedAbove) < 3
if crossedAbove and within3Days
label.new(x = bar_index, y = close, text = "EMA Cross", style = label.style_label_up, color = color.green)