Jump to content

Welcome to the new Traders Laboratory! Please bear with us as we finish the migration over the next few days. If you find any issues, want to leave feedback, get in touch with us, or offer suggestions please post to the Support forum here.

  • Welcome Guests

    Welcome. You are currently viewing the forum as a guest which does not give you access to all the great features at Traders Laboratory such as interacting with members, access to all forums, downloading attachments, and eligibility to win free giveaways. Registration is fast, simple and absolutely free. Create a FREE Traders Laboratory account here.

dbntina

VWAP Indicator with 1SD and 2SD bands

Recommended Posts

thrunner, thanks for that info. I had not realized the start time changed things THAT much. I figured the pre market volume would be swamped after the open and not change things to much of a degree.

Blowfish, that is kind of what I figured as far as those two charts go. In some sense aren't some of these algorithms just updating too slow for how many times we see price under the 3rd std dev? I mean if getting under the 2nd band is a 98% move away from the mean, shouldnt price virtually never get under the 3rd band? Thats pretty much what investors r/t "proprietary" calculation does. Even if more accurate, maybe its less usefull as price then just rides down the band on a big move from what i've seen so far.

Share this post


Link to post
Share on other sites
format study -> scaling have you selected 'same as symbol'?
Thank you! It always pays to ask somebody who knows the program. :doh: This type of scaling (to symbol) is default in TS but MC defaults to 'screen', something most new users of MC probably don't know about. Attached please find the revised png with scaling to 'same as symbol'.

5aa70e3215d69_MCproperscalesymbol2008-01-10_085356.png.eb32c4354bfe14b06745eab0e2cc7185.png

Share this post


Link to post
Share on other sites

Below see VWAP indicators for ES H08 for JAN 10. ONe is from the build in vwap function in Ensign...the other is from the VWAP indicator posted here. You will notice that the Ensign one seems wrong as it has gone way past the 3rd std deviation. I am not 100% sure though...here they are and here are my settings. They all have their start time at 4:30 globex open on Jan9.

 

Does any match other peoples trading software?

 

Here is the TS code...(was posted on the TS forum)..

I modified the original to do (open+high+low+close)/4

-------------------------------------------------------------------

 

[LegacyColorValue = true];

 

{***********************************************************************************************

 

Coded by dbntina/boxmeister 8/2/2007

 

Used the VWAP_H code provided by Tradestation on 02/07/2003 Topic ID = 6735 Thanks Guys!

 

Added the computation for variance and the Standard Deviation to combine into one indicator

plot and this indicator plots the VWAP, SD1 bands, SD2 bands

 

-----------------------------------------------------------------------------------------------

 

Applicable now for Globex charts, made code a little bit faster, added SD3 band and formated.

Changings by swisstrader 08/14/2007

 

***********************************************************************************************}

 

 

vars: currSess(0),

currVol(0),

avPrice(0),

oneThird( Reciprocal(3) ),

PriceW(0),

VolumW(0),

barCount(0),

ii(0),

wgtVol(0),

diffPc(0),

sqrPrc(0),

indivVariance(0),

sumIndivVarnc(0),

VariancePop(0),

VolWAPValue(0),

VolWAPVariance(0),

VolWAPSD(0),

uppSD1(0),

lowSD1(0),

uppSD2(0),

lowSD2(0),

uppSD3(0),

lowSD3(0);

 

 

if BarType < 2 then

 

{Session change}

currSess = CurrentSession(0);

{used Volume}

currVol = Ticks;

{Price input series}

 

avPrice = (Open+High+Low+Close)/4;

 

{resets at SessionChange}

if currSess <> currSess[1] then begin

PriceW = 0;

VolumW = 0;

barCount = -1;

VolWAPValue = 0;

end;

 

PriceW = PriceW + currVol*avPrice;

VolumW = VolumW + currVol ;

barCount = barCount + 1;

if VolumW > 0 then

VolWAPValue = PriceW / VolumW;

 

{Calculate the individual variance terms for each intraday bar starting with the current

bar and looping back through each bar to the start bar. The terms are each normalized

according to the Variance formula for each level of volume at each price bar }

sumIndivVarnc = 0;

for ii = 0 to barCount begin

wgtVol = currVol[ii]/VolumW;

diffPc = avPrice[ii]-VolWAPValue;

sqrPrc = Square(diffPc);

indivVariance = wgtVol * sqrPrc;

sumIndivVarnc = sumIndivVarnc + indivVariance;

end;

 

