VWAP calculation doesn't match other platforms
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 (!!)
profile picture

KGo

#12
The current VWAP indicator is using the prior day VWAP closing value for intraday bar zero. Then the summation calc is beginning with the second intraday bar. Consider commenting out these lines to use the full day of trade data:
CODE:
Please log in to see this code.

profile picture

Eugene

#13
This check is required to avoid a runtime error (index out of bounds) on the first bar of data.
profile picture

KGo

#14
When the else statement is removed the check is not needed. Bar zero and intraday bar zero calculate like any other bar with result of average price since volume cancels out in the calculation.

There could be an issue if volume on any bar is misrepresented as zero but that's not addressed in the original or with this suggestion.

profile picture

Eugene

#15
Indeed, now this makes good sense. After applying the fix I see how the value on the first bar correctly aligns with the price dynamics rather than copying the prior bar's value.

Kevin, I appreciate you taking the effort to submit the fix! We'll factor it in C.Indicators v2018.05. Thanks.
profile picture

KGo

#16
You're welcome.
profile picture

gchudublin

#17
I download community indicator and loaded VWAP, but it has only one line, but if I use TD Ameritrade, their ThinkOrSwim has -2, 2.0 parameters, so it actually draw 3 lines(see attached picture). do you have any idea how to make the community indicator same as the ThinkOrSwim?
profile picture

Eugene

#18
I have no idea what these lines or parameters are on the 3rd party platform. For "our" version please read this thread from the start and refer to the online user guide:

VWAP (Volume Weighted Average Price)
profile picture

Eugene

#19
To all VWAP users out there.

Community Indicators v2018.05 has been released with KGo's fix for VWAP indicator's potentially incorrect value on intraday bar #0.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).