# scan for narrow range candle sticks

#### Fernwood

##### New member
Would anyone be able to help with a scan for narrow range candle sticks? Basically 20ma and 200ma tightening with candlesticks in-between?

Solution
I was actually watching those exact videos and was wondering how one could scan for something like this

Because Mr. Velez doesn't define the narrow state exactly, here's a scan for stocks where the 20 Period Simple Moving Average and 200 period Simple Moving Average are within 5% deviations of each other, based on a comment by EnclaveDCLXVI in the Youtube comment section:

"There seems to only be one missing ingredient; the scan. Too many results for a 5% max deviation between the moving averages. There's more needed to this set-up than is recorded... the scan.

Note that the charts in his examples have extended-hours OFF.

SCAN
Code:
``````# scan for 20 SMA is within 5% deviation of the 200 SMA
# by...``````

##### Member
Would anyone be able to help with a scan for narrow range candle sticks? Basically 20ma and 200ma tightening with candlesticks in-between?

Don't yet have enough information to assist you.

1) Your definition of "narrow", "in-between" and "tightening"
2) when you say MA, are you referring to the simple moving average, or one of the exotic exponential, double exponential, triple exponential, hull, etc?
3) Picture(s) that include the narrow, inbetween, and tightening
4) What you've done so far

I know of an Oliver Velez who talks about a "narrow state" that involves the 20 period simple moving average and the 200 period simple moving average, but the examples he posts are "subjective" and he doesn't define it precisely. It feels like "you know it when you see it". What you've provided so far is also subjective, so need some objective criteria in what you mean by narrow (error, deviation, percentile, etc.), in-between (above, below, etc.), tightening (what exactly is tightening?) etc. that can be relayed to ThinkOrSwim.

Last edited by a moderator:

#### moxiesmiley

##### Member
def SMA200 = SimpleMovingAvg(price=close, length=200);
def SMA20 = SimpleMovingAvg(price=close, length=20);

if SMA200 crosses above SMA20 then 1 else 0;
#if SMA20 crosses above SMA200 then 1 else 0;
#if SMA20 crosses SMA200 then 1 else 0;

#### al cuervo

##### New member
can you specify something like sma20 crosses above sma200 but is less than 3% away from it ( that would specify the narrow space between them)

#### moxiesmiley

##### Member
can you specify something like sma20 crosses above sma200 but is less than 3% away from it ( that would specify the narrow space between them)
You could but I couldn't really see the purpose. Different time frames would return different results. So you would have to stick to one time frame, scan within 3% and (i believe) combine it with a study library (bollinger bands, keltner channels, etc). That would be my first approach

Maybe...
if SMA200 && SMA20 is within/between value=.3 then 1 else 0;

but if you change time frames it would return different results.

#### al cuervo

##### New member
thanks appreciate that, can that same within/between value be use to track the last 30 minutes of the previous day?

#### al cuervo

##### New member
I meant the High and Low of the last 30 minutes being within the same 3%

#### moxiesmiley

##### Member
thanks appreciate that, can that same within/between value be use to track the last 30 minutes of the previous day?
Yeah. Although its pseudo code, so its more of a blueprint and wouldnt execute proper. And HIGH && LOW are different than moving averages. Looking into "high()", "low()", "getHighest()" and "getLowest()".

#### Fernwood

##### New member
def SMA200 = SimpleMovingAvg(price=close, length=200);
def SMA20 = SimpleMovingAvg(price=close, length=20);

if SMA200 crosses above SMA20 then 1 else 0;
#if SMA20 crosses above SMA200 then 1 else 0;
#if SMA20 crosses SMA200 then 1 else 0;
thank you for the attempt, this returned error. something missing?

#### Fernwood

##### New member
Don't yet have enough information to assist you.

1) Your definition of "narrow", "in-between" and "tightening"
2) when you say MA, are you referring to the simple moving average, or one of the exotic exponential, double exponential, triple exponential, hull, etc?
3) Picture(s) that include the narrow, inbetween, and tightening
4) What you've done so far

I know of an Oliver Velez who talks about a "narrow state" that involves the 20 period simple moving average and the 200 period simple moving average, but the examples he posts are "subjective" and he doesn't define it precisely. It feels like "you know it when you see it". What you've provided so far is also subjective, so need some objective criteria in what you mean by narrow (error, deviation, percentile, etc.), in-between (above, below, etc.), tightening (what exactly is tightening?) etc. that can be relayed to ThinkOrSwim.

I was actually watching those exact videos and was wondering how one could scan for something like this

#### moxiesmiley

