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.

jperl

Trading with Market Statistics. IV Standard Deviation

Recommended Posts

I'm adding band options to the VWAP indicator in Investor/RT. I'm planning on adding several options as to how the bands are computed (std dev of cl, variance, half days range, etc), but for now, I'm using the method dogpile explained a couple pages back. Dogpile, if you can, verify that these look correct.

 

Here is a 2-min chart of ES (8/23) using just the day session:

http://www.charthub.com/images/2007/08/24/VWAP.png

 

Here is a 2-min chart of ES (8/23) starting 90 minutes prior to day session:

http://www.charthub.com/images/2007/08/24/VWAP_2.png

 

Thanks

Share this post


Link to post
Share on other sites

For any Esignal users who might be interested, this custom study by Chris Kryza incorporates some of the elements that Jerry is using.

 

This is today's chart at approx 12:20pm Pacific Standard Time using 5 min candles

snapshot-77.png.11baf5bd1817e1177b4fcfd957f1f3c0.png

Share this post


Link to post
Share on other sites

BlowFish

They all look similar and "close enough" to me ... Trading is not exact science anyway. Pick the simplest one, especially if you want to run the indicator on all 4 indeces ( hint CPU load).

Share this post


Link to post
Share on other sites

Blowfish,

 

I did look at the post...the short answer is I really don't know which one is best. I am basically going off of what JPERL is saying as he came up with the idea and methodology.

 

I don't understand the reasons why a certain method of the four would be used over another or the mathematics behind which one is used and why. Then I am not sure about what amount of margin of error is significant. So I am not sure at all....sorry. :confused:

 

Didn't want you to think that I was ignoring your post...not much help sorry,

 

dbntina

Share this post


Link to post
Share on other sites
BlowFish

They all look similar and "close enough" to me ... Trading is not exact science anyway. Pick the simplest one, especially if you want to run the indicator on all 4 indeces ( hint CPU load).

 

Well I have joined a couple of maths forums..been chilling so haven't got round to asking about calculating variances using non iterative methods. The various methods I have coded are lightening fast (no loops). I think you could run dozens on tick charts with little problem.

 

BTW the blue set is the 'long hand' calculation and I think I prefer it. Maybe I am judging too harshly.

 

One thing I have noticed is the VWAP as presented by TS does not use the total series volume for wieghting??? it is along the lines of :-

 

(for bar n = 1 to z) where z is lastbar on chart

 

Vwap = Price(n) * Vol(n) / TotalVol(1-n)......so vol is summed from first bar to curent bar.

 

Should that not be

 

Price(n) * Vol(n) /TotalVol(1-z)........so total volume is summed from firstbar to the last bar??

 

So I am confused again the VWAP as presented by TS does not divide by the total volume of the series? Is this correct? Dosen't seem like it is.

 

Cheers,

Nick

Share this post


Link to post
Share on other sites

here is the code segment calculationg vwap.. Line 3 sums total volume, not just volume of the bar n

____________________

Volume_i = UpTicks+DownTicks;// volume for a bar "i"

Price_Volume = Price_Volume + (AvgPrice * Volume_i);// SUM ( Price_Volume ) + AvgPrice * Volume_i

Total_Volume = Total_Volume + Volume_i;// sum total volume

 

if Total_Volume > 0 then

vwap_value = Price_Volume / Total_Volume;

_____________________________

Share this post


Link to post
Share on other sites

Hi Nick,

 

posted a long reply yesterday and then couldn't submit it ! I thought I saved the txt file but can't find it. I think all the tradestation calculations for VWAP may be wrong. TS native, mine, Dbntina, and the code you submitted.

 

In your code line 3 does not sum total volume it sums volume up to bar N. Whenever a new bar comes in (with added volume) every single preceding bar needs re-calculating with the new total volume for the series. You need to do something like

 

for n = 1 to totalnumber of bars VolumeTotal= VolumTotal + Volume(n)

 

