Quote from IronFist:
Let me make sure I have this right.
The range of values which I'm using to calculate the SD is going to be every candle so far since the new VWAP began, right? So I can't just use a fixed value n for this calculation.
Assuming that's the case I'm only going to be able to do this for fixed time bars because I'm not good enough to code it such that it could use range/tick/volume bars where there might be a different amount each day.
Ok, chart is looking much better.
Few issues problems to iron out.
1) Is that 7/25 marker at the bottom of the 2 period window the end of the 1st 24 hour window?
I'll assume it is for the moment.
Couple of funny things, which may be related to your question...
2) That large red candle at about 9:30 seems to be swinging pretty wildly outside of the 3std band. Doesn't really seem right... HOWEVER, I think it is because you are calculating STD relative to the average of the price bar (is this what you mean by varying ranges?). You could recode it so that instead of using average price, you use the differnece value of the greatest price swing during the OHLC bar during that bar minus VWAP. I.e.
diff = max(VWAP - P(OHLC)) for each point.
Or more explicitly, diff is equal to the maximum of
(VWAP-Po, VWAP-PH, VWAP-PL, VWAP-PC) for each bar.
That would solve the narrow boundary issue.
3) secondly, if your 24 hour window period ends at the 7/25 marker, the old values of VWAP, stdev, etc.. need to be reset and started at the next point.
You only get to define 1 and only 1 window of time to reapply the function to each time. I.e. start VWAP and STDEV at midnight end at midnight.
Clear variables. Repeat.
Start next VWAP/stdev at next point after midnight (looks correct on VWAP, but stdev did not seem to reset on 7/25 open), why?
Assuming that's the case I'm only going to be able to do this for fixed time bars because I'm not good enough to code it such that it could use range/tick/volume bars where there might be a different amount each day.
I can't see why you would change the interval between time bars on any given day (24 hr) window. In any typical program I'm aware of, the time intervals are always fixed (1 bar/min/day, 1bar/sec/day, 1bar/10min/day, etc.. is fixed over window).
Not sure why there would be a different amount each day. Maybe you can clarify.
If you did want to start calculating VWAP at the 1st instant of each trading day (as you mentioned), they would have to change that in the program or give you the flexibility to do so.
It looks like they fix the VWAP window at 24hrs. I can see why that alternative might be more meaningful.