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

开源脚本

本着真正的TradingView精神,此脚本的作者已将其开源,以便交易者可以理解和验证它。向作者致敬!您可以免费使用它,但在出版物中重复使用此代码受网站规则约束。 您可以收藏它以在图表上使用。

想在图表上使用此脚本?

免责声明