OPEN-SOURCE SCRIPT

5/20 SMA Trade Signal

53
//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}}")

免責聲明

這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。