then you run the weighting.

 

for n = 1 to totalnumber of bars VWAP = close * Volume(n) /VolumeTotal

 

Basically you need to use the volume for the whole series (not just up to bar N) for the weighting. The same issue as with the SD.

 

I'm not sure if I am explaining myself well do you see what I am getting at?

 

If you are calculating the variance with total volume for the whole series should you not do the same for the VWAP itself?

 

Jerry sorry to bug you I wonder if you had any comment on this, a simple yes or no would be cool:cool:

 

Cheers,

Nick.

 

P.S. Apologies to all, I know I am being pedantic about this but its become a sort of challenge. having said that its not wrong to strive for 'truth' & 'accuracy'.

Share this post


Link to post
Share on other sites

HI Blowfish

Quick reply... I will look at the code again after market close. Should be easy to print the volume out for testing...

The way I read the code is:

1. Variable "Total_Volume" is set to zero at the beginning of the period ( standard TS code uses if date[0] <> date[1] then...

2. each bar you add bar volume to "Total_Volume" ( line 3 of the code I posted)

Share this post


Link to post
Share on other sites

 

In your code line 3 does not sum total volume it sums volume up to bar N. Whenever a new bar comes in (with added volume) every single preceding bar needs re-calculating with the new total volume for the series. You need to do something like

 

for n = 1 to totalnumber of bars VolumeTotal= VolumTotal + Volume(n)

 

then you run the weighting.

 

for n = 1 to totalnumber of bars VWAP = close * Volume(n) /VolumeTotal

 

Basically you need to use the volume for the whole series (not just up to bar N) for the weighting. The same issue as with the SD.

 

If you are calculating the variance with total volume for the whole series should you not do the same for the VWAP itself?

 

Yes, that is correct Nick. Every time you add a new bar, with new volume, you have to renormalize the VWAP computation to include this new volume. What that means is computing the VWAP terms beginning at the start time each time you add a new bar.

Share this post


Link to post
Share on other sites

I have a pic for you. Left side has 405 min bars with total volume showing at lower right corner in red (850,237). Second chart is 5 min with vwap modified to print Total_volume value at last bar( I used AtCommentrayBar( ) ). You can see it shows the same volume.

re code comments:

precondition at bar number n..

_______________________________________________________

"Price_Volume" has subtotal of all Price_i * Volume_i, where i is 1 - (n-1)... and

"Total_Volume" has subtotal of all Volume_i, where i is 1 - (n-1)...

__________________________________________________________

NOW the bar n happens and the code below is executed

 

Volume_i = UpTicks+DownTicks;// volume for a bar "i"

Price_Volume = Price_Volume + (AvgPrice * Volume_i);// SUM ( Price_Volume ) + AvgPrice * Volume_i

Total_Volume = Total_Volume + Volume_i;// sum total volume

 

if Total_Volume > 0 then

vwap_value = Price_Volume / Total_Volume;

 

I think code is correct..

How do u read ( understand)this code segment? I guess I am not sure if I understand your concern.

 

Note: Just noticed that I used 2 forms of ES on the pic... ESU07.D is the same as @ES.D ( TS symbol for continuous contract)

5aa70df75d092_VWAPVolume1.gif.0cae2f2f63f8b76adb06732ad44e679c.gif

Share this post


Link to post
Share on other sites

Hi Nick,

 

The concern is that the value used for total volume in all the algorithms is not the total volume for the whole series it is the volume for the series up to the bar you are processing.

 

As an example

 

Lets say you are processing bar 100.

 

Total Volume is now the old Total Volume + Volume(100) you now need to re process bars 1-99 with the new total volume!! As there is more volume in the whole 'universe' Bars 1-99 need re-weighting taking into accounting for this volume.

 

Lets use the annotation Volume(1 to 100) for the total volume for bars 1 to 100

 

WeightedPrice(n) = price * volume(n) / volume(1 to 100) NOT

 

WeightedPrice(n) = price * volume(n) / volume(1 to n)

 

Put another way the weights on all the previous bars change when the total volume changes (i.e. there is new tick). Of course you don't re-plot old bars but the weighting they contribute changes so you do need to re-calculate the series. (well strictly speaking you do).

 

Obviously this is computationally intensive and my hunch is most software doesn't bother. TS dosent. Actually I wonder if institutions that lean heavily on VWAP do? Thats a spooky thought... the 'inaccurate' line seems to be heavily leaned upon.

 

Cheers,

Nick.

 

P.S. the usual caveats apply - its not the line you trade its how you trade it. Yes its all a bit anal but there is a difference etc. etc.

Share this post


Link to post
Share on other sites

:) .. add to that computational error associated with new calculations and I would say ... nahh... this is good enough..

 

