Tracking average daily volume by time of day on a 30 min chart
Author: Tobey
Creation Date: 2/27/2019 9:04 PM
profile picture

Tobey

#1
Hi Eugene

Volume at the open and close are usually higher than during the middle of the day.

So I'd like to create a 60 day moving average of the volume bar by bar on a 30 min chart. So it would be the volume of the opening bar plus the bar 13 bars ago plus the bar 26 bars ago etc. As the average moved through the day it would reflect the average trading volume for each 30 min bar.

I'd appreciate your ideas as to how to do this.

Thanks so much
Tobey
profile picture

Eugene

#2
Hi Tobey,

QUOTE:
So it would be the volume of the opening bar plus the bar 13 bars ago plus the bar 26 bars ago etc.

Hardcoding bars ago is not too elegant. See code from post #12 in this topic:

Close of bar of specific time

All that's left is to replace Close with Volume and specify your time of day instead of "1030".

QUOTE:
Volume at the open and close are usually higher than during the middle of the day.

Yes, some trading system developers put an emphasis on the last hour. Take a look at this in Community Indicators, for example:

Last Hour Indicator (Smart Money Index)
profile picture

Tobey

#3
Hi Eugene,

"Close of bar of specific time" Plots the volume for the bar at the time you enter in the indicator window.

In the example Attached, we have a blue line for the average volume with average volume peaking at the beginning and ending of the day. The Cyan line above is 150% 0f the average hourly volume. You can see a few volume bars that are above the average volume for that time of day. I'd like to create this kind of line on a 30 min chart I'm hoping it is a good way to spot heavy volume at any point in the day. Is there a good way to do this?

Thanks again,
Tobey
profile picture

Eugene

#4
Time to refresh memory - you've already asked for this :)

Counting bars up with greater than 150% of average volume
profile picture

Tobey

#5
Hi Eugene,

Yes and with your help it is working very nicely on a daily chart. And I could do this on a 30 min chart by adding the last 13 bars to make a day and comparing it to 650 bars as 50 days.

But this doesn't take into account the normal fluctuation of volume during the day. What would be heavy volume in the middle of the day could just be less than average volume near the open or close. I am hoping to get a look at the activity inside the day.

If it is possible great! If not I can use the 13 to 650 relationship on the 30 min chart.

As always Much Thanks for your help,
Tobey
profile picture

Eugene

#6
Tobey, let me know if this works as you envisioned it:

CODE:
Please log in to see this code.
profile picture

Tobey

#7
Hi Eugene,

Thanks! I tried the code. You can see it in the attachment. I also marked up the volume panel. I hope you can see it and I hope it gives you a better idea of what I am thinking.

Thanks again
Tobey
profile picture

Tobey

#8
Hi Eugene,

Here is an example of the 13 to 650 bar formula. As you can see most open and close volume shows up above the moving averages.

Thanks
Tobey
profile picture

superticker

#9
What I see from the Post# 7 diagram is the opening 30-bar behaves totally contra to all the other 30-minute bars for the rest of the day. In other words, the day traders are doing the "reverse" of the end-of-day traders in reproducible fashion. So, as a day trader, if the opening 30-minute bar spikes up, you want to buy short for the remainder of the day. And if the opening 30-minute bar spikes down, you want to go long for the rest of the day. Bottom line, the net price goes nowhere.

Is that the meaning you're trying to convey from the graphic? (Or am I missing something?)

I do agree the end-of-day traders and day traders can have a push-pull relationship since they operate at different distinct times during the day. I never thought about building a trading strategy around that behavior ... though.
profile picture

Tobey

#10
HI Superticker,

Interesting point. My goal is a little longer term. I'm looking to find big money sneaking into a stock that is about to move up. BURL may not be a good example. It only has one bar up on heavy volume. In some cases I've seen 2 or 3 bars of heavy before the price starts a big move. The reverse could also be possible. A few bars of heavy volume with the price moving down before a bigger move. In these cases people are trying to buy or sell as much as the can without really moving the price. I think it can be an indicator of things to come.

Tobey
profile picture

Tobey

#11
Hi Eugene,

I got a hold of some code my friend used in Think or Swim to create the average volume daily volume for each bar in a 30min chart. He has it setup so he can change the number of bars.

It's a lot of code but he is just adding up every 13th bar and dividing by the number of bars to get the average. Then he is plotting it as a simple moving average.

I tried to duplicate it in WLPro last night but all I kept getting was the dreadit "error"

Is there a way to code something like this in WLPro?

Thanks again for your advice,
Tobey


CODE:
Please log in to see this code.
profile picture

Eugene

#12
Tobey, hardcoding it like this is pretty inelegant and error-prone. Think about stepping down to 1-5 minute scale on a not top liquid stock. Occasionally it'll end up summing the volume at 10:31am for yesterday with 10:29am's volume today or with 10:33am tomorrow etc. Not to mention that this approach can hardly be scaled up to a moving average that lags less than SMA does. The code will quickly become a mess. So if you're asking me then there's always a way but this one's just not the way to go.

