BjarkeSvane
Posts: 4
Joined: Wed Sep 15, 2021 8:39 am

VWAP with price and positive/negative volumes

Hi,

I'm currently trying to visualize some price+volume data and want to add a VWAP to the chart. Unfortunately it seems that the calculation is wrong - VWAP increases to above the maximum price used in the calculation, as you can see at 06:45 in the attached screenshot.

I suspect that this is because some of my volumes are negative, indicating either buy or sell. How do I adjust the indicator to correctly calculate a VWAP based on my data?
Screenshot 2021-09-15 104410.png
Screenshot 2021-09-15 104410.png (13.18 KiB) Viewed 681 times
Best regards,
Bjarke Svane
User avatar
sebastian.h
Posts: 1734
Joined: Fri Aug 07, 2020 7:08 am

Re: VWAP with price and positive/negative volumes

Hi,
Thank you for contacting us with your issue.

It's hard to say without seeing your code in a live demo.

Here are links that might help resolve your problem.
https://jsfiddle.net/gh/get/library/pur ... tors/vwap/
https://api.highcharts.com/highstock/series.vwap
https://stackoverflow.com/questions/536 ... t-day-data

Let me know how are you doing with this.
Best regards.
Sebastian Hajdus
Highcharts Developer
BjarkeSvane
Posts: 4
Joined: Wed Sep 15, 2021 8:39 am

Re: VWAP with price and positive/negative volumes

Hi,

Thanks for answering. I played around a bit and figured that I could make a hidden series with data=Math.abs(volumedata), and then use that for the VWAP calculation. It would probably be cleaner to make a custom indicator, but this method was very easy and seems to work.

Best regards,
Bjarke Svane
User avatar
sebastian.h
Posts: 1734
Joined: Fri Aug 07, 2020 7:08 am

Re: VWAP with price and positive/negative volumes

Hi Bjarke,
Thanks for the message.

Yes, the hidden series seems to be a good solution.

Best regards.
Sebastian Hajdus
Highcharts Developer

Return to “Highcharts Stock”