The code enforces fast < slow < baseline lengths and waits at least baselineLength chart bars. That gate is a display policy, not proof that initialization effects have disappeared. The developing bar is blank, and the Data Window shows 1, -1 or 0 only for an available confirmed state.
One-timeframe EMA direction filterpinescript
//@version=6
indicator("Confirmed EMA Direction [Pineify]", overlay=true)
int fastLength = input.int(20, "Fast EMA length", minval=1)
int slowLength = input.int(50, "Slow EMA length", minval=2)
int baselineLength = input.int(200, "Baseline EMA length", minval=3)
if fastLength >= slowLength or slowLength >= baselineLength
runtime.error("Require fast < slow < baseline lengths.")
float fastEma = ta.ema(close, fastLength)
float slowEma = ta.ema(close, slowLength)
float baseline = ta.ema(close, baselineLength)
bool ready = bar_index >= baselineLength - 1 and not na(baseline) and not na(fastEma) and not na(slowEma)
bool confirmed = ready and barstate.isconfirmed
int state = close > baseline and fastEma > slowEma ? 1 : close < baseline and fastEma < slowEma ? -1 : 0
color stateColor = state == 1 ? color.teal : state == -1 ? color.orange : color.gray
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)
plot(confirmed ? baseline : na, "Baseline EMA", color=color.blue, linewidth=2, style=plot.style_linebr)
fill(pFast, pSlow, color=confirmed ? color.new(stateColor, 80) : na, fillgaps=false)
plot(confirmed ? state : na, "State: 1 bullish, -1 bearish, 0 neutral", display=display.data_window)
bgcolor(confirmed ? color.new(stateColor, 93) : na)