本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("THF Crossover and Trend Signals Golden & Death Cross with Volume", overlay=true)
// Define periods for EMA and SMA
emaLength21 = input(21, title="EMA Length 21")
emaLength50 = input(50, title="EMA Length 50")
smaLength50 = input(50, title="SMA Length 50")
smaLength200 = input(200, title="SMA Length 200")
// Calculate EMA and SMA 50 and 200
emaValue21 = ta.ema(close, emaLength21)
emaValue50 = ta.ema(close, emaLength50)
smaValue50 = ta.sma(close, smaLength50)
smaValue200 = ta.sma(close, smaLength200)
// Plot the lines on the chart
plot(emaValue21, color=color.green, linewidth=2, title="EMA 21")
plot(emaValue50, color=color.yellow, linewidth=2, title="EMA 50")
plot(smaValue50, color=color.red, linewidth=2, title="SMA 50")
plot(smaValue200, color=color.blue, linewidth=2, title="SMA 200")
// Buy and sell signals
buySignal = ta.crossover(emaValue21, smaValue50)
sellSignal = ta.crossunder(emaValue21, smaValue50)
// Plot buy and sell signals with larger, more prominent text (simulating bold)
plotshape(series=buySignal, location=location.belowbar, color=color.green, style=shape.labelup, title="Buy Signal", text="BUY", textcolor=color.white, size=size.large)
plotshape(series=sellSignal, location=location.abovebar, color=color.red, style=shape.labeldown, title="Sell Signal", text="SELL", textcolor=color.white, size=size.large)
// Golden Cross and Death Cross signals
goldenCross = ta.crossover(emaValue50, smaValue200)
deathCross = ta.crossunder(emaValue50, smaValue200)
plotshape(series=goldenCross, location=location.belowbar, color=color.yellow, style=shape.labelup, title="Golden Cross", text="GOLDEN CROSS", textcolor=color.black, size=size.large)
plotshape(series=deathCross, location=location.abovebar, color=color.blue, style=shape.labeldown, title="Death Cross", text="DEATH CROSS", textcolor=color.white, size=size.large)
// Volume Moving Average
volumeMA = input(20, title="Volume Moving Average Period")
volumeSMA = ta.sma(volume, volumeMA)
plot(volumeSMA, color=color.orange, linewidth=2, title="Volume Moving Average")
// Color volume bars based on comparison with moving average
volumeColor = volume > volumeSMA ? color.green : color.red
plot(volume, color=volumeColor, style=plot.style_columns, title="Volume")