Best way to calculate average (dollar/stock) volume?

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #164627 quote
    marie123marie123
    Participant
    Junior

    Hello,

    I made this loop to calculate the average dollar and stock volume over the last 60 days. Is this the best way to do it or can I do it without a loop?

    for i=60 downto 0 do
    totalDollarVol=totalDollarVol+volume[i]*close[i]
    totalStockVol=totalStockVol+volume[i]
    next
    averageDollarVol=totalDollarVol/60
    averageStockVol=totalStockVol/60
    
    #164629 quote
    JC_BywanJC_Bywan
    Moderator
    Master

    Good morning, you can use the “average” keyword applied to “volume” and “volume*close”:

    averageDollarVol=average[60](volume*close)
    averageStockVol=average[60](volume)
    marie123 thanked this post
    #164630 quote
    marie123marie123
    Participant
    Junior

    Great, thank you!

    One last question: is this also possible when you want to check the volume from day 50 to day 100? So can I use a different day to start the calculation?

    #164633 quote
    JC_BywanJC_Bywan
    Moderator
    Master

    Not sure to understand the question, if “check the volume from day 50” was a way to just accessing it, it’s volume[50]… but if you meant accessing the values from previous post on day 50, it’s same formula and using averageDollarVol[50] and averageStockVol[50]. If you meant something else, sorry I don’t understand could you please rephrase? Thanks.

    #164634 quote
    marie123marie123
    Participant
    Junior

    When I use your formula I get the average volumes from today until day 60. That’s what I need when I analyze the current situation.

    But I also need this for a backtest:

    for i=110 downto 50 do
    totalDollarVol=totalDollarVol+volume[i]*close[i]
    totalStockVol=totalStockVol+volume[i]
    next
    averageDollarVol=totalDollarVol/60
    averageStockVol=totalStockVol/60

    Here I check another 60 days for the average volume but I start with a different day.

    #164635 quote
    JC_BywanJC_Bywan
    Moderator
    Master

    ok, 50 to 110 (not 100) so that you have a 60 too, but starting earlier in the past. Then it is indeed the second case: ” … but if you meant accessing the values from previous post on day 50, it’s same formula and using averageDollarVol[50] and averageStockVol[50]” :

    averageDollarVol = average[60](volume*close)
    averageStockVol = average[60](volume)
    
    x=averageDollarVol[50]
    y=averageStockVol[50]

    NB: stricly speaking, it would have been 60 to 1, or 59 to 0, or 109 to 50 to get 60. If you really needed 60 to 0 / 110 to 50, then you can replace 60 by 61.

    marie123 thanked this post
    #164638 quote
    marie123marie123
    Participant
    Junior

    That helps me a lot, thank you very much!!

    JC_Bywan thanked this post
Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Best way to calculate average (dollar/stock) volume?


ProScreener: Market Scanners & Detection

New Reply
Author
author-avatar
marie123 @marie123 Participant
Summary

This topic contains 6 replies,
has 2 voices, and was last updated by marie123marie123
5 years, 6 months ago.

Topic Details
Forum: ProScreener: Market Scanners & Detection
Language: English
Started: 03/19/2021
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...