# Volume without considering outliers?

#### kkrac

##### New member
I want to search for stocks that have, in average, 1 million volume in the 50 periods or so. But I'm not interested in outliers (eg: average volume is of 50k and one day volume is of 45 million, I don't want to factor in that day with 45million volume in my search.)

What would be the best/right way to do this?

I want to search for stocks that have, in average, 1 million volume in the 50 periods or so. But I'm not interested in outliers (eg: average volume is of 50k and one day volume is of 45 million, I don't want to factor in that day with 45million volume in my search.)

What would be the best/right way to do this?

what to do with spikes?
1. a volume spike removes the stock from scan result list
2. a volume spike is not included in the volume average formula.

I want to search for stocks that have, in average, 1 million volume in the 50 periods or so. But I'm not interested in outliers (eg: average volume is of 50k and one day volume is of 45 million, I don't want to factor in that day with 45million volume in my search.)

What would be the best/right way to do this?

kkrac,

I've created a script that removes both the highest volume and the lowest volume used to calculate the average volume. Instead of the sum of the latest 50 volumes divided by 50, it is the sum of the middle 48 volumes of those 50 divided by 48.

Interestingly, when a 50 period moving average is used there's not much difference from the original average line, even for GameStop in the chart below where volume showed really big spikes. I changed it from 50 periods to a 10-period average volume and then there were more obvious differences between the normal average and the average without highest and lowest volumes (2nd chart).

In the charts below, the top histogram shows the normal volume average and the bottom one shows the average with high and low excluded.

with a 10 period average:

Code:
``````# VolumeAvg_NoOutliers
# Question from kkrac  4-1-23

declare lower;
declare zerobase;

input length = 50;

def Largest = Highest(volume, length);
def Smallest = Lowest(volume, length);

def Total1 = Sum(volume, length);
def Total2 = Total1 - Largest - Smallest;

plot Vol = volume;
plot AvgNoOutliers = Total2 / (length - 2);

Vol.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Vol.SetDefaultColor(Color.RED);
Vol.SetLineWeight(3);

AvgNoOutliers.SetDefaultColor(Color.BLUE);
AvgNoOutliers.SetLineWeight(2);``````

87k+ Posts
356 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?