本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator(title = 'MACD-V (Volatility Normalized MACD)', shorttitle = 'MACD-V', overlay = false)
// Inputs
fastLength = input.int(12, title = 'Fast Length')
slowLength = input.int(26, title = 'Slow Length')
signalLength = input.int(9, title = 'Signal Length')
atrLength = input.int(26, title = 'ATR Length')
src = input.source(close, title = 'Source')
// Calculations
fastEMA = ta.ema(src, fastLength)
slowEMA = ta.ema(src, slowLength)
macdLine = fastEMA - slowEMA
atrValue = ta.atr(atrLength)
float macdV = macdLine / atrValue * 100
float Signal = ta.ema(macdV, signalLength)
// Plots
plot(macdV, title = 'MACD-V', color = color.new(#2962FF, 0), linewidth = 2)
plot(Signal, title = 'Signal', color = color.new(#ff299b, 0), linewidth = 2)
hline(150, 'Extreme Overbought', color = color.red, linestyle = hline.style_dashed)
hline(50, 'Strong Momentum Up', color = color.green, linestyle = hline.style_dotted)
hline(0, 'Zero Line', color = color.gray)
hline(-50, 'Strong Momentum Down', color = color.orange, linestyle = hline.style_dotted)
hline(-150, 'Extreme Oversold', color = color.red, linestyle = hline.style_dashed)
// Optional: Histogram (difference from a short signal, or raw acceleration)
float hist = macdV - Signal
// color
color hColor = hist >= 0 ? hist > hist[1] ? #26a69a : #b2dfdb : hist > hist[1] ? #ffcdd2 : #ff5252
plot(hist, "Histogram",color = hColor, style = plot.style_columns)
hline(0, "Zero", #787b8680)
// Create alert conditions.
alertcondition(hist[1] >= 0 and hist < 0, "Rising to falling", "MACD Volatility histogram switched from a rising to falling state")
alertcondition(hist[1] <= 0 and hist > 0, "Falling to rising", "MACD Volatility histogram switched from a falling to rising state")