ta icon indicating copy to clipboard operation
ta copied to clipboard

volume_price_trend is completly wrong

Open Groni3000 opened this issue 2 years ago • 0 comments

Wiki link you provided: https://en.wikipedia.org/wiki/Volume%E2%80%93price_trend It tells: VPT is based on a running cumulative volume that adds or subtracts ...

Another link: https://www.barchart.com/education/technical-indicators/price_volume_trend It tells: Add to yesterday's cumulative total: Percentage Change * Volume [today] + PVT [yesterday]

I used TradingView indicator: Price Volume Trend by [everget] (https://ru.tradingview.com/u/everget/) Окт 29, 2018 And it tells me the same...

So the formula should be vpt = (closes.pct_change().dropna() * volume.iloc[1:]).cumsum() if you use pandas or np_closes, np_volume = closes.to_numpy(), volume.to_numpy() np_vpt = np.cumsum((np_closes[1:]/np_closes[:-1] - 1) * np_volume[1:]) if you use numpy

But Tradingview version uses rolling SMA smoothing factor with 21 window by default like this: tradingview_vpt = (closes.pct_change().dropna() * volume.iloc[1:]).cumsum().rolling(21).mean() or IF YOU WANT - exponentially weighted with span like this: tradingview_vpt = (closes.pct_change().dropna() * volume.iloc[1:]).cumsum().ewm(span=21, adjust=False).mean()

Check it please. Am I wrong or misunderstood?

Groni3000 avatar Jun 29 '22 15:06 Groni3000