OPEN-SOURCE SCRIPT
SMMA 40/225 Crossover Alert (Bar Close)

//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)")
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)")
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
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.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
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.