CFDs – Average Volume during Market hours

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

    Hello, I’d like to:

    1/ compare in Intraday current volume to Average[20](Volume) taking into account only volume during normal market hours, for example 9am to 5.30pm for DAX. The average should exclude volumes during the period 5.30pm to 9.00am next day.

    2/ compare current volume (today) VS yesterday’s volume at the same time, for example volume today between 9.00am and 9.30am VS volume the day before between 9.00am and 9.30 am.

    Thanks

    20201225_122249_Avg-Volume.png 20201225_122249_Avg-Volume.png
    #155190 quote
    Vonasi
    Moderator
    Master

    Khaled – I guess that you are requesting someone to code you an indicator? If so then you have posted in the wrong forum. I have moved your topic to the place for indicators.

    Post your topic in the correct forum:
    _ ProRealTime Platform Support: only platform related issues.
    _ ProOrder: only strategy topics.
    _ ProBuilder: only indicator topics.
    _ ProScreener: only screener topics
    _ General Discussion: any other topics.
    _ Welcome New Members: for new forum members to introduce themselves.

    #155236 quote
    Khaled
    Participant
    Veteran

    Thank you Vonasi!

    #155415 quote
    Khaled
    Participant
    Veteran

    Good morning, maybe my initial request was not clear enough…

    Let’s assume:

    volume 5 min bar closing at 17:25 is 50 (the previous day)

    volume 5 min bar closing at 17:30 is 70 (the previous day)

    volume 5 min bar closing at 08:50 is 100

    volume 5 min bar closing at 08:55 is 120

    volume 5 min bar closing at 09:00 is 200

    volume 5 min bar closing at 09:05 is 250

    I’d like to calculate the Simple Average Volume on last 4 bars excluding the time from 17:30pm to 08:59 am, i.e. average of (50, 70, 200, 250)=142.5

    When I apply the condition

    if time>=090000 and time<=173000 then
    
    xVol = Average[4](Volume)
    
    endif

    the first average calculated at 09:00 will take into account the four bars closing before 09:00, i.e. (09:00, 08:55, 08:50, 08:45)

    Thank you for you help.

    #155422 quote
    robertogozzi
    Moderator
    Master
    #155440 quote
    Khaled
    Participant
    Veteran

    Thank you Roberto. I’m afraid this doesn’t solve my problem.

    I have copied the “Time Range Simple Moving Average” code and changed “TRSMA” into “TRAV” (Time Range Average Volume” and replaced “Close” with “Volume”. Kept Periods = 20

    // TRAV - Time Range Average Volume
    
    DEFPARAM CalculateOnLastBars = 200
    //Periods    = 20
    //StartTime  = 090000
    //EndTime    = 173000
    Periods      = max(2,min(999,Periods))
    StartTime    = max(0,min(240000,StartTime))
    EndTime      = max(0,min(240000,EndTime))
    //
    i     = 0
    TRAV = 0
    FOR j = 0 TO 3000
    IF opentime[j] >= StartTime AND opentime[j] <= EndTime THEN
    TRAV = TRAV + Volume[j]
    i = i + 1
    IF i = Periods THEN
    BREAK
    ENDIF
    ENDIF
    NEXT
    TRAV = (TRAV / Periods)
    IF TRAV = 0 THEN
    TRAV = Volume
    ENDIF
    Return TRAV AS "TRAV"

    On a 5 min TF, if you look at the candle starting 28 Dec. at 09:00 the volume is 1199 but the TRAV is 59.95 (1199/20). The second candle starting at 09:05 shows a volume of 727, so the average (from the begining of the day) shoud be = 963, but the TRAV shows 96.30 (dividing by 20 instead of dividing by the number of candles since 09:00am). So the code divides the cumulative volume by 20.

    I tried to tweak the code to get this value corresponding to the average but I was unsuccesful.

    Can you please look again at this (maybe using summation or average formula)?

    Thanks a million.

    Average-Volume-2020-12-28-142249.png Average-Volume-2020-12-28-142249.png
    #155442 quote
    Vonasi
    Moderator
    Master

    Maybe this?

    Only works on v11

    p = 4
    starttime = 090000
    endtime = 173000
    
    once avg = undefined
    
    if opentime >= starttime and opentime < endtime then
    a = a + 1
    $vol[a] = volume
    
    if a >=p then
    total = 0
    for b = a downto a-p
    total = total + $vol[b]
    next
    
    avg = total/p
    endif
    else 
    avg = 0
    endif
    
    return avg
    Khaled thanked this post
    #155443 quote
    Khaled
    Participant
    Veteran

    Thank you Vonasi. Doesn’t work on the first bar of the 28th Dec. Divides the Vol by 4 instead of 1, same issue with the second bar, divides the Cumulative Vol by 4 instead of 2.

    Average-Volume-Vonasi-2020-12-28-1527.png Average-Volume-Vonasi-2020-12-28-1527.png
    #155447 quote
    Khaled
    Participant
    Veteran

    Solved! Thank you very much for your help, Roberto and Vonasi!!!!

    DEFPARAM CALCULATEONLASTBARS = 200
    
    // Average Volume Intraday
    
    IF time = 090000 then
    barstart= barindex
    ENDIF
    
    IF time>=090000 and time<=173000 then
    n = max(1, (intradaybarindex-barstart+1))
    AV = SUMMATION[n](volume)/ n
    ENDIF
    
    RETURN AV as "Average Volume Intraday"

    As you can see, the Avg Vol on the first 30 min bar is equal to the volume of the first bar, works well for the second, etc.

    Average-Volume-Khaled-2020-12-28-1549.png Average-Volume-Khaled-2020-12-28-1549.png
    #155458 quote
    Vonasi
    Moderator
    Master

    Glad you found your answer. I didn’t get that that was the problem you were trying to solve from your descriptions and I guess Roberto didn’t either. 🙂

    Khaled thanked this post
    #155459 quote
    Vonasi
    Moderator
    Master

    You might want to change TIME for OPENTIME as TIME is the closing time of a candle so you will miss the first candle in your session.

    Khaled thanked this post
    #155460 quote
    Vonasi
    Moderator
    Master

    This does the same thing:

    DEFPARAM CALCULATEONLASTBARS = 1000
    
    IF opentime = 090000 then
    n = 0
    myvolume = 0
    endif
    
    IF opentime >= 090000 and opentime < 173000 then
    n = n + 1
    myvolume = myvolume + volume
    av = myvolume / n
    endif
    
    return av as "Average Volume Intraday"
    Khaled thanked this post
    #155461 quote
    Khaled
    Participant
    Veteran

    Thank you so much Vonasi! Will use this associated with STD on Vol and compare the Current Session to Day-1 and/or Week-1 (same day) to confirm acceleration in the market activity (sort of filter).

    #155464 quote
    robertogozzi
    Moderator
    Master

    Good to hear you have solved it!

    The average is made to account for PERIODS units, no matter the time. If your time starts at 9, it will consider 1 current bar + the last 19 bars of the previous day before 17:30.

    Since volume was 0 last Thursday, actually it seems the average of the first candle is volume / 20 periods. NO, it’s the sum of the volume of the last 20 periods / 20 periods. Of course it considers only periods within the defined time range.

    Khaled thanked this post
Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.

CFDs – Average Volume during Market hours


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Khaled @khaled Participant
Summary

This topic contains 13 replies,
has 3 voices, and was last updated by robertogozzi
5 years, 1 month ago.

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