Script

Script

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

// Input settings
fastLength = input.int(9, title="Fast SMA Length", minval=1)
slowLength = input.int(21, title="Slow SMA Length", minval=1)

// Calculate moving averages
fastSMA = ta.sma(close, fastLength)
slowSMA = ta.sma(close, slowLength)

// Plot the moving averages
plot(fastSMA, color=color.blue, linewidth=2, title="Fast SMA")
plot(slowSMA, color=color.orange, linewidth=2, title="Slow SMA")

// Plot buy/sell signals
longSignal = ta.crossover(fastSMA, slowSMA)
shortSignal = ta.crossunder(fastSMA, slowSMA)

plotshape(longSignal, style=shape.labelup, location=location.belowbar, color=color.green, size=size.small, text="BUY")
plotshape(shortSignal, style=shape.labeldown, location=location.abovebar, color=color.red, size=size.small, text="SELL")

Read More

Share:

Latest News