VWAP calculation question
Author: jedediah
Creation Date: 3/29/2012 1:41 PM
profile picture

jedediah

#1
When I plot VWAP from the Community.Indicators on an intraday chart, I get a value that does not match (does not even come close to matching) the indicator value from other platforms. It seems like the VWAP is being calculated using daily bars. Is there anyway to have the VWAP use intraday bars for its calculation? I've tried searching the forums and the wiki for an answer...no luck. Thanks.
profile picture

Eugene

#2
I'd say then our version is an approximation. Not every user has access to intraday data (Wealth-Lab Developer does not come with an intraday data feed out of the box). Our VWAP actually uses Daily data (native chart scale to be precise). It follows the Investopedia definition and was documented in the Wiki more than 4 years ago.

The code is open source for any interested parties to modify it to account for all intraday transaction data for the precise VWAP calculation. It's Community Indicators, so everyone's welcome.
profile picture

jedediah

#3
Thanks Eugene for you reply. I was just wondering if there was an easy way to configure the VWAP to us intraday data...I experimented with using SetScaleCompressed and this did not work (obviously). I am just beginning to climb the programming learning curve and I appreciate your help. I opened up the community indicators src and will try to modify it...I will probably have more questions, though. Thanks, again.
profile picture

Eugene

#4
Where are you going to take each individual trade that takes place over the defined period of time? (Wikipedia: VWAP). There's no tick data in Wealth-Lab Pro.
profile picture

jedediah

#5
I plan to use 1 minute data since I do not have access to a smaller time frame in Wealth-Lab Pro. This should be a fairly close approximation of the VWAP calculated from tick values (at least by noon when I start using VWAP for counter-trend trades). Thoughts?
profile picture

jedediah

#6
O.K., I took you suggestion Eugene. I really did not know how to write and recompile the formal VWAP indicator, so I used the code to write an informal indicator in the DataSeries format. Good news is that it gives the correct values for intraday VWAP. Bad news is that it takes forever to calculate on larger data sets (I have 8GB ram and an i7...but my resources aren't taxed, so I don't know why the calcs take so long). Also, it plots the zero values and this messes up the y-axis scaling. Here's the code:

CODE:
Please log in to see this code.


I set my initial bar variable to Bars.Count - 1500 to truncate the calculations so the program doesn't freeze, but I would like to place this indicator on a year's worth of data without causing any problems. Any suggestions on how to get it to calculate more quickly? Also, is there any way to avoid plotting the indicator's zero values? Thanks, in advance, for your help.
profile picture

Eugene

#7
The zeroes are easy to fix:
CODE:
Please log in to see this code.


A cached version (formal indicator) works sufficiently fast. For example, on my PC it's done in less than 4 seconds on a chart of 1-minute Crude Oil with 1.8 million bars (+CL#).

Thanks for the heads-up and code. I'll replace the old VWAP with this intraday-only code in Community Indicators.
profile picture

jedediah

#8
Thanks Eugene! I had tried to solve the zero problem, but I kept getting errors. Your code works perfect. Incidentally, this also solved the problem with the calculation time. I pulled this up on a year's worth of 1-minute data without a problem. Thanks, again.

a.j.
profile picture

chrishar00

#9
Hi there - Has this intraday VWAP code been added to the community indicators pack yet?
profile picture

Eugene

#10
Here's a little quest: check out the extension's change log.
profile picture

chrishar00

#11
Perfect, thanks Eugene. I tried the indicator and it didn't look right, so I thought it had not been incorporated yet. Then I noticed that I wasn't streaming charts and I was a few days off on the data comparison - user error (!!)