##### Member
I was actually watching those exact videos and was wondering how one could scan for something like this
You know, its the pressure of the pen creating the width. There is no difference from %10 or %.03 in the video. The point he is showing when the lines cross

#### al cuervo

##### New member
I believe the point of finding stocks where the sma20 and sma200 are close together is that when a move is initiated from this state, they tend to be more explosive with a bigger up or down move than usual. If also the price of the last 30 minutes of previous day (high price and low price) are also close it makes it Ideal an similar situation as an opening day breakout except this starts 30 mins from previous day.
The way it works is if the price opens above the trap zone created by ( 1. high of last 30 mins, 2. low of last 30mins, 3. 20sma & 4. 200sma ) then is buying bias if price is within the trap zone do nothing and if price is below the trap zone is a selling bias.

#### moxiesmiley

##### Member
I believe the point of finding stocks where the sma20 and sma200 are close together is that when a move is initiated from this state, they tend to be more explosive with a bigger up or down move than usual. If also the price of the last 30 minutes of previous day (high price and low price) are also close it makes it Ideal an similar situation as an opening day breakout except this starts 30 mins from previous day.
The way it works is if the price opens above the trap zone created by ( 1. high of last 30 mins, 2. low of last 30mins, 3. 20sma & 4. 200sma ) then is buying bias if price is within the trap zone do nothing and if price is below the trap zone is a selling bias.
Ah gotcha, interesting strategy. I might look into this more

#### al cuervo

##### New member
Don't know if this will help but been thinking about it a lot, what if the scan is on the daily (since you said it would change in different TF) and the parameters would be the high and low price of the previous day last 30 min, where we can input the price value of the difference between the high and low that we would like to see (like show only if difference between high and low is .75, depending on the price range were looking for) and then is only true if the 20sma and the 200sma are within that range and then the study would plot it in the chart like a opening range breakout

I can't script to save my life just trying to help!

#### moxiesmiley

##### Member
Don't know if this will help but been thinking about it a lot, what if the scan is on the daily (since you said it would change in different TF) and the parameters would be the high and low price of the previous day last 30 min, where we can input the price value of the difference between the high and low that we would like to see (like show only if difference between high and low is .75, depending on the price range were looking for) and then is only true if the 20sma and the 200sma are within that range and then the study would plot it in the chart like a opening range breakout

I can't script to save my life just trying to help!
That is possible. My SecondsTillTime() programming isn't that get ATM, i might try to do this in future as practice

##### Member
I was actually watching those exact videos and was wondering how one could scan for something like this

Because Mr. Velez doesn't define the narrow state exactly, here's a scan for stocks where the 20 Period Simple Moving Average and 200 period Simple Moving Average are within 5% deviations of each other, based on a comment by EnclaveDCLXVI in the Youtube comment section:

"There seems to only be one missing ingredient; the scan. Too many results for a 5% max deviation between the moving averages. There's more needed to this set-up than is recorded... the scan.

Note that the charts in his examples have extended-hours OFF.

SCAN
Code:
``````# scan for 20 SMA is within 5% deviation of the 200 SMA
# References:
# Note: 2 minute time frame, extended hours = OFF

input shortLength = 20;
input longLength = 200;
input deviations = 0.05; #5 %
def SMA20 = Average(close, shortLength);
def SMA200 = Average(close, longLength);

def stdDeviation = StDevAll(SMA200);

def UpperLine = SMA200 + deviations * stdDeviation;
def LowerLine = SMA200 - deviations * stdDeviation;

plot scan = SMA20 <= UpperLine && SMA20 >= LowerLine;``````

UPPER STUDY
Code:
``````# upper study for 20 SMA is within 5% deviation of the 200 SMA
# References:
# 2 minute chart
# turn off extended hours

input shortLength = 20;
input longLength = 200;
input deviations = 0.05; #5 %
plot SMA20 = Average(close, shortLength);
plot SMA200 = Average(close, longLength);
SMA20.SetDefaultColor(Color.CYAN);
SMA200.SetDefaultColor(Color.Red);

def stdDeviation = StDevAll(SMA200);

plot UpperLine = SMA200 + deviations * stdDeviation;
plot LowerLine = SMA200 - deviations * stdDeviation;
UpperLine.SetDefaultColor(Color.White);
LowerLine.SetDefaultColor(Color.White);``````

I ran the scan just now on the S&P 500 (evening of 2/10/2022), and returned one stock: KMB

In the image,
RED LINE = 200 sma
WHITE LINES = 5% deviation of the 200 SMA.
CYAN LINE = 20 SMA