P.S. finally got your point. I would say that error is well withing the "noise" of the market.

Share this post


Link to post
Share on other sites

OK glad I finally put it clearly! On the plus side this has given me a far deeper knowledge of the tools. Personally I always like to have that. I think is all to do with 'constructing your reality'. Kind of building your beliefs from ground zero. I do wonder if that is why people don't have confidence in there tools - they don't spend enough time getting to really understand what they do and how they do it.

 

Ironically when you have done all that leg work its probably best forgoten when you actually trade!!

 

I also wonder if I allowed myself to get sidetracked by the subconscious demons trying to delay the final test (trading with real money). I have spent a good portion of the last week pursuing about half a dozen versions of this indicator.

 

Actually I think I should post them but still could do with writing a decent histogram module. I can see that taking a while to get right.

 

Cheers.

Share this post


Link to post
Share on other sites

Can somebody please advise me on this code.

I am a newbie to Easylanguage.

I am using this code on mullticharts

Comments appreciated

 

Naveen

 

 

vars: vwap(0),

pv(0),

Totalvolume(0),

Barfromstart(0),

Squareddeviations(0),

Probabilityweighteddeviations(0),

deviationsum(0),

standarddeviation(0);

If date > date[1]

then

begin

Barfromstart=0;

pv=AvgPrice*volume;

Totalvolume=volume;

vwap=pv/totalvolume;

end

else

begin

Barfromstart=Barfromstart[1]+1;

pv=pv[1] + AvgPrice*Volume;

Totalvolume=Totalvolume[1] + Volume;

vwap=pv/Totalvolume;

end;

deviationsum=0;

for value1= 0 to Barfromstart

begin

Squareddeviations=Square(vwap-avgprice[value1]);

Probabilityweighteddeviations=volume[value1]*Squareddeviations/Totalvolume;

deviationsum=deviationsum+Probabilityweighteddeviations;

end;

 

standarddeviation=SquareRoot(deviationsum);

plot1(vwap);

plot2(vwap+standarddeviation);

plot3(vwap+2*standarddeviation);

plot4(vwap-standarddeviation);

plot5(vwap-2*standarddeviation);

Share this post


Link to post
Share on other sites
Guest cooter
HI NAVEEVIa,

 

I tried your code and it looks fine (as far as I can tell). It does suffer from being pretty processor intensive though.

 

Cheers.

 

Looking at all the VWAP, SD and PVP code on this forum, can you help us determine which one is least processor intensive then, while still as accurate as possible?

Share this post


Link to post
Share on other sites

Hi Cooter,

 

To be honest my whole interest in the code side of things came from being slightly disappointed with the performance of traditional algorithms. All have noticeable delays when first applying and make my charts feel a little sluggish.

 

I have code that I believe is now accurate, actually more accurate as it avoids some rounding errors associated with continuously summing. (you then have to be careful with overflow errors, no sign of that but I guess I should try it on the Nikkei & forex to be sure). It also runs pretty darn fast instantaneous for all intents and purposes. There are no loops in it at all. I just havent got round to posting it for a couple of reasons-

 

