I was actually watching those exact videos and was wondering how one could scan for something like this
# scan for 20 SMA is within 5% deviation of the 200 SMA
# by...
Would anyone be able to help with a scan for narrow range candle sticks? Basically 20ma and 200ma tightening with candlesticks in-between?
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 approachcan you specify something like sma20 crosses above sma200 but is less than 3% away from it ( that would specify the narrow space between them)
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()".thanks appreciate that, can that same within/between value be use to track the last 30 minutes of the previous day?
thank you for the attempt, this returned error. something missing?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;
I was actually watching those exact videos and was wondering how one could scan for something like thisDon't yet have enough information to assist you.
Can you please share:
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.
![]()
def SMA200 = SimpleMovingAvg(price=close, length=200);thank you for the attempt, this returned error. something missing?
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 crossI was actually watching those exact videos and was wondering how one could scan for something like this
Ah gotcha, interesting strategy. I might look into this moreI 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.
That is possible. My SecondsTillTime() programming isn't that get ATM, i might try to do this in future as practiceDon'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!
I was actually watching those exact videos and was wondering how one could scan for something like this
# scan for 20 SMA is within 5% deviation of the 200 SMA
# by: tradecombine
# References:
# https://usethinkscript.com/threads/scan-for-narrow-range-candle-sticks.9764
# https://www.youtube.com/watch?v=Lqbbxxp6Xvc
# 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 for 20 SMA is within 5% deviation of the 200 SMA
# by: tradecombine
# References:
# https://usethinkscript.com/threads/scan-for-narrow-range-candle-sticks.9764
# https://www.youtube.com/watch?v=Lqbbxxp6Xvc
# 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);
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
D | scan for a narrow price range | Questions | 1 | |
C | +/- 4% Price Change Scan | Questions | 2 | |
![]() |
Scan for price range/duration? | Questions | 1 | |
![]() |
Conditional scan if ticker is greater than specific price | Questions | 2 | |
D | Custom Filter for scan that excludes Stocks that had recent Earnings | Questions | 1 |
Start a new thread and receive assistance from our community.
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.
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.