Files
QuanTAlib/lib/volume/vwad/vwad.pine
T
Miha Kralj 24e86d762a Add documentation links for various volatility indicators and channels
- Updated BBWN, BBWP, CCV, CV, CVI, EWMA, GKV, HLV, HV, Jvolty, JVOLTYN, MASSI, NATR, RSV, RV, RVI, TR, UI, VOV, VR, YZV indicators with documentation links.
- Added documentation links for Aberration, Acceleration Bands, Andrews' Pitchfork, Adaptive Price Zone, ATR Bands, Bollinger Bands, Center of Gravity, Donchian Channels, Decay Min-Max Channel, Detrended Synthetic Price, EACP, EBSW, HOMOD, Jurik Volatility Bands, Keltner Channel, MA Envelope, Min-Max Channel, Price Channel, Regression Channels, Standard Deviation Channel, Stoller Average Range Channel, Super Trend Bands, Ultimate Bands, Ultimate Channel, VWAP Bands, and VWAP with Standard Deviation Bands.
2026-02-18 11:55:48 -08:00

47 lines
1.7 KiB
Plaintext

// The MIT License (MIT)
// © mihakralj
//@version=6
indicator("Volume Weighted Accumulation/Distribution (VWAD)", "VWAD", overlay=false)
//@function Calculates VWAD using volume weighting for enhanced sensitivity
//@param src_high High price series
//@param src_low Low price series
//@param src_close Close price series
//@param src_vol Volume series
//@param period Lookback period for volume weighting
//@returns VWAD value representing volume-weighted accumulation/distribution
//@optimized for performance and dirty data
vwad(simple int period, series float src_high = high, series float src_low = low, series float src_close = close, series float src_vol = volume) =>
if period <= 0
runtime.error("Period must be greater than 0")
var int p = math.max(1, period), var int head = 0
var array<float> vol_buffer = array.new_float(p, na)
var float sum_vol = 0.0
float old_vol = array.get(vol_buffer, head)
if not na(old_vol)
sum_vol -= old_vol
float current_vol = nz(src_vol, 0.0)
sum_vol += current_vol
array.set(vol_buffer, head, current_vol)
head := (head + 1) % p
float mfm = 0.0
if not na(src_high) and not na(src_low) and not na(src_close)
mfm := (src_close - src_low) - (src_high - src_close)
mfm := src_high != src_low ? mfm / (src_high - src_low) : 0.0
float vol_weight = sum_vol > 0.0 ? current_vol / sum_vol : 0.0
float weighted_mfv = current_vol * mfm * vol_weight
var float cumulative_vwad = 0.0
cumulative_vwad += weighted_mfv
cumulative_vwad
// ---------- Main loop ----------
// Inputs
i_period = input.int(20, "Volume Weight Period", minval=1)
// Calculation
vwad_value = vwad(i_period)
// Plot
plot(vwad_value, "VWAD", color=color.yellow, linewidth=2)