OPEN-SOURCE SCRIPT
5/20 SMA Trade Signal

//version=5
indicator("5/20 SMA Trade Signal", overlay=true)
// Inputs (editable if you want to tweak later)
fastLen = input.int(5, "Fast SMA (default 5)", minval=1)
slowLen = input.int(20, "Slow SMA (default 20)", minval=1)
// Calculate SMAs
fastSMA = ta.sma(close, fastLen)
slowSMA = ta.sma(close, slowLen)
// Plot SMAs
plot(fastSMA, title="Fast SMA", color=color.orange, linewidth=2)
plot(slowSMA, title="Slow SMA", color=color.blue, linewidth=2)
// Signals (use bar close confirmation to avoid intrabar repaint)
bullCross = ta.crossover(fastSMA, slowSMA) and barstate.isconfirmed // 5 SMA closes ABOVE 20 SMA
bearCross = ta.crossunder(fastSMA, slowSMA) and barstate.isconfirmed // 5 SMA closes BELOW 20 SMA
// Label both as "TRADE SIGNAL"
plotshape(bullCross, title="TRADE SIGNAL (5 > 20)", style=shape.labelup, location=location.belowbar,
text="TRADE SIGNAL", color=color.new(color.green, 0), textcolor=color.white, size=size.tiny)
plotshape(bearCross, title="TRADE SIGNAL (5 < 20)", style=shape.labeldown, location=location.abovebar,
text="TRADE SIGNAL", color=color.new(color.red, 0), textcolor=color.white, size=size.tiny)
// Optional alerts for automation/webhooks
alertcondition(bullCross, title="5 SMA crossed ABOVE 20 SMA",
message="TRADE SIGNAL: 5 SMA crossed ABOVE 20 SMA on {{ticker}} @ {{close}}")
alertcondition(bearCross, title="5 SMA crossed BELOW 20 SMA",
message="TRADE SIGNAL: 5 SMA crossed BELOW 20 SMA on {{ticker}} @ {{close}}")
indicator("5/20 SMA Trade Signal", overlay=true)
// Inputs (editable if you want to tweak later)
fastLen = input.int(5, "Fast SMA (default 5)", minval=1)
slowLen = input.int(20, "Slow SMA (default 20)", minval=1)
// Calculate SMAs
fastSMA = ta.sma(close, fastLen)
slowSMA = ta.sma(close, slowLen)
// Plot SMAs
plot(fastSMA, title="Fast SMA", color=color.orange, linewidth=2)
plot(slowSMA, title="Slow SMA", color=color.blue, linewidth=2)
// Signals (use bar close confirmation to avoid intrabar repaint)
bullCross = ta.crossover(fastSMA, slowSMA) and barstate.isconfirmed // 5 SMA closes ABOVE 20 SMA
bearCross = ta.crossunder(fastSMA, slowSMA) and barstate.isconfirmed // 5 SMA closes BELOW 20 SMA
// Label both as "TRADE SIGNAL"
plotshape(bullCross, title="TRADE SIGNAL (5 > 20)", style=shape.labelup, location=location.belowbar,
text="TRADE SIGNAL", color=color.new(color.green, 0), textcolor=color.white, size=size.tiny)
plotshape(bearCross, title="TRADE SIGNAL (5 < 20)", style=shape.labeldown, location=location.abovebar,
text="TRADE SIGNAL", color=color.new(color.red, 0), textcolor=color.white, size=size.tiny)
// Optional alerts for automation/webhooks
alertcondition(bullCross, title="5 SMA crossed ABOVE 20 SMA",
message="TRADE SIGNAL: 5 SMA crossed ABOVE 20 SMA on {{ticker}} @ {{close}}")
alertcondition(bearCross, title="5 SMA crossed BELOW 20 SMA",
message="TRADE SIGNAL: 5 SMA crossed BELOW 20 SMA on {{ticker}} @ {{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.