OPEN-SOURCE SCRIPT

SMMA 40/225 Crossover Alert (Bar Close)

23
//version=5
indicator("SMMA 40/225 Crossover Alert (Bar Close)", shorttitle="SMMA Cross Alert", overlay=true)

// === SMMA Function ===
smma(src, length) =>
sma_ = ta.sma(src, length)
smma = 0.0
smma := na(smma[1]) ? sma_ : (smma[1] * (length - 1) + src) / length
smma

// === Calculate SMMA 40 & 225 ===
smma40 = smma(close, 40)
smma225 = smma(close, 225)

// === Crossover Conditions (confirmed after bar close) ===
bullishCross = ta.crossover(smma40, smma225)
bearishCross = ta.crossunder(smma40, smma225)

// === Trigger only after bar close ===
bullishSignal = bullishCross and barstate.isconfirmed
bearishSignal = bearishCross and barstate.isconfirmed

// === Alerts ===
alertcondition(bullishSignal, title="SMMA Bullish Crossover", message="✅ SMMA 40 crossed ABOVE SMMA 225 — BUY Signal (Confirmed at Bar Close)")
alertcondition(bearishSignal, title="SMMA Bearish Crossover", message="❌ SMMA 40 crossed BELOW SMMA 225 — SELL Signal (Confirmed at Bar Close)")

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.