# Scan for stocks with consecutive close above SMA

#### Miket

##### Member
How would you go about scanning for stocks in TOS that have had 7 consecutive closes above their 5 sma?

How would you go about scanning for stocks in TOS that have had 7 consecutive closes above their 5 sma?

@Miket Here's your scan for 7 consecutive closes above SMA (5)
Just place this in the scanner directly

sum(close > Average(close,5), 7) >= 7

Last edited:
Someone's studying LBR Good stuff

@hashy Yes, this style speaks to me

@hashy Yes, this style speaks to me
Same. She's amazing. So much good stuff buried in some of her obscure YouTube lectures.

She is hosting a free webinar Dec 4th "Linda Raschke- Accelerating your Evolution as a Trader"

She is hosting a free webinar Dec 4th "Linda Raschke- Accelerating your Evolution as a Trader"
Damn, just seeing this and looks like I missed it. Hopefully she releases a recording. Thanks for the heads up.

Last edited:
My question is how do I run a scan in TOS where I can find stocks that closed above the 20 SMA for 3 days in a row?
Thanks for any help.

Place this code directly into the scanner, it does precisely what you are looking for - at least 3 consecutive closes above SMA(20). Make sure you use the daily aggregation

Code:
``sum(close > Average(close,20), 3) >= 3``

@BenTen Good of you to move this here, sure seems like lots of work (from a moderator's point of view)

@tomsk Thank you so much it worked great. I ran another scan by changing to 20 to 5 and got a lot of interesting possibilities for the next trading day.

@Miket Here's your scan for 7 consecutive closes above SMA (5)
Just place this in the scanner directly

sum(close > Average(close,5), 7) >= 7
this is just what I was looking for and I have been trying to add input variables for
the number of days and average value can you give some guidance to that? Thank You

@BenTen
I was trying this regarding the code in this thread but my if seems to be wrong

Code:
``````def nDays = Integer();
def AvgDays = Integer();
def ConsDays = Boolean();
input AvgDays =5;
input nDays =7;

if sum(close > Average(close,5), nDays) >= NDays
then ConsDays.true
else ConsDay.False``````

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