本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=5
indicator("Death Cross and Golden Cross Highlighter", overlay=true)
// Define input parameters for moving averages
shortLength = input.int(50, title="Short Moving Average Length")
longLength = input.int(200, title="Long Moving Average Length")
// Calculate the moving averages
shortMA = ta.sma(close, shortLength)
longMA = ta.sma(close, longLength)
// Plot the moving averages
plot(shortMA, color=color.blue, title="Short MA")
plot(longMA, color=color.red, title="Long MA")
// Identify Golden Cross and Death Cross conditions
goldenCross = ta.crossover(shortMA, longMA)
deathCross = ta.crossunder(shortMA, longMA)
// Plot shapes on the chart to highlight the crossovers
plotshape(series=goldenCross, location=location.belowbar, color=color.green, style=shape.labelup, text="Golden Cross")
plotshape(series=deathCross, location=location.abovebar, color=color.red, style=shape.labeldown, text="Death Cross")
// Background color for the cross periods
bgcolor(color=goldenCross ? color.new(color.green, 90) : na)
bgcolor(color=deathCross ? color.new(color.red, 90) : na)