a) I am still running it against various instruments conditions etc.

 

b) Still running it against other code to make sure it is consistent.

 

c) I have it in multicharts (which imports .ELD but wont export). Seems kind of naff to post it as a text file if I'm going to do it properly.

 

d) Hasn't been that much interest (yours was the first enquiry) so I guess people are reasonably satisfied with what's out there.

 

e) There is still something puzzling me with the VWAP and the algorithm that seems to be commonly used. No biggy but like a dog with a bone I am not ready to let go just yet.

 

Cheers,

Nick.

Share this post


Link to post
Share on other sites
Guest cooter
Hi Cooter,

 

To be honest my whole interest in the code side of things came from being slightly disappointed with the performance of traditional algorithms. All have noticeable delays when first applying and make my charts feel a little sluggish.

 

I have code that I believe is now accurate, actually more accurate as it avoids some rounding errors associated with continuously summing. (you then have to be careful with overflow errors, no sign of that but I guess I should try it on the Nikkei & forex to be sure). It also runs pretty darn fast instantaneous for all intents and purposes. There are no loops in it at all. I just havent got round to posting it for a couple of reasons-

 

a) I am still running it against various instruments conditions etc.

 

b) Still running it against other code to make sure it is consistent.

 

c) I have it in multicharts (which imports .ELD but wont export). Seems kind of naff to post it as a text file if I'm going to do it properly.

 

d) Hasn't been that much interest (yours was the first enquiry) so I guess people are reasonably satisfied with what's out there.

 

e) There is still something puzzling me with the VWAP and the algorithm that seems to be commonly used. No biggy but like a dog with a bone I am not ready to let go just yet.

 

Cheers,

Nick.

 

I'd like to test what you have in TS, when you're ready to share it.

 

How does Multicharts compare to TS, by the way?

Share this post


Link to post
Share on other sites

My relationship with MC is kind of love hate. It has great potential (which is like those school report cards ....could do better...)

 

The good - its a one of payment when I grandfathered in it was only a coule of hundred bucks. It compiles easy language and even supports there API for .DLL's. I have had no compatibility issues though some do (mainly with systems I think). Support is pretty good too. (Needs to be sometimes)!

 

The bad some basic things are poorly implemented or just feel un polished. There are numerous little irritating bugs and stuff that is a wee bit more serious (less and less). This in itself isn't so bad but it's taken a long long time to get round to fixing these things. Some of the things they think are 'acceptable' or just don't get are annoying in the extreme. For example there drawing tools are inconsistent in operation and just plain poor. There attitude is that no one ever made any money with drawing tools. Basic data handling and rasterisation (display) of charts have a couple of 'wrinkles'. For me these have to be rock solid before you add bells and whistles. Often they break stuff with new releases, fair enough caca happens, trouble is they often take a month or more to repair it again. Releases are very infrequent and 'hotfixes' almost non existent. Compared to Ensign for example they are streets apart.

 

They have just made there forums customers only, other wise I could point you at a couple of amusing threads.

 

I put an enormous amount of time and energy into MC for myself and providing feedback for them. I am loath to throw that all away. To be honest it is better now, even though it has been released for some months now I have seen more robust and polished software that is beta testing.

 

