Count volume during a certain timeframe

Questions about MultiCharts and user contributed studies.
bmills313
Posts: 13
Joined: 14 Jan 2010

Count volume during a certain timeframe

Postby bmills313 » 11 Jun 2010

I'm looking for a way to calculate the volume that occurred from the close of the day session to a certain point in time...let's say 9:00am the following day.

I typically chart with constant volume bars so maybe another way to accomplish this is to somehow provide a starting time and ending time and then count the # of bars that were drawn within that timeframe. You could then multiply the count by the value of the bar (500 contract, etc.) and then come up with the volume. Not perfect but it might work.

Or...can you access the tick data in the database and count it that way? Like add up the volume column of all the ticks between a start and end time?

I gotta believe there's some way to do this I just don't know how! Any help would be much appreciated!

Thanks!

bmills

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Postby TJ » 11 Jun 2010

you've got the right idea...
but the execution is a bit tricky, I will explain later.

First,
you will need to set up a variable (let's call it "overnight.volume"),
then start adding the volume to it after the regular session closes (eg. for ES, it is 1615),
keep adding to it after each bar,
at the beginning of 0900, you will have your total overnight volume.

Here's the tricky part:
with volume bar chart, the bars do not begin or end at the exact session times.
When you want to start counting at the end of the regular session,
the bar might begin at 161501, or 164000...
or whenever it takes to finish the bar that started before the session end time (161459).
The trick is to detect the end time, so that you can reset the counter to zero before you start your new day's accumulation.

Give this code a try and see if it meets your need...

Code: Select all

// Overnight Volume
// version: beta 0.1
// author: TJ
// date: 20100611
// license: public domain
//

input:
start.time_s(161500),
end.time_s(90000);

var:
overnight.volume(0);

if time_s > start.time_s and time_s[1] < start.time_s then
overnight.volume = 0;

if time_s > start.time_s or time_s < end.time_s then
overnight.volume = overnight.volume + ticks;

plot10(overnight.volume, "ONV");

bmills313
Posts: 13
Joined: 14 Jan 2010

Postby bmills313 » 12 Jun 2010

Thanks TJ, I'm gonna give this a shot.

As I'm not super familiar with writing scripts and such...would this plot something on the price chart like "ONV 123,456" above the point in time I ask it to calculate up to or does it plot at some other location? If I scrolled back several days will it show the volume count for that day, too, or does it just keep count of the current day? I assume just the current day...

Really think this will help and once I get in front of my trading machine I will give it a go and report back :)

Thanks!


bmills

bmills313
Posts: 13
Joined: 14 Jan 2010

Postby bmills313 » 13 Jun 2010

you've got the right idea...
but the execution is a bit tricky, I will explain later.

First,
you will need to set up a variable (let's call it "overnight.volume"),
then start adding the volume to it after the regular session closes (eg. for ES, it is 1615),
keep adding to it after each bar,
at the beginning of 0900, you will have your total overnight volume.

Here's the tricky part:
with volume bar chart, the bars do not begin or end at the exact session times.
When you want to start counting at the end of the regular session,
the bar might begin at 161501, or 164000...
or whenever it takes to finish the bar that started before the session end time (161459).
The trick is to detect the end time, so that you can reset the counter to zero before you start your new day's accumulation.
TJ,

I just compiled this and it looks like it works! I love that it displays the data for every date on the chart; I see some real potential here, especially if I could figure a way to place a moving average so I could at a quick glance look in the morning and see how above or below the average the ONV was.

However it appears that as I change the # of contracts per bar so does the count. I presume this is because on the slower resolution bars (say 15,000 contracts) those bars may close several minutes after they started and the faster resolution bars (say 1,000 contracts) will have closed much sooner and the bar that is yet to be completed when the end time hits is not counted at all...

A couple follow ups:

1. is the only way around the above issue to use much faster resolution bars so the one that's being drawn at the end time doesn't have as much impact? Obviously 1-contract bars would be deadly accurate and seeing as I don't plan on keeping this indicator on any chart but one I check quickly in the morning this may not be that big of a deal...but I wondered if there was another way.

2. Is there a way to place a moving average on this study? Since it makes that ramp up from 0 and finally plateaus I'd really only want to base the MA amount from like 1 minute after the end-time of the calculation. Would you have to create another variable that's the final value at the end time and plot that amount and then base the MA on those points? I've never done a moving average calculation on a value within a study so this is new ground for me...

Thanks for the help...this is certainly helpful :)

bmills

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Postby TJ » 13 Jun 2010

you can have the calculation starts at exactly 161500... irregardless of the volume bar close.
ie you might have half a bar in the regular session,
and half a bar in the after hour session.
that would take a little more finesse and a little more coding to zero down on the exact contract that split the proverbial time line.
Does it worth the trouble of time and expense to get to the detail?
will your trading be improved 100% because of it?
... you will have to be the judge.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Postby TJ » 13 Jun 2010

