PenttiRah
(Pentti Rahko)
1
I have following Pine script in TradingView to calculate Up/Down volume ratio and I would like covert it to Optuma script.
upVol = sum(change(close) > 0 ? volume : 0, 50)
downVol = sum(change(close) < 0 ? volume : 0, 50)
ratio = upVol/downVol
I guess ACC function could be used to calculate volume over last 50 days but how to separate up/down days volume?
ACC(VOL(), BARS=50)
DEJHMA8
(Darren Hawkins)
2
Hi Pentti,
You can use IF statements to separate up from down days, and sum the values for each:
//Get volume for up/down days;
Up1 = IF(CLOSE() IsUp, VOL(),0);
Dn1 = IF(CLOSE() IsDown, VOL(),0);
//Sum up/down volume;
UpVol = ACC(Up1, RANGE=Look Back Period, BARS=50);
DnVol = ACC(Dn1, RANGE=Look Back Period, BARS=50);
//Calc Ratio;
UpVol / DnVol
Use in a Show View and set the Positive/Negative Barriers to 1 to show the ratio: