mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-07-27 17:27:43 +00:00
35a6702b06
Deep review of all indicator categories verified .md headers against .cs WarmupPeriod, parameters, inputs, and outputs. Fixes include warmup corrections, parameter documentation, output type accuracy, and Pine Script alignment.
45 lines
1.7 KiB
Plaintext
45 lines
1.7 KiB
Plaintext
// Licensed under the Apache License, Version 2.0
|
|
// © 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) =>
|
|
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)
|