...
2. Is there a way to place a moving average on this study? Since it makes that ramp up from 0 and finally plateaus I'd really only want to base the MA amount from like 1 minute after the end-time of the calculation. Would you have to create another variable that's the final value at the end time and plot that amount and then base the MA on those points? I've never done a moving average calculation on a value within a study so this is new ground for me...

Thanks for the help...this is certainly helpful :)

bmills
anything is possible...

if you can imagine it,
visualize it,
quantify it,
articulate it,
you can program it.


"moving average" is a general concept,
if you can define it... to the exact detail of its calculation,
you can easily code it.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Postby TJ » 13 Jun 2010

if after hour volume is your focus,

you can:

1. create a separate chart for this analysis
2. make the chart for after hour only, no RTH
3. use a minute chart, so that you can have exact volume delineation.
4. or use daily chart
5. you can apply the "Volume Avg" indicator that comes with MultiCharts. it plots the volume with average.

bmills313
Posts: 13
Joined: 14 Jan 2010

Postby bmills313 » 14 Jun 2010

Does it worth the trouble of time and expense to get to the detail?
will your trading be improved 100% because of it?
... you will have to be the judge.
What you've given me here gets me the "gist" of what I'm looking for. It doesn't need to be down to the exact # of contracts as a few here and there won't make that big of a difference and for my application this works great.

I'll mess around with moving averages and such to really help me hone in on getting what I want out of the overnight volume for my application :)

Thanks for your help, TJ!

bmills

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Postby TJ » 14 Jun 2010

you are welcome.

Gibo887
Posts: 10
Joined: 16 May 2020
Location: Italy
Has thanked: 2 times
Been thanked: 1 time

Re: Count volume during a certain timeframe

Postby Gibo887 » 05 Mar 2021

Goodmorning everyone. I was looking for an indicator that would calculate the volume between two time frames and came across this post. It's a bit dated so I don't know if anyone will be able to answer me: I tested the indicator, it works but it has a problem (or maybe just me?), It doesn't reset the volume calculation. It would be nice if he could add up the volumes from the opening of the market to the opening of the European cash market and from there reset - stop - to restart the calculation the following day. Can someone help me?

User avatar
Kate MultiCharts
Posts: 575
Joined: 21 Oct 2020
Has thanked: 7 times
Been thanked: 144 times

Re: Count volume during a certain timeframe

Postby Kate MultiCharts » 10 Mar 2021

Goodmorning everyone. I was looking for an indicator that would calculate the volume between two time frames and came across this post. It's a bit dated so I don't know if anyone will be able to answer me: I tested the indicator, it works but it has a problem (or maybe just me?), It doesn't reset the volume calculation. It would be nice if he could add up the volumes from the opening of the market to the opening of the European cash market and from there reset - stop - to restart the calculation the following day. Can someone help me?
Hello,

Here's an example of code you can use to achieve your goal:

Code: Select all

input: Time_Open_Market(1200); input: Time_European_Cash_Market(1600); var: sum_volume(0); var: condition1(true); var: condition2(true); if time = Time_Open_Market then begin condition1 = true; end; if time = Time_European_Cash_Market then begin condition1 = false; end; sum_volume = sum_volume + volume; if condition1 = false then begin sum_volume = 0; end; plot17(sum_volume);
1.png
(88.7 KiB) Not downloaded yet

Gibo887
Posts: 10
Joined: 16 May 2020
Location: Italy
Has thanked: 2 times
Been thanked: 1 time

Re: Count volume during a certain timeframe

Postby Gibo887 » 10 Mar 2021

Goodmorning everyone. I was looking for an indicator that would calculate the volume between two time frames and came across this post. It's a bit dated so I don't know if anyone will be able to answer me: I tested the indicator, it works but it has a problem (or maybe just me?), It doesn't reset the volume calculation. It would be nice if he could add up the volumes from the opening of the market to the opening of the European cash market and from there reset - stop - to restart the calculation the following day. Can someone help me?
Hello,

Here's an example of code you can use to achieve your goal:

Code: Select all

input: Time_Open_Market(1200); input: Time_European_Cash_Market(1600); var: sum_volume(0); var: condition1(true); var: condition2(true); if time = Time_Open_Market then begin condition1 = true; end; if time = Time_European_Cash_Market then begin condition1 = false; end; sum_volume = sum_volume + volume; if condition1 = false then begin sum_volume = 0; end; plot17(sum_volume);
1.png
Hello, I am really grateful to you for your help. I tried to set the indicator with time between 23:00 and 09:00 and it seems to work. Thanks again.
A further detail would improve the indicator even more if it is possible: it would be fantastic if it showed an average of the closing of "x" previous days, or as in the image, a line that simply signals the volume count reached the day before... it can be done?
Thank you very much for your help
Attachments
20210310-130532-001.png
(37.82 KiB) Not downloaded yet


Return to “MultiCharts”