# volume pressure ratio as histogram bars

#### shakib3585

##### Active member
VIP
Hello All,

Can anyone please help me with a script that shows the up/down volume ratio as histogram bars? I would like to use it on any aggregation period.

Thank you

Hello All,

Can anyone please help me with a script that shows the up/down volume ratio as histogram bars? I would like to use it on any aggregation period.

Thank you

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.

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);``````

Last edited by a moderator:
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);``````

87k+ Posts
199 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

What is useThinkScript?

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.

What are the benefits of VIP Membership?