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.
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);
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.
# 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);
useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.
How do I get started?
We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.
If you are new, or just looking for guidance, here are some helpful links to get you started.
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.