AlfyParticipant
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
What are you expecting to see that you are not seeing … presumably not attached (see at red arrowhead)?
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
JSParticipant
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
AlfyParticipant
Average
Thanks Roberto, your advice fixed the problem and the numbers make much more sense now.
Best regards