This example uses fixed opacity, not a gradient. It hides values on the developing chart bar and starts displaying after at least slowLength chart bars. EMAs still depend on the available starting history. Equal averages have a neutral state. Alerts require the current chart bar to close and the prior bar to have passed the history gate.
EMA boundaries and confirmed chart-bar crossingspinescript
//@version=6
indicator("Confirmed EMA Cloud [Pineify]", overlay=true)
int fastLength = input.int(20, "Fast EMA length", minval=1)
int slowLength = input.int(50, "Slow EMA length", minval=2)
if fastLength >= slowLength
runtime.error("Fast length must be smaller than slow length.")
float fastEma = ta.ema(close, fastLength)
float slowEma = ta.ema(close, slowLength)
bool ready = bar_index >= slowLength - 1 and not na(fastEma) and not na(slowEma)
bool confirmed = ready and barstate.isconfirmed
int state = fastEma > slowEma ? 1 : fastEma < slowEma ? -1 : 0
color shade = state == 1 ? color.new(color.teal, 70) : state == -1 ? color.new(color.orange, 70) : color.new(color.gray, 85)
pFast = plot(confirmed ? fastEma : na, "Fast EMA", color=color.teal, style=plot.style_linebr)
pSlow = plot(confirmed ? slowEma : na, "Slow EMA", color=color.orange, style=plot.style_linebr)
fill(pFast, pSlow, color=confirmed ? shade : na, title="Confirmed EMA cloud", fillgaps=false)
bool crossesUp = ta.crossover(fastEma, slowEma)
bool crossesDown = ta.crossunder(fastEma, slowEma)
bool bullFlip = confirmed and ready[1] and crossesUp
bool bearFlip = confirmed and ready[1] and crossesDown
plotshape(bullFlip, title="Confirmed bullish cross", style=shape.triangleup, location=location.belowbar, color=color.teal, size=size.tiny)
plotshape(bearFlip, title="Confirmed bearish cross", style=shape.triangledown, location=location.abovebar, color=color.orange, size=size.tiny)
alertcondition(bullFlip, "Bullish EMA cross", "Fast EMA crossed above slow EMA on a closed chart bar.")
alertcondition(bearFlip, "Bearish EMA cross", "Fast EMA crossed below slow EMA on a closed chart bar.")