How to Adjust Volume Bars for Volume Spikes (Truncate)

IsItPossible

Member
When an unusual amount of volume happens on any given time frame, the resulting volume bar will tend to skew the rest of the volume bars in view. In order to accommodate the large volume bar for the volume spike, the other volume bars become unusually small. This makes volume trends difficult to see.

Can we truncate (adjust) those spike volume bars to maintain a more balanced volume view.

Something like this:

Here is the working script so far:

#----------------------------------------------------------------------------
# Author: IsItPossible
#
# Name: My_Volume_Truncate_Spikes
# Summary: This study can be used as an indicator which helps us suppress
# when an unusual amount of volume happens on any given time frame, the resulting
# volume bar will tend to skew the rest of the volume bars in view. In order to
# accommodate the large volume bar for the volume spike, the other volume bars become
# unusually small. This makes volume trends difficult to see.
#
# This indicator truncates (adjust) those volume spike bars to maintain a more
# balanced volume view.
#
#----------------------------------------------------------------------------

declare lower;

# Define input parameters
input thresholdMultiplier = 2.0; #Hint thresholdMultiplier: Specify the threshold multiplier for identifying volume spikes
input avgLength = 50; #Hint avgLength: Specify the bars to be considered to calculate average volume
input ColorAsPrice = {default false, true};

# Calculate the average volume over a specified period
def averageVolume = Average(volume, avgLength);

# Calculate the threshold volume level
def thresholdVolume = averageVolume * thresholdMultiplier;

# Identify volume spikes
def isVolumeSpike = volume > thresholdVolume;

# Plotting volume spikes
def maxPeriod = if GetAggregationPeriod() == AggregationPeriod.DAY then 252 else if GetAggregationPeriod() < AggregationPeriod.WEEK then 50 else if GetAggregationPeriod() < AggregationPeriod.MONTH then 12 else 10;

plot VolumeSpike = isVolumeSpike and Highest(thresholdVolume, maxPeriod) < volume;
VolumeSpike.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
VolumeSpike.SetDefaultColor(Color.LIGHT_ORANGE);

# Truncating volume spikes
def truncatedVolume = if isVolumeSpike and Highest(thresholdVolume,maxPeriod ) < volume then Highest(thresholdVolume, maxPeriod) else volume;

# Plotting truncated volume
plot TruncatedVolumep = truncatedVolume;
#TruncatedVolumep.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
TruncatedVolumep.SetDefaultColor(Color.CURRENT);

TruncatedVolumep.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
#TruncatedVolumep.SetLineWeight(3);
TruncatedVolumep.DefineColor("Up", Color.UPTICK);
TruncatedVolumep.DefineColor("Down", Color.DOWNTICK);
TruncatedVolumep.DefineColor("Current", Color.CYAN);
TruncatedVolumep.AssignValueColor(if ColorAsPrice then (if close > close[1] then TruncatedVolumep.Color("Up") else if close < close[1] then TruncatedVolumep.Color("Down") else GetColor(1)) else TruncatedVolumep.Color("Current") );

Last edited:
Solution
When an unusual amount of volume happens on any given time frame, the resulting volume bar will tend to skew the rest of the volume bars in view. In order to accommodate the large volume bar for the volume spike, the other volume bars become unusually small. This makes volume trends difficult to see.

Can we truncate (adjust) those spike volume bars to maintain a more balanced volume view.

Something like this:

Here is the working script so far:

#----------------------------------------------------------------------------
# Author: IsItPossible
#
# Name: My_Volume_Truncate_Spikes
# Summary: This study can be used as an indicator which helps us suppress
#...
One thing that helps is adding a label into the volume script. The label I have right now is " " so it says nothing and is the same color as my background so I don't even see it. Helps a ton

One thing that helps is adding a label into the volume script. The label I have right now is " " so it says nothing and is the same color as my background so I don't even see it. Helps a ton
But won't it take some space at top in the panel! besides what purpose wud it serve!

When an unusual amount of volume happens on any given time frame, the resulting volume bar will tend to skew the rest of the volume bars in view. In order to accommodate the large volume bar for the volume spike, the other volume bars become unusually small. This makes volume trends difficult to see.

Can we truncate (adjust) those spike volume bars to maintain a more balanced volume view.

Something like this:

Here is the working script so far:

#----------------------------------------------------------------------------
# Author: IsItPossible
#
# Name: My_Volume_Truncate_Spikes
# Summary: This study can be used as an indicator which helps us suppress
# when an unusual amount of volume happens on any given time frame, the resulting
# volume bar will tend to skew the rest of the volume bars in view. In order to
# accommodate the large volume bar for the volume spike, the other volume bars become
# unusually small. This makes volume trends difficult to see.
#
# This indicator truncates (adjust) those volume spike bars to maintain a more
# balanced volume view.
#
#----------------------------------------------------------------------------

declare lower;

# Define input parameters
input thresholdMultiplier = 2.0; #Hint thresholdMultiplier: Specify the threshold multiplier for identifying volume spikes
input avgLength = 50; #Hint avgLength: Specify the bars to be considered to calculate average volume
input ColorAsPrice = {default false, true};

# Calculate the average volume over a specified period
def averageVolume = Average(volume, avgLength);

# Calculate the threshold volume level
def thresholdVolume = averageVolume * thresholdMultiplier;

# Identify volume spikes
def isVolumeSpike = volume > thresholdVolume;

# Plotting volume spikes
def maxPeriod = if GetAggregationPeriod() == AggregationPeriod.DAY then 252 else if GetAggregationPeriod() < AggregationPeriod.WEEK then 50 else if GetAggregationPeriod() < AggregationPeriod.MONTH then 12 else 10;

plot VolumeSpike = isVolumeSpike and Highest(thresholdVolume, maxPeriod) < volume;
VolumeSpike.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
VolumeSpike.SetDefaultColor(Color.LIGHT_ORANGE);

# Truncating volume spikes
def truncatedVolume = if isVolumeSpike and Highest(thresholdVolume,maxPeriod ) < volume then Highest(thresholdVolume, maxPeriod) else volume;

# Plotting truncated volume
plot TruncatedVolumep = truncatedVolume;
#TruncatedVolumep.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
TruncatedVolumep.SetDefaultColor(Color.CURRENT);

TruncatedVolumep.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
#TruncatedVolumep.SetLineWeight(3);
TruncatedVolumep.DefineColor("Up", Color.UPTICK);
TruncatedVolumep.DefineColor("Down", Color.DOWNTICK);
TruncatedVolumep.DefineColor("Current", Color.CYAN);
TruncatedVolumep.AssignValueColor(if ColorAsPrice then (if close > close[1] then TruncatedVolumep.Color("Up") else if close < close[1] then TruncatedVolumep.Color("Down") else GetColor(1)) else TruncatedVolumep.Color("Current") );

i didn't look over your code yet
take a look at this

Not the exact question you're looking for?

87k+ Posts
400 Online

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?