I think there are a couple of people using it here quite happily (brownsfan springs to mind). I do wonder if he is still as happy the Open Ecry imterface has broken for the last 3 weeks and I believe he was using OEC too. :(

 

Cheers.

Share this post


Link to post
Share on other sites
Guest cooter

They have just made there forums customers only, other wise I could point you at a couple of amusing threads.

 

Yeah, I'd like to read these, just to get a feel for whether they are serious about supporting their software. PM is OK if you don't want to clutter up this thread.

Thanks.

Share this post


Link to post
Share on other sites

Hi Jerry,

 

First I wanted to say thank you for the great series of threads. I recently had a chance to go over them and has been quite enlightening. If you dont mind, I would like to ask a few questions. I understand I am a little late in replying and if some of the questions have been asked before, my apologies and please feel free to ignore them.

 

I am seeing the tremendous advantage of your methodology for a discretionary trader like myself. This is because on top of reading the pulse of the market through auction theory, pattern recognition, volume, etc... your methodology adds further structure to my trading. Hence, I would like to really understand this technique as I understand I am unable to read further about this.

 

First, regarding the VWAP, PVP, and SD do you use the previous day value for these? For example, at the open what values do you use and when do you adjust the values for todays trading in real time?

 

Second, you mentioned to stay away from trading around the PVP as market indecision takes place. I have been using the POC as a potential support/resistance the entire time and found this concept quite interesting. Could you care to elaborate on this?

 

Third, when the skew is negative but price is trading above the WVAP, do you not fade a retracement back to the VWAP to SD1? Or would you wait to fade the SD1 above the VWAP and a target back to the VWAP?

 

Fourth, do you play the range between SD2 and SD3? Is any price movement extending beyond SD3 a fading opportunity? I have been using your concept to observe the Nikkei and have found price to break out of SD3 at times and never fall back.

 

Thanks Jerry.

Share this post


Link to post
Share on other sites
First I wanted to say thank you for the great series of threads. I recently had a chance to go over them and has been quite enlightening.

 

Your very welcome. I thank you for providing a forum where we can post videos. Without that, I would not have begun these threads

 

 

First, regarding the VWAP, PVP, and SD do you use the previous day value for these? For example, at the open what values do you use and when do you adjust the values for todays trading in real time?

 

The thread on position trading [thread=2423]Part X[/thread] describes how I use the previous days volume distribution to take a position trade near the open. Today's developing volume distribution is simply added onto yesterdays. Once the position trade is completed, I then switch to using todays volume distribution for further day trades.

 

 

Second, you mentioned to stay away from trading around the PVP as market indecision takes place. I have been using the POC as a potential support/resistance the entire time and found this concept quite interesting. Could you care to elaborate on this?

 

I pointed out in this thread that the PVP is a dividing point between a high volume trading zone and a low volume trading zone. Consider for example a distribution with a negative skew. Several things can happen around the PVP as follows:

a)Price can break out into the low volume zone above the 1st SD, in which case you want to go long or

b)Price can break back into the high volume zone below the VWAP in which case you want to go short or

c)Price action may simply oscillate between the 1st SD and the VWAP, in which case you might consider a short after a bounce off the 1st SD or a long after a bounce off the VWAP.

So at the PVP itself you have no idea of any expectation until one of the above 3 conditions occurs

Trading at the PVP thus becomes a slippery slope as I described in [thread=2232]Part VII [/thread].

 

Third, when the skew is negative but price is trading above the WVAP, do you not fade a retracement back to the VWAP to SD1? Or would you wait to fade the SD1 above the VWAP and a target back to the VWAP?

 

Not quite sure what you meant in the first part of this question. With a negative skew (VWAP<< PVP) and price action above the VWAP, wait for a breakout to occur above the 1st SD for a long trade. If that does not occur (if for example price bounces off the SD) then go short with the VWAP as the profit target. As I indicated above you might get oscillations in this region between SD and the VWAP.

Once the breakout occurs say above the SD, you would only consider long trades away from the VWAP. example a retace to the SD, go long, or if price action is above the 2nd SD, again go long on a retrace to the 2nd SD. Such trades should be viable as long as the skew is negative. Eventually however the skew will become zero as the breakout continues. It's at that point you would take a countertrend trade TOWARD the VWAP. This is described in the thread on counter trend trading [thread=2285]Part VIII[/thread]

 

Fourth, do you play the range between SD2 and SD3?

 