{hand-over summary of individual variance and calculate StdDev}

VolWAPVariance = sumIndivVarnc;

VolWAPSD = SquareRoot(VolWAPVariance);

 

{calculation of StdDevBands}

uppSD1 = VolWAPValue + VolWAPSD;

lowSD1 = VolWAPValue - VolWAPSD;

uppSD2 = uppSD1 + VolWAPSD;

lowSD2 = lowSD1 - VolWAPSD;

uppSD3 = uppSD2 + VolWAPSD;

lowSD3 = lowSD2 - VolWAPSD;

 

{plot}

Plot1(VolWAPValue, "VWAP");

Plot2(uppSD1, "VWAP_SD1_Up");

Plot3(lowSD1, "VWAP_SD1_Dn");

Plot4(uppSD2, "VWAP_SD2_Up");

Plot5(lowSD2, "VWAP_SD2_Dn");

Plot6(uppSD3, "VWAP_SD3_Up");

Plot7(lowSD3, "VWAP_SD3_Dn");

vwap_ensign_settings_jan10.thumb.PNG.c4f0793452d9d6d9847c5f5432d70489.PNG

vwap_ensign_wrong_jan_10.thumb.PNG.0348cb796ee9872433d8ca10bf782132.PNG

vwap_ts_jan_10_correct.thumb.PNG.a06ad170fb1195f285c8806ac913b739.PNG

Share this post


Link to post
Share on other sites
ONe is from the build in vwap function in Ensign
As Darth and others may have pointed out, the Ensign VWAP looks wrong, perhaps you should ask Ensign for the code and/or a better explanation. I had previously looked at the code by Swisstrader that you posted above https://www.tradestation.com/Discussions/Topic.aspx?Topic_ID=66875 . The TS results looks right and is nearly identical to the dbtina VWAP code (OP here) if accounted for the start time (the change
avPrice = (High+Low+Close)*oneThird <--> avPrice = (Open+High+Low+Close)/4
makes little difference and is perhaps faster).

 

For what it is worth, the VWAP on Ninjatrader looks incorrect as well.

5aa70e32373d5_ntvwap2008-01-10_223759.jpg.2a9166d8fae846829d380e88390e6e46.jpg

Share this post


Link to post
Share on other sites

Just interested in how you guys know which VWAP is the 'right' reference here?

The VWAP forumla isn't that complex, so there shouldn't be that many variations.

For the ensign version being wrong, jerry sure gets a lot out of it don't you think?

 

As for the market having to stay within the 3rd standard dev because of a normal distributions assumes to be the case ... probably the markets aren't normally distributed all the time.

 

Let's assume that you have a narrow value area and suddenly price breaks out at the end of the day. The VWAP has averaged volume * price over the whole day so a few more bars make hardly any difference, it's easy for price to pull away from the VWAP on strong momentum.

Because of averaging volume * price, the VWAP will considerably lag behind price on a trend day, nothing new here.

 

StdDev formula.

 

Chebyshev's inequality entails that for (nearly) all random distributions, not just normal ones, we have the following weaker bounds:

At least 50% of the values are within 1.41 standard deviations from the mean.

At least 75% of the values are within 2 standard deviations from the mean.

At least 89% of the values are within 3 standard deviations from the mean.

At least 94% of the values are within 4 standard deviations from the mean.

At least 96% of the values are within 5 standard deviations from the mean.

At least 97% of the values are within 6 standard deviations from the mean.

At least 98% of the values are within 7 standard deviations from the mean.

Edited by Sparrow

Share this post


Link to post
Share on other sites
Just interested in how you guys know which VWAP is the 'right' reference here?
You are correct in saying we don't know what is 'right'. We also don't know Jerry's Ensign setup parameters and lj2500 could have set it up incorrectly in his Ensign studies. I should have pointed out to LJ that the Ensign study for VWAP is here, although I have never used Ensign: http://ensign.editme.com/vwap

In that URL, the VWAP looks 'correct' in the observation that the SD lines are expanding in a root mean square relationship to the VWAP line (much as a Bollinger bands being 2SD away from a MA of price). That is they are not a fixed width linear channels away from the VWAP. Here is the picture from Ensign:

 

vwap-1.png

Share this post


Link to post
Share on other sites

My suspission is that the TS version doesn't use the real average in the SD calculation, however I haven't invested a lot of time in understanding the code.

PriceW = PriceW + currVol*avPrice;

VolumW = VolumW + currVol ;

