up vs down volume ratio

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #205952 quote
    Alfy
    Participant
    Average

    Good afternoon guys, I’m trying to build a ratio of up vs down volume over the last 50 trading days. So I’m looking to calculate the ratio of volume on days when the stock closed higher on the day vs the volume on days when the stock closed lower. I’ve attempted to create the code but I don’t think I’ve done it correctly. Can someone take a look please? Any help much appreciated

    if close/close [1]>1 then
    volup=Volume
    endif
    if close/close [1]<1 then
    voldn=Volume
    endif
    ratio=(summation[50](volup)) /(summation[50](voldn))
    Return Ratio
    #205953 quote
    GraHal
    Participant
    Master

    What are you expecting to see that you are not seeing … presumably not attached (see at red arrowhead)?

    Alfy thanked this post
    #205955 quote
    robertogozzi
    Moderator
    Master

    Add these two lines at the very beginning, as a variable which hasn’t been modified will retain the previous value so that it always happens that both variables have some value, be it the current one or a prior one:

    volup = 0
    voldn = 0
    Alfy thanked this post
    #205956 quote
    JS
    Participant
    Senior

    Hi @Alfy

    Try this…

     

    If Close = Close[1] then
    VolUp = VolUp
    VolDown = VolDown
    EndIf
    
    If Close > Close[1] then
    VolUp = VolUp + Volume
    ElsIf Close < Close[1] then
    VolDown = VolDown + Volume
    EndIf
    
    Ratio = Summation[50](VolUp) / Summation[50](VolDown)
    
    Return Ratio
    
    #205958 quote
    Alfy
    Participant
    Average

    Thanks Roberto, your advice fixed the problem and the numbers make much more sense now.

    Best regards

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

up vs down volume ratio


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Alfy @alfy Participant
Summary

This topic contains 4 replies,
has 4 voices, and was last updated by Alfy
3 years, 1 month ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 12/17/2022
Status: Active
Attachments: 2 files
Logo Logo
Loading...