Above SD2, you are on your own. I usually don't take trades above SD2, mainly because continuation to SD3 is not that viable. And as I say that, you realize that in the last two months trades to the SD3 and beyond have become quite common.

 

Is any price movement extending beyond SD3 a fading opportunity? I have been using your concept to observe the Nikkei and have found price to break out of SD3 at times and never fall back.

 

Beyond SD3 is no mans land. When I see the market extend beyond SD3, I just shake my head in amazement, take a break and go have a cup of coffee.

Share this post


Link to post
Share on other sites

Thank you Jerry. Regarding the skew, a long position would be the option in a negative skew and a short for a positive skew? I think I may have these two definitions mixed up as I had though a negative skew with price action below VWAP would be a short and vice versa.

Share this post


Link to post
Share on other sites
Thank you Jerry. Regarding the skew, a long position would be the option in a negative skew and a short for a positive skew? I think I may have these two definitions mixed up as I had though a negative skew with price action below VWAP would be a short and vice versa.

Your initial thought was correct

The sign of the skew tells you where most of the trading has taken place. Positive skew: Most of the trading has taken place above the VWAP

Negative skew: Most of the trading has taken place below the VWAP.

 

Your first order of business when looking at a volume distribution is to determine the sign of the skew. Once you have done that, see where the price action is.

a) If price action is above the VWAP and skew >0, look for long trades only.

b) If price action is below the VWAP and skew <0, look for short trades only.

 

These are the best trades to look for and Newbies should only do these to begin with. When you take these kinds of trades, you will be trading in the high volume zone of the distribution.

 

It's when price action is BELOW the VWAP and skew > 0 or

price action is ABOVE the VWAP and skew < 0

that things get interesting and exciting. Then your looking for breakouts into the low volume region with range extension. "Exciting" means "Living on the edge". If you like the rush of living on the edge, then look for trades in the low volume zone. These types of trades are described beginning in [thread=2232]Part VII[/thread]

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.


  • Topics

  • Posts

    • Is it possible to use AND and OR for optimization in Amibroker? Lets look at this line of code: U = Optimize(1, 0, 1, 1);  Buy = (C > MA(C,20) ) == U;  //condition is True if U = 1 and False if U = 0 In effect I can flip ">" operator to "<=" by using numerical values of 0 for False and 1 for True in optimization. Is there a way to do the same with AND and OR? Lets look at this line of code: Buy = ROC(C,5) > 1 OR ROC(C,1) < -2;  and this one: Buy = ROC(C,5) > 1 AND ROC(C,1) < -2;  Is there a way to run an optimization on the following so it is an equivalent to switching between AND and OR: OPERATOR = Optimize(AND, AND, OR, ?);  Buy = ROC(C,5) > 1 OPERATOR ROC(C,1) < -2;  Any help would be greatly appreciated.
    • Sure just to name a few - Plus500, XM.com, Forex.com
    • Being regulated by the CySEC! Are you serious? 🤣 Ok. Let's get serious. Only the FCA is what we can call a real regulator, so could you please name just ONE crypto broker regulated by the FCA? And I said REGULATED and not REGISTERED. You know what I mean. 😜
    • ) I want to share my trading experience with Fiatotrade . Two years ago I started a small amount, received a little profit and withdrew the entire amount without any problems. Then after some time he threw quite a large amount and began to trade in large volumes. Problems began in the form of slippages and requotes, as it turned out later - this is due to the fact that the type of account was Standard . In general, I decided to withdraw the entire amount again, they asked me to confirm the passport data (probably because the amount was large). Confirmed - withdrawn in 5 minutes. Then I took a break again and a year ago I decided again to trade with this broker. Again I started a large amount, but already on the ECN account. There was no requote, and with slippings almost without problems. In general, trade is on its own, and profit is also available and derived. Therefore, I remain with this broker for now, because I checked it on my own skin.
    • Does anyone have ValueChart indicator for NT8?
×
×
  • Create New...

Important Information

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