#### Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.

# scan for ranges

Hi there, how would i set up a scan where i look for stocks that have been consolidating in a range/tight range for X amount of time?

• ✭✭
like a bollinger band squeeze?
• mod
edited March 2021
B Bands are a good way to do it.

Another way might be Price Channels. Choose a channel length, a per cent difference ( e.g. upper - lower divided by lower less than, say, 1 per cent) and today's upper = x days ago upper and today's lower = x days ago lower - where the x is less than the length of the channel - so maybe 15 days ago for a 20 day channel.

You would have to play around with it quite a bit to get what you like. Run it for dates in the past to see what happens after the scan conditions are met.
• thanks markd i like the idea of price channels, where can i find the literature which will teach me to create the code?
• so i can take a stab at it
• mod
edited March 2021
Chart School has a page on Technical Indicators and Overlays with links to each one. The Price Channel page (one of the Overlay links) has sample code you can adapt:

https://school.stockcharts.com/doku.php?id=technical_indicators:price_channels
• Ok so to create a channel
[Upper Price Chan(20) > close]
[Lower Price Chan(20) < close]

This formulation says that price for the last 20 days is in between a range, right?

and [Upper Price Chan(20) > close]
and [Lower Price Chan(20) < close]

Is that correct, that just catches any 20day range?
• Once, i know that's correct then i want to add some info so i filter for x% ranges, i.e. a 10% range

then i want to add another statement which says that price is close to the bottom of the range, or price is close to the top of the range.....is that possible using a stochastic statement?
• mod
The close is almost always between the Upper and Lower Channels, so you don't have to specify that's where the close is (the exception would be if it closes at the bar's high or low and the high or low is equal to the channel).

To test for the width of the range, you have to compare the difference between the upper and lower channels
(Upper Price Chan(20) - Lower Price Chan(20)) to the Lower Price Chan value - so -

and [Upper Price Chan(20) - Lower Price Chan(20) < Lower Price Chan(20) * .1]

To locate the current close in the price channel, you can use Fast Stochastics. For instance, to find closes below the middle of the channel

and [Fast Stoch %K(20,1) < 50]