VolWAPValue = PriceW / VolumW;

.

.

.

diffPc = avPrice[ii]-VolWAPValue;

 

e.g. avg of 9/5 + 5/3 not equal 14/8;

 

My NT version SDs look very narrow compared to the others, although the 1st SD has held up price very well ... most likely a bug somewhere.

Edited by Sparrow

Share this post


Link to post
Share on other sites

The VWAP has a very long memory because it hasn't got a period, that's why it takes a whole lot to change the width of the SDs after some time.

Ensign doesn't look so different from the NT version, problem is that if one SD is off the error gets multiplied with each next SD. Small differences can have a huge impact.

 

Therefore it would be interesting to know if the VWAP has been setup equally in all charts. The only parameter is start time, so nothing much to choose from.

Just trying eliminate one source of error here.

 

Cheers

Share this post


Link to post
Share on other sites

I haven't tried the VWAP from the link trunner supplied (yet). That one is a design your own study. Ensign has added vwap as a standard study now, so there should no longer be a need to use the dyo. Although, I will try it over the weekend. I would have thought the ensign designers would have compared the two.

 

As for jperl's version. I have asked him he said there are minor differences between his version and the built in vwap study in ensign (I took this as he developed his own study by coding it himself). I don't know if his JAN 10 chart looks like mine. JPERL, if you are reading...do you mind making a comment?

 

It looks like we don't know what the "real" one should look like (I guess the institutional traders' version)...how are we going to figure this out? I guess we can compare all of ours together...can others post their vwap FOR JAN-10? With the start time being the globex open of 4:30pm on Jan9?

Share this post


Link to post
Share on other sites
I haven't tried the VWAP from the link trunner supplied (yet). That one is a design your own study. Ensign has added vwap as a standard study now, so there should no longer be a need to use the dyo. Although, I will try it over the weekend. I would have thought the ensign designers would have compared the two.

 

As for jperl's version. I have asked him he said there are minor differences between his version and the built in vwap study in ensign (I took this as he developed his own study by coding it himself). I don't know if his JAN 10 chart looks like mine. JPERL, if you are reading...do you mind making a comment?

 

It looks like we don't know what the "real" one should look like (I guess the institutional traders' version)...how are we going to figure this out? I guess we can compare all of ours together...can others post their vwap FOR JAN-10? With the start time being the globex open of 4:30pm on Jan9?

 

Can't comment at this time because I am out of town and won't be back until Jan. 15th. If someone reminds me, I will take a look at the data when I get back.

Share this post


Link to post
Share on other sites

I have had a chance to take a look at the Ensign internal plot for VWAP. To be clear, I do not use this code, but wrote my own using Ensigns ESPL language.

Here is what I found:

 

For VWAP, Ensigns computation and mine are dead nuts on. No difference.

For the SD of the VWAP, there appears to be minor differences between my code results and Ensigns for most charts that I have looked at, EXCEPT FOR ES DATA of JAN 10. The comparison is shown in the two charts below:

 

In the first 1 min chart for the time period from the 9:30 EST open to about 11:30, the SD's are very close.

HOWEVER, from about 11:30 on, there is considerable disagreement as shown in the second chart.

I do not know the source of this disagreement, but it appears to be related to the large increase in volume occurring after 11:30.

I have submitted this info to Howard Arrington to look at, but I have not heard back from him.

If any of you use ensign, you might wish to nudge him about this to get a response.

ESJan10_930.thumb.jpg.6d325c3355d52b43fecf2b3a98f8057c.jpg

ESJan10_1130.thumb.jpg.11dc4d3c22435dbbb13c552bc5d74170.jpg

Share this post


Link to post
Share on other sites

Thank you very much for the update and explanation, Jerry. Attached please find two plots of the same period in question, based on TS data and DBtina VWAP TS code, one with start time of 0930 and the other with start time of 0000 EST. The DBtina based code generated similar results to your ESPL study.

 

However, VWAP & SDs were about 1 point lowered with start time calculation at midnight most likely because of substantial volume prior to RTH (regular hrs).

5aa70e367b670_ESJan102008-01-26_144017.png.930e1123e82e55e9d767054d1d3694f7.png

5aa70e367f466_ESJan10starttime00002008-01-26_144429.png.87c428ccb72bdc8f7ab8a197d77bb7e5.png

Share this post


Link to post
Share on other sites

