# How to find volume up to the present candle in intraday

Hi,

How to find the cumulative volume ? I want to sum of the volumes from market starting time to up to the present candle.If any sample code is very appreciated.

2 Likes

Have you searched the forum?

See: Sum Function.

1 Like

@Kum001 similar topic with a solution for you in a couple of posts on this thread,

2 Likes

@Kum001

https://forum.amibroker.com/t/counting-problem/2500/2

to sum intraday since day start

Just adding error notice for people not getting it that it is for intraday.

``````
if ( Interval() >= InDaily && Status( "actionex" ) != actionExEditVerifyFormula )

dn = DateNum();
newDay = dn != Ref( dn, -1 );
csum = SumSince( newday, V ) + ValueWhen( newday, V );
Plot( csum, "Sum of Volume since Start of Day", colorGreen, styleHistogram, Null, Null, 0, 0, -60 );

``````
4 Likes

FYI, perhaps you can look at a static percentage of the prior full days volume, given how far you are into the current session. Rather a better way perhaps would be for a Relative Volume, is to sum up the same volume of prior days, but just for the time frame you are at now and then get an avg. So for example, if you were in the current session at 10:21 am and wanted to know how the current relative volume looks like, the indicator would add up the volume of 'n' prior days from 9:30 - 10:21 and compare the n prior average to what you are expeincing so far in the current session.

Sounds like a good scan/filter in pre-market to see what's in play that day etc.
-S

1 Like

Can you elaborate on how you would do this, in pseudocode of course,

Hmmm I'll try.

It's tricky, because you will most likely (in a live situation) in some sort of partial current bar interval. So the larger the interval, the less meaningful your relative volume might be. Unless of course you include the "Now" interval volume, but even then you will be measuring total interval volume back in time etc. Anyway something like..

1 - get the interval you are in.
2 - find the start time of the session you are interested in.
3 - get the time stamp of the your current interval.
4 - make a variable the length of your days of look back.
5 - loop and check if bar time <= your current bar time and bar time > your session start time -or- whatever window of time you are interested in. Then add up volume for the date and fill op your day look back variable.
6 - take an average or whatever
7 - compare it to your current volume total thus far in your current day or your time window.

-S

1 Like

Thanks for the outline @Sean, it's much appreciated, and it'll give the forum something "meaty" to work with, rather than a vague one-liner that most questions start out with.

I haven't spent much time analysing your suggestion, or how to implement it, but I'll do so over the next few days, if only to satisfy my own curiosity.

Also, you might want to fork this off to a new topic.

Regards, phase21

@fxshrat In the same way if i want to calculate yesterday's volume at the same time can i write in below way
dn = DateNum();
yesterday = dn != Ref( dn, -2 );
csum = SumSince( yesterday , V ) + ValueWhen( yesterday , V );

My questions is it won't consider today's candles right? will it calculate only yesterday start of the candle to yesterday end of the candle ?

@portfoliobuilder In the same way if i want to find yesterday's volume
can i write the code in below way.

``````Bar_yesterday = BarsSince( Day() != Ref( Day(), -2 ) ) + 1;
YesterdayVolume = Sum( V, Bar_yesterday );
``````

But this "Sum" function calculating sum of the volumes from yesterday's candle up to today's candle. But if i want only yesterday's start of the candle to end of the candle volume what modification should i do?

No, you can not do it the way you have posted. It is not that simple (not just one line and not just some number change). You want to shift forward the entire intraday values by one day or n-days (since you want to know at each time of current day the value at same time of yesterday or days before (shifted to current day's timenum)). So if you want to precisely shift forward (since each day may have different number of bars available) you would have to iterate to achive that (no barcount loop). And before you will ask, yes I know how to do that as I have done that few years ago. But I won't reveal each and every know-how copy&paste ready just like that. It is bit more code than just two lines. Just think a little and take your time without rushing. Maybe you will come to realisation yourself soon.

Below in picutre is what I understand you want to do: Lower pane shows shifted array. And as you can see some days have different length. So you can not do just Ref() this and that by some number.

On the other hand if you want to know just the end cum. volume value of entire previous day then that one is (much) simple(r).

``````prev_days_Vsum = TimeFrameGetPrice("V", inDaily, -1);
``````

But that's not what you want (as it looks).

Thanks @fxshrat for your valuable reply. But the bar count always same right. If i am in hourly chart and the market start at 9 AM and close at 5 PM so the number of bars always 9 right(constant) in the case ?

If you want to do it your way then just do it your way. No one prohibits you. Use Ref(csum, -bars) then.

I was talking about precise way working in every case happening and every intraday time frame.

You assume that there will always be same amount of intraday bars within a time frame. But assumption are not facts.

1 Like

Hi @fxshrat By running the code,which you mentioned getting the error. Can you please suggest me.Please find the attachment.

For SumSince you need AB 6.10 or higher

https://www.amibroker.com/guide/afl/sumsince.html

("AFL 4.10" means implemented to AB 6.10. Difference between AFL version and AB version is always 2.)

1 Like

Hi.. @fxshrat .I am trying to achieve the same out put with old version only.
So is the below code is correct? Please correct me if anything is wrong.

``````Bar_today = BarsSince( Day() != Ref( Day(), -1 ) ) + 1;
Bar_yesterday = BarsSince( Day() != Ref( Day(), -2 ) )+1 ;

TodayVolume = Sum( V, Bar_today );
YesterdayVolume = Sum( V, Bar_yesterday );
``````

The code seems to be wrong.

What AmiBroker version are you running?

Please provide evidence, in the form of description/ code/ logical argument/ illustrations, to support your statement, otherwise, ...