shakib3585,
This script plots the ratio of bars with volume up to bars with volume down over the last <length> bars as a histogram. The line at 1.0 indicates where the numbers of up and down volume bars are equal. The default length is 20 bars, but this may not be best and it can be adjusted in the inputs.
The chart shows the new volume ratio indicator and also the default VolumeAvg indicator in ThinkOrSwim.
View attachment 21858
Code:
# Volume_UpDnRatio_Histogram
# Question from shakib3585 on 2/13/24
# Calculates the ratio of bars with volume up to bars with volume down within the last <length> number of bars.
declare lower;
input length = 20;
input cut_off = 1.0;
def upvol = if volume > volume[1] then 1 else 0;
def dnvol = if volume < volume[1] then 1 else 0;
plot VolRatio = sum(upvol, length) / sum(dnvol, length);
plot cutoff = cut_off;
VolRatio.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
VolRatio.SetLineWeight(4);
VolRatio.SetDefaultColor(Color.RED);
cutoff.SetLineWeight(2);
cutoff.SetDefaultColor(Color.BLACK);