jperl, thank you for taking some time to give us your response and comparison of your vwap+sd and ensign's (confirming what I thought - that the ts vwap/sd code posted here and yours seems correct and ensign's seems off). I have also emailed ensign with the info that has been posted here, showing the discrepency between theirs and the posted vwap code. Maybe they will be able to shed some light on the differences.

Share this post


Link to post
Share on other sites

 

However, VWAP & SDs were about 1 point lowered with start time calculation at midnight most likely because of substantial volume prior to RTH (regular hrs).

 

Yes thrunner, if you start the VWAP computation prior to the regular open, you will see some differences. Usually these differences are small because the premarket volume is low.

Share this post


Link to post
Share on other sites

Hi Guys ,

First thanks Jerry for the great thread on Market Statistics . I just finished reading all 11 parts.Great Job !

I use Tradestation for my charting and i've tried to find an .eld for the PVP everywhere with no luck..

I know it has been coded by Dbntina but i see he only posted the VWAP with the SD bands.I read in his posts that he was gonna email it to whoever asked for it but he hasn't been around this board for a while now so i can't get a hold of him .If anyone else has it I would appreciate if you could post it

Thanks

Share this post


Link to post
Share on other sites

I was just wondering if any has done the code for PVP? If not, would one of the coding guru's on TL be willing to take that on for us? Thanks for all the work on the VWAP.

 

David

Share this post


Link to post
Share on other sites
I have had a chance to take a look at the Ensign internal plot for VWAP. To be clear, I do not use this code, but wrote my own using Ensigns ESPL language.

Here is what I found:

 

For VWAP, Ensigns computation and mine are dead nuts on. No difference.

For the SD of the VWAP, there appears to be minor differences between my code results and Ensigns for most charts that I have looked at, EXCEPT FOR ES DATA of JAN 10. The comparison is shown in the two charts below:

 

In the first 1 min chart for the time period from the 9:30 EST open to about 11:30, the SD's are very close.

HOWEVER, from about 11:30 on, there is considerable disagreement as shown in the second chart.

I do not know the source of this disagreement, but it appears to be related to the large increase in volume occurring after 11:30.

I have submitted this info to Howard Arrington to look at, but I have not heard back from him.

If any of you use ensign, you might wish to nudge him about this to get a response.

 

 

Jerry,

 

Here is the problem as I see it and currently a deadlock for me. I've posted on another thread but haven't had a response just yet.

 

Depending on how the source code for real time data is implemented for various feeds this might differ. IB feed is sampled data and continuously updates volume to catch up with the ticks. Same with OpenTick. The bottom line means the bands will differ drastically based on backfilled data (which should be total volume accounted for) vs data that was accumulated throughout the day (sampled ticks and their respective sizes). Additionally, since IB data is sampled, price bars may also differ in a backfill compared to what was accumulated live, but this would only have a minor impact on VWAP. As for SD, the volume change would have a drastic impact. Consider 2 numbers with the same average but with different highs and lows (same average, completely different SD).

At the moment I am stuck, it seems that OpenTick feed for YM (streaming) is accurate, but backfill mucks it all up.

Depending on implementation, IB feed can/cannot be good for accuracy. Do they use Volume updates as volume or is volume derived from and accumulated from every tick sent? If using volume updates then you have a situation where you have increased the weighting but have incorrectly attributed that weighting to the current bar! (remember a voume update means more volume but at what prices??)

 

This is my understanding so far....:crap:

Share this post


Link to post
Share on other sites
Jerry,

 

Here is the problem as I see it and currently a deadlock for me. I've posted on another thread but haven't had a response just yet.

 

Depending on how the source code for real time data is implemented for various feeds this might differ. IB feed is sampled data and continuously updates volume to catch up with the ticks. Same with OpenTick. The bottom line means the bands will differ drastically based on backfilled data (which should be total volume accounted for) vs data that was accumulated throughout the day (sampled ticks and their respective sizes). Additionally, since IB data is sampled, price bars may also differ in a backfill compared to what was accumulated live, but this would only have a minor impact on VWAP. As for SD, the volume change would have a drastic impact. Consider 2 numbers with the same average but with different highs and lows (same average, completely different SD).

At the moment I am stuck, it seems that OpenTick feed for YM (streaming) is accurate, but backfill mucks it all up.

Depending on implementation, IB feed can/cannot be good for accuracy. Do they use Volume updates as volume or is volume derived from and accumulated from every tick sent? If using volume updates then you have a situation where you have increased the weighting but have incorrectly attributed that weighting to the current bar! (remember a voume update means more volume but at what prices??)

 

This is my understanding so far....:crap:

 

You raise some interesting questions, with unfortunately no interesting answers. I think what is need here is some kind of comparison of various data feeds on the tick level to see how they compare. I have not looked into this so I can't provide any guidance.

Share this post


Link to post
Share on other sites
can any one help me to plot VWAP in amibroker?

 

This is VWAP with SDs and (last value of) PVP for AmiBroker which I programed some time ago. It doesn't plot volume distribution, because AmiBroker can plot it on itself since version 5.20. I don't know how fast PC do you have, but the PVP calculation is quite demanding. So if you can settle for VWAP and SDs only and use AmiBroker's daily Volume at Price Overlay to judge PVP by eye, you can erase the part of code starting with ///// PVP /////. The code will be much faster then.

Also please note that I use black background, so change colors in code if needed.

 

ND = Day() != Ref(Day(), -1);

///// VWAP and SDs /////

P = (H + L) / 2;
VWP = P * V;
BI = BarIndex();
BeginBI = ValueWhen(ND, BI);
BeginBI = BeginBI[barCount -1];
if(BeginBI < BarCount - 1)
{
InRange = BI >= BeginBI;
CumV = Cum(V * InRange);
CumVWP = Cum(VWP * InRange);
VWAP = CumVWP / CumV;
S = Cum(Ref(CumV, -1) * V * (P - Ref(VWAP, -1))^2 / CumV);
Variance = S / CumV;
SD = sqrt(Variance);
VWAP = IIf(InRange, VWAP, Null);
Plot(VWAP, "VWAP", colorYellow, styleNoTitle + styleNoRescale);
Plot(VWAP + SD, "+1SD", colorGreen, styleDashed + styleNoTitle + styleNoRescale);
Plot(VWAP - SD, "-1SD", colorRed, styleDashed + styleNoTitle + styleNoRescale);
Plot(VWAP + 2*SD, "+2SD", colorSeaGreen, styleDashed + styleNoTitle + styleNoRescale);
Plot(VWAP - 2*SD, "-2SD", colorOrange, styleDashed + styleNoTitle + styleNoRescale);
Plot(VWAP + 3*SD, "+3SD", colorPaleGreen, styleDashed + styleNoTitle + styleNoRescale);
Plot(VWAP - 3*SD, "-3SD", colorLightOrange, styleDashed + styleNoTitle + styleNoRescale);
}

///// PVP /////

BarSinceND = BarsSince(ND);
iStart = Max(BarCount - 1 - BarSinceND[barCount - 1], 0);
Top = HighestSince(ND, High);
Bot = LowestSince(ND, Low);
Range = Top - Bot;
BoxesInRange = Range / TickSize + 1;
VolUnit = Volume / ((High - Low) / TickSize + 1);
VUcount = 0;
MaxVUcount = 0;
PVP = Null;

if(iStart > 0)
{
for(i = iStart; i < BarCount; i++)
{
jShift = round((Bot[i - 1] - Low[i]) / TickSize);
if((BoxesInRange[i] < BarCount))
	{
	if(jShift > 0)
		{
		LastVUcount = VUcount;
		VUcount = 0;
		for(j = jShift; j < BoxesInRange[i]; j++)
			{
			VUCount[j] = LastVUCount[j - jShift];
			}
		}
	jStart = round((Low[i] - Bot[i]) / TickSize);
	jEnd = round((High[i] - Bot[i]) / TickSize);
	for(j = jStart; j <= jEnd; j++)
		{
		VUcount[j] = VUcount[j] + VolUnit[i];
		MaxVUcount = Max(MaxVUcount, VUcount[j]);
		}
	}
}
for(j = 0; j < BoxesInRange[barCount - 1]; j++)
{
if(MaxVUcount == VUcount[j])
	PVP = Bot[barCount - 1] + j * TickSize;
}
Plot(PVP, "PVP", colorTurquoise, styleDots + styleNoTitle + styleNoRescale);
}

Share this post


Link to post
Share on other sites

VWAP for esignal...You can get it here:

 

http://share.esignal.com/groupcontents.jsp?folder=Formulas-EFS2&groupid=10

 

look for AMVWAP2...(here it is attached)..you also need the amstudies function library found here:

http://share.esignal.com/groupcontents.jsp?folder=Formulas-Libraries&groupid=10

 

remember to copy the AMSTUDIES.efslib to

C:\Program Files\eSignal\FunctionLibrary\*

 

thats it.

amvwap.zip

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.