Price Volume Divergence Oscillator (PVDO)

bazanga · study · 94 行 · 点赞 73 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=6
indicator("Price Volume Divergence Oscillator", shorttitle="PVDO", overlay=false)
 
// 1. Inputs
priceDeltaType = input.string("Signed High - Low", "Price Movement", options=["Close - Open", "Signed High - Low"])
normLength = input.int(11, "Normalization Length", minval=1)
maType = input.string("EMA", "PVDO MA Type", options=["SMA", "EMA", "HMA", "LMA", "RMA", "WMA", "VWMA", "TEMA"])
pvdoMaLength = input.int(121, "PVDO MA Length", minval=1)
signalMaType = input.string("EMA", "Signal MA Type", options=["SMA", "EMA", "HMA", "LMA", "RMA", "WMA", "VWMA", "TEMA"])
signalMaLength = input.int(44, "Signal MA Length", minval=1)
logisticBandwidth = input.float(121, "Logistic Bandwidth", minval=1)
storedLength = input.int(11, "Stored Imbalance Length", minval=1)
histLength = input.int(44, "Correction Histogram Smoothing", minval=1)
histScale = input.float(0.25, "Correction Histogram Scale", minval=0.01)
 
// 2. Pressure
candleRange = math.max(high - low, syminfo.mintick)
pressure = volume * (close - open) / candleRange
pressureScale = ta.sma(math.abs(pressure), normLength)
pressureNorm = na(pressureScale) ? na : pressureScale == 0.0 ? 0.0 : pressure / pressureScale
 
// 3. Price Movement
priceMove = priceDeltaType == "Close - Open" ? close - open : close > open ? high - low : close < open ? -(high - low) : 0.0
priceScale = ta.sma(math.abs(priceMove), normLength)
priceNorm = na(priceScale) ? na : priceScale == 0.0 ? 0.0 : priceMove / priceScale
 
// 4. Raw PVDO
pvdoRaw = -(priceNorm - pressureNorm) * math.abs(priceNorm)
 
// 5. Moving Average Functions
tema(src, len) =>
    ema1 = ta.ema(src, len)
    ema2 = ta.ema(ema1, len)
    ema3 = ta.ema(ema2, len)
    3 * ema1 - 3 * ema2 + ema3
 
ma(src, len, type) =>
    switch type
        "SMA" => ta.sma(src, len)
        "EMA" => ta.ema(src, len)
        "HMA" => ta.hma(src, len)
        "LMA" => ta.linreg(src, len, 0)
        "RMA" => ta.rma(src, len)
        "WMA" => ta.wma(src, len)
        "VWMA" => ta.vwma(src, len)
        "TEMA" => tema(src, len)
 
// 6. PVDO Moving Averages
pvdoMain = ma(pvdoRaw, pvdoMaLength, maType)
pvdoSignal = ma(pvdoMain, signalMaLength, signalMaType)
 
// 7. Logistic Adaptive Smoothing
mkr_logistic_weight(src, bandwidth) => 1.0 / (1.0 + math.exp(-math.abs(src) / bandwidth))
var float pvdoLogistic = na
var float signalLogistic = na
pvdoChange = pvdoMain - nz(pvdoLogistic, pvdoMain)
signalChange = pvdoSignal - nz(signalLogistic, pvdoSignal)
pvdoWeight = mkr_logistic_weight(pvdoChange, logisticBandwidth)
signalWeight = mkr_logistic_weight(signalChange, logisticBandwidth)
pvdoLogistic := na(pvdoLogistic[1]) ? pvdoMain : pvdoLogistic[1] + pvdoWeight * pvdoChange
signalLogistic := na(signalLogistic[1]) ? pvdoSignal : signalLogistic[1] + signalWeight * signalChange
 
// 8. Stored Imbalance
decay = (storedLength - 1.0) / storedLength
var float storedImbalance = na
storedImbalance := na(storedImbalance[1]) ? pvdoMain : storedImbalance[1] * decay + pvdoMain
 
// 9. Logistic Stored Imbalance
var float storedLogistic = na
storedChange = storedImbalance - nz(storedLogistic, storedImbalance)
storedWeight = mkr_logistic_weight(storedChange, logisticBandwidth)
storedLogistic := na(storedLogistic[1]) ? storedImbalance : storedLogistic[1] + storedWeight * storedChange
 
// 10. Correction Pressure Histogram
storedScale = ta.sma(math.abs(storedLogistic), storedLength)
storedValue = na(storedScale) ? na : storedScale == 0.0 ? 0.0 : storedLogistic / storedScale
storedNormalized = (math.exp(2 * storedValue) - 1) / (math.exp(2 * storedValue) + 1)
var float correctionPressureSmooth = na
correctionPressureEMA = ta.ema(storedNormalized, histLength)
correctionPressureSmooth := na(correctionPressureSmooth[1]) ? storedNormalized : correctionPressureEMA
correctionDisplay = correctionPressureSmooth * histScale
 
// 11. Histogram State
histRising = correctionDisplay > correctionDisplay[1]
histPositive = correctionDisplay >= 0
correctionColor = histPositive ? (histRising ? color.new(#4caf4f, 63) : color.new(#a4e8a6, 51)) : (histRising ? color.new(#ff9292, 49) : color.new(#f32323, 59))
zeroCross = ta.cross(correctionDisplay, 0)
 
// 12. Outputs
hline(0, "Zero Line", color=color.gray)
plotshape(zeroCross ? 0 : na, title="Correction Pressure Zero Cross", style=shape.circle, location=location.absolute, color=color.rgb(255, 245, 151), size=size.tiny)
plot(pvdoLogistic, title="PVDO Logistic Overlay", color=pvdoLogistic > pvdoLogistic[1] ? color.green : color.red, linewidth=2)
plot(signalLogistic, title="Signal Logistic Overlay", color=signalLogistic > signalLogistic[1] ? color.aqua : color.rgb(248, 174, 1), linewidth=2)
plot(correctionDisplay, title="Correction Pressure", style=plot.style_columns, color=correctionColor, linewidth=2)

← 返回列表