How can i call the volume for each 30 min bar of the previous day? and the previous week same day (30 min)?
Forums › ProRealTime English forum › ProBuilder support › How can i call the volume for each 30 min bar of the previous day? and the previous week same day (30 min)?
- This topic has 10 replies, 5 voices, and was last updated 3 years ago by Karen.
-
-
12/29/2020 at 10:24 AM #155519
Good morning Roberto and Vonasi, can I ask another question please. On a 30min TF (for example), how can i call the volume for each 30 min bar of the previous day? and the previous week same day (30 min)?
Example: we are 29 Dec. and I would like to plot (1) the current day volume between 9.00 am and 9.30 am, with (2) the 30 min volume of 28 Dec. between 9am and 9.30 am, with the (3) the last week (22 Dec.) volume between 9am and 9.30 am.
Thank you
12/29/2020 at 10:53 AM #155526You can use arrays, 48 elements for the Daily array (24 hours * 2 elements each hour) and 240 for the Weekly array (24 hours * 2 elements * 5 days).
Each 30 minutes you will need to shift all elements 1 place to make room for the new one.
1 user thanked author for this post.
12/29/2020 at 10:57 AM #155529Do not append different questions to exixting topics. Start a new one, instead. Thank you 🙂
I did it.
1 user thanked author for this post.
12/29/2020 at 12:01 PM #155541This returns the volume at the same time the previous day:
1234$lastvol[opentime] = $vol[opentime]$vol[opentime] = volumereturn $lastvol[opentime]2 users thanked author for this post.
12/29/2020 at 12:26 PM #15554912/30/2020 at 12:24 PM #155668Sorry but I finally got around to testing that last bit of code and it only works for the first tick at the open of a new volume bar and after that the values update incorrectly.
So I stopped trying to be clever by using arrays and went back to old fashioned loops. It is much slower to load but at least the results are correct. This one includes the volume from this time a week ago too.
123456789101112131415for b = 1 to barindexif opentime[b] = opentime and opendayofweek[b] <> opendayofweek thenlastvol = volume[b]breakendifnextfor b = 1 to barindexif opentime[b] = opentime and opendayofweek[b] = opendayofweek thenlastweekvol = volume[b]breakendifnextreturn lastvol as "this time previous day", lastweekvol as "this time last week"Here is a version that when applied to a volume chart draws points showing the previous days volume for the same candle at this time and the previous weeks volume for the same candle on the same day.
1234567891011121314151617181920212223242526defparam drawonlastbaronly = trueif islastbarupdate thenfor b = 1 to barindexif opentime[b] = opentime and opendayofweek[b] <> opendayofweek thenlastvol = volume[b]drawpoint(barindex,lastvol,1)coloured(0,0,0)drawtext("D",barindex+1,lastvol,sansserif,bold,12) coloured(0,0,0)breakendifnextfor b = 1 to barindexif opentime[b] = opentime and opendayofweek[b] = opendayofweek thenlastweekvol = volume[b]drawpoint(barindex,lastweekvol,1)coloured(0,0,0)drawtext("W",barindex+1,lastweekvol,sansserif,bold,12) coloured(0,0,0)breakendifnextelselastvol = undefinedlastweekvol = undefinedendifreturn12/31/2020 at 10:04 AM #15576501/07/2021 at 9:08 AM #15670601/07/2021 at 9:22 AM #156711FYI, intraday relative volume comparison as an indicator can be found here: https://www.prorealcode.com/topic/relative-volume-rvol/#post-125548
1 user thanked author for this post.
07/14/2021 at 5:27 PM #173633Dear @Vonasi and PRC communityBased on this great example, I tried to implement code for a screener that would allow me to calculate “Current cumulative volume up to this time of today / Cumulative volume up to this time of yesterday”. It looks like this:
12345678910111213timeframe (daily)v=volumetimeframe(default)vol = volumefor b = 1 to barindexif opentime[b] = opentime and opendayofweek[b] <> opendayofweek thenlastvol = SUMMATION[b](vol)[b]breakendifnextcv = vRV = round((v/lastvol),2)return rvUnfortunately, it did not work properly. When I check and manually count yesterday’s volume to some point in time, I can see that the lastvol is not counted correctly for that period. Could you help me fix a bug that is causing an incorrect calculation of lastvol?
07/14/2021 at 6:26 PM #173639It looks like I finally managed to solve this problem. This code is extremely slow, so it will take a lot of thinking to optimize it (and I would really appreciate tips on improving it – because it’s really VERY slow while using as a screener), but finally I can compare exact volumes!
12345678910111213Defparam DRAWONLASTBARONLY = truetimeframe (daily)v=volumetimeframe(default)vol = volumefor b = 1 to barindexif opentime[b] = opentime and opendayofweek[b] <> opendayofweek thenlastvol = v[b]breakendifnextRV = round((v/lastvol),2)return RV as "Ralative Volume",1 -
AuthorPosts
Find exclusive trading pro-tools on