本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © SMRTAlgo
//@version=6
indicator("Volume Momentum Index [SMRT Algo]", shorttitle="Volume Momentum Index [SMRT Algo]", overlay=false)
momentumLength = input.int(14, "Momentum Length", minval=1)
smoothingLength = input.int(5, "Base Smoothing Length", minval=1)
vmiSmoothLength = input.int(5, "VMI Smooth Length", minval=1)
signalLength = input.int(9, "Signal Length", minval=1)
volumeInfluence = input.float(0.75, "Volume Influence", minval=0.0, step=0.05)
normalizationLength = input.int(50, "Normalization Length", minval=10)
overboughtLevel = input.float(60.0, "Overbought Level")
upperLevel = input.float(30.0, "Upper Level")
lowerLevel = input.float(-30.0, "Lower Level")
oversoldLevel = input.float(-60.0, "Oversold Level")
Green = input.color(color.new(#0df1c6, 0), "Colors ",inline = '1', group = 'Art',display = display.none)
Red = input.color(color.new(#e91e63, 0), "",inline = '1', group = 'Art',display = display.none)
Range = input.color(color.new(color.gray, 0), "",inline = '1', group = 'Art',display = display.none)
priceChange = close - close[momentumLength]
priceNormalization = ta.ema(math.abs(priceChange), momentumLength)
priceMomentum = priceChange / math.max(priceNormalization, 0.0000001)
averageVolume = ta.ema(volume, momentumLength)
volumeRatio = volume / math.max(averageVolume, 0.0000001)
priceDirection = close > close[1] ? 1.0 : close < close[1] ? -1.0 : 0.0
volumePressure = priceDirection * volumeRatio
// Bounded volume pressure
boundedVolumePressure = volumePressure / (1.0 + math.abs(volumePressure))
volumeAdjustment = 1.0 + (volumeInfluence * boundedVolumePressure)
rawVMI = priceMomentum * volumeAdjustment
vmiRaw = ta.ema(rawVMI, smoothingLength)
highestVMI = ta.highest(math.abs(vmiRaw), normalizationLength)
vmiNormalized = 100.0 * vmiRaw / math.max(highestVMI, 0.0000001)
vmiFirstSmooth = ta.ema(vmiNormalized, vmiSmoothLength)
vmi = ta.ema(vmiFirstSmooth, vmiSmoothLength)
signal = ta.ema(vmi, signalLength)
histogram = vmi - signal
h1 = hline(overboughtLevel, "Overbought", color=Red, linestyle=hline.style_solid)
h2 = hline(overboughtLevel+5, "Overbought", color=Red, linestyle=hline.style_solid)
fill(h1,h2,color = color.new(Red,80))
hline(upperLevel, "Upper Level", color=color.new(color.gray, 50), linestyle=hline.style_dotted)
hline(0, "Zero", color=color.gray, linestyle=hline.style_dotted)
hline(lowerLevel, "Lower Level", color=color.new(color.gray, 50), linestyle=hline.style_dotted)
l1 = hline(oversoldLevel, "Oversold", color=Green, linestyle=hline.style_solid)
l2 = hline(oversoldLevel-5, "Oversold", color=Green, linestyle=hline.style_solid)
fill(l1,l2,color = color.new(Green,80))
vp = plot(vmi, title="Volume Momentum Index", color=vmi >= 0 ? Green : Red, linewidth=2,display = display.none)
plot(vmi, title="Volume Momentum Index", color=vmi >= 0 ? Green : Red, linewidth=2,display = display.none)
vs = plot(signal, title="VMI Signal", color=color.orange, linewidth=2,display = display.none)
plot(signal, title="VMI Signal", color=color.orange, linewidth=2,display = display.none)
//fill(vp,vs,color = color.new(Green,90))
base = (vmi+signal)/2
TrendThreshold = 1.5
atrBase = ta.atr(14)
tilt = (base - base[1]) / (0.1 * atrBase)
Up = tilt < TrendThreshold * -1
Down = tilt > TrendThreshold
Flat = not Up and not Down
plot((vmi+signal)/2,color=Up?Green:Down?Red:Range,linewidth = 3, style=plot.style_circles)
plot((vmi+signal)/2,color=Up?Green:Down?Red:Range)
//plot(histogram, title="VMI Histogram", style=plot.style_columns, color=histogram >= 0 ? color.new(Green, 25) : color.new(Red, 25))
//fill(plot(0), plot(histogram), top_value, bottom_value, top_color, bottom_color, title, display, fillgaps, editable) → void
histogramPlot = plot(histogram, title="VMI Histogram", color = color.new(histogram>0?Green:Red, 90),style = plot.style_columns)
zeroPlot = plot(0, title="Histogram Zero", display=display.none)
fill(histogramPlot, zeroPlot, histogram, 0, color.new(chart.bg_color, 0), color.new(histogram>0?Green:Red, 25))
bullishReversal = ta.crossover(vmi, signal) and vmi < oversoldLevel and signal < oversoldLevel
bearishReversal = ta.crossunder(vmi, signal) and vmi > overboughtLevel and signal > overboughtLevel
plotshape(bullishReversal ? vmi : na, title="", style=shape.triangleup, location=location.bottom, color=Green, text="", textcolor=color.white, size=size.tiny)
plotshape(bearishReversal ? vmi : na, title="", style=shape.triangledown, location=location.top, color=Red, text="", textcolor=color.white, size=size.tiny)
alertcondition(bullishReversal, title="Bullish VMI Reversal", message="VMI Bullish Reversal detected")
alertcondition(bearishReversal, title="Bearish VMI Reversal", message="VMI Bearish Reversal detected")