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}}")
开源脚本
本着TradingView的真正精神,此脚本的创建者将其开源,以便交易者可以查看和验证其功能。向作者致敬!虽然您可以免费使用它,但请记住,重新发布代码必须遵守我们的网站规则。
免责声明
这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。
开源脚本
本着TradingView的真正精神,此脚本的创建者将其开源,以便交易者可以查看和验证其功能。向作者致敬!虽然您可以免费使用它,但请记住,重新发布代码必须遵守我们的网站规则。
免责声明
这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。