OPEN-SOURCE SCRIPT

DK: SMA Crossover BY

//version=5
indicator("SMA Crossover", overlay=true)

// Input parameters for short-term and long-term SMAs
shortLength = input.int(9, title="Short SMA Length", minval=1)
longLength = input.int(21, title="Long SMA Length", minval=1)

// Calculate the short-term and long-term SMAs
shortSMA = ta.sma(close, shortLength)
longSMA = ta.sma(close, longLength)

// Plot the SMAs on the chart
plot(shortSMA, color=color.blue, linewidth=2, title="Short SMA")
plot(longSMA, color=color.red, linewidth=2, title="Long SMA")

// Generate Buy and Sell signals
bullishCross = ta.crossover(shortSMA, longSMA)
bearishCross = ta.crossunder(shortSMA, longSMA)

// Plot Buy and Sell signals on the chart
plotshape(bullishCross, color=color.green, style=shape.labelup, location=location.belowbar, title="Buy Signal", text="BUY")
plotshape(bearishCross, color=color.red, style=shape.labeldown, location=location.abovebar, title="Sell Signal", text="SELL")
Moving Averages

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in publication is governed by House rules. You can favorite it to use it on a chart.

Want to use this script on a chart?

Disclaimer