How can i call the volume for each 30 min bar of the previous day? and the previous week same day (30 min)?

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #155519 quote
    Khaled
    Participant
    Veteran

    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

    #155526 quote
    robertogozzi
    Moderator
    Master

    You 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.

    Khaled thanked this post
    #155529 quote
    robertogozzi
    Moderator
    Master

    Do not append different questions to exixting topics. Start a new one, instead. Thank you 🙂

    I did it.

    Khaled thanked this post
    #155541 quote
    Vonasi
    Moderator
    Master

    This returns the volume at the same time the previous day:

    $lastvol[opentime] = $vol[opentime]
    $vol[opentime] = volume
    
    return $lastvol[opentime]
    robertogozzi and ashehzi thanked this post
    #155549 quote
    Khaled
    Participant
    Veteran

    Thanks a million Vonasi!

    #155668 quote
    Vonasi
    Moderator
    Master

    Sorry 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.

    for b = 1 to barindex
    if opentime[b] = opentime and opendayofweek[b] <> opendayofweek then
    lastvol = volume[b]
    break
    endif
    next
    
    for b = 1 to barindex
    if opentime[b] = opentime and opendayofweek[b] = opendayofweek then
    lastweekvol = volume[b]
    break
    endif
    next
    
    return 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.

    defparam drawonlastbaronly = true
    
    if islastbarupdate then
    for b = 1 to barindex
    if opentime[b] = opentime and opendayofweek[b] <> opendayofweek then
    lastvol = volume[b]
    drawpoint(barindex,lastvol,1)coloured(0,0,0)
    drawtext("D",barindex+1,lastvol,sansserif,bold,12) coloured(0,0,0)
    break
    endif
    next
    
    for b = 1 to barindex
    if opentime[b] = opentime and opendayofweek[b] = opendayofweek then
    lastweekvol = volume[b]
    drawpoint(barindex,lastweekvol,1)coloured(0,0,0)
    drawtext("W",barindex+1,lastweekvol,sansserif,bold,12) coloured(0,0,0)
    break
    endif
    next
    else
    lastvol = undefined
    lastweekvol = undefined
    endif
    
    return
    Screenshot_1-4.png Screenshot_1-4.png
    #155765 quote
    Khaled
    Participant
    Veteran

    Thank you Vonasi. You’re a MASTER! I beleive this can help day traders to detect unusual volume spike during the day or to eliminate noise when price varies without volume.

    Again, thank you and happy holiday season!

    #156706 quote
    Khaled
    Participant
    Veteran

    @Vonasi, @robertogozzi, @Nicolas,

    Happy New Year!

    Khaled

    robertogozzi thanked this post
    #156711 quote
    Nicolas
    Keymaster
    Master

    FYI, intraday relative volume comparison as an indicator can be found here: https://www.prorealcode.com/topic/relative-volume-rvol/#post-125548

    Khaled thanked this post
    #173633 quote
    Karen
    Participant
    Average
    Dear @Vonasi and PRC community

    Based 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:

    
    timeframe (daily)
    v=volume
    timeframe(default)
    vol = volume
    for b = 1 to barindex
    if opentime[b] = opentime and opendayofweek[b] <> opendayofweek then
    lastvol = SUMMATION[b](vol)[b]
    break
    endif
    next
    cv = v
    RV = round((v/lastvol),2)
    return rv

    Unfortunately, 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?

    #173639 quote
    Karen
    Participant
    Average

    It 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!

    Defparam DRAWONLASTBARONLY = true
    timeframe (daily)
    v=volume
    timeframe(default)
    vol = volume
    for b = 1 to barindex
    if opentime[b] = opentime and opendayofweek[b] <> opendayofweek then
    lastvol = v[b]
    break
    endif
    next
    RV = round((v/lastvol),2)
    return RV as "Ralative Volume",1
Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.

How can i call the volume for each 30 min bar of the previous day? and the previous week same day (30 min)?


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Khaled @khaled Participant
Summary

This topic contains 10 replies,
has 5 voices, and was last updated by Karen
4 years, 7 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 12/29/2020
Status: Active
Attachments: 1 files
Logo Logo
Loading...