But why the need in it? What's wrong with changing the time in my sample code?
CODE:
Please log in to see this code.
profile picture

Tobey

#13
Hi Eugene,

Thanks for the good advice. I'm a little lost with the if ( GetTime(bar) == 1000) code. I only see it giving me information for 10:00 or whatever time I put in.

But I think I could make it simpler by just using two moving averages crossing over. On a 30 min chart a 13 bar moving average would equal 1 days rolling volume. A 650 bar moving average would add up to an average 50 day volume number. So when the 13 mov of volume crossed above the 650 bar average volume it would indicate the beginning of a heavy volume day at any time in the day.

And now we have something even I can code! I'll give it a try.

Thanks again for all your help and advice
Tobey
profile picture

Eugene

#14
QUOTE:
I'm a little lost with the if ( GetTime(bar) == 1000) code. I only see it giving me information for 10:00 or whatever time I put in.

But wasn't this the idea? I was under impression that you're interested in that particular time of day volume. The code averages it, discarding any other time slots, and shows the value for the rest of the day.
profile picture

Tobey

#15
Hi Eugene,

Yes the idea was to look at each bar during the day to see if unusually heavy volume was starting. The thing is we don't know whether it's going to be 10am or 2pm and what the average volume is at that time of day. If you had the information bar by bar you could scan for a couple of bars in a row up on heavy volume. And that would be great!

On the other hand the two moving averages will sort of work, but the signal will be a little delayed.

Thanks for following up
Tobey
profile picture

Eugene

#16
Hi Tobey,

I must have missed the moment when your initial interest in the open/close vs. midday volume has shifted to detecting an unusually heavy volume on an arbitrary bar. In this context, comparing the 11:30am or 2:30pm bar to its n-day average value would look far-fetched to me.

To implement your new idea there's approach more adaptive than the 13/650-bar MAs. Your Strategy can readily compress intraday data into Daily scale and access that data from higher timeframe. Check out the Multi-Time Frame Analysis chapter > Intraday/Daily in the WealthScript Programming Guide. In particular you'd want to use SetScaleDaily, RestoreScale and Synchronize like shown in code examples there.

A more advanced technique is illustrated in this Knowledge Base article from WL Wiki: Intraday / Multi-Time Frame | Mixing intraday and daily data > "Updating a Daily indicator using Intraday values"
profile picture

Tobey

#17
Hey Eugene,

I think I'm not being clear. Let me try to restate the question as a word problem.

On a 30 min chart, pick any volume bar representing 30 mins of trading.

What is the average trading volume for just that bar (30min) over the past 50 days?

Then how does today's volume for that bar (30 min) compare to the average volume over the past 50 days?

If today's volume for that bar (30 min) is 150% of the average volume for the bar it could be the start of a big move up or down depending on the price change.

I'd like to do this for every bar in the day individually, because I see there is a big difference in average depending on the time of day.

Two bars together with heavy volume would further confirm the beginning of a move and help find an early entry point at a better price.

I hope this is a clearer description of the problem.

Thanks again for thinking about it,
Tobey
profile picture

Eugene

#18
I think you've expressed your idea clearly and I've shared my opinion about it:

I must have missed the moment when your initial interest in the open/close vs. midday volume has shifted to detecting an unusually heavy volume on an arbitrary bar. In this context, comparing the 11:30am or 2:30pm bar to its n-day average value would look far-fetched to me.

The dynamics of opening/closing bars has a special place but I'm not sure if comparing the volume of an arbitrary bar during the market session sounds like a credible idea to me. But it's your call. Looks like I've provided sufficient guidance for you to code your idea.
profile picture

Tobey

#19
Hi Eugene,

Great. Given your concerns, I'll try the 13 to 650 moving averages. I think it will be a little slower to give a signal. But it should beat an end of day signal.

Thanks so much for all the help on this one.
Tobey
profile picture

Eugene

#20
Whatever works for you is fine with me :)
profile picture

Tobey

#21
Hi Eugene,

Below is the code for for running on a 30 min chart.

As we have been talking about, I'm looking to generate a buy signal when the 13 bar mov crosses the Hi Average volume bar ( 60 day average volume x 1.5 ). Here I'm looking for a cross above of 2 bars to buy and a cross below of just one bar to sell.

The strategy compiles OK
But it hits an error when I run it on 30 mins to the Dow 30 data set.

Object reference not set to and an instance of an object
Unable to get Data on Demand for symbol: AA

Update Data on Demand is checked on the file menu.

Thanks for taking a look at this
Tobey

CODE:
Please log in to see this code.




profile picture

Eugene

#22
Please see the Knowledge Base (Wiki) article: Errors | Strategy > Object reference not set to an instance of an object.
profile picture

Tobey

#23
Thank You. I think it is working.
profile picture

Eugene

#24
You're welcome.
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).