# Scan for stocks whose price is between two MAs

#### dhman06

##### Member
Hello all,

I would like to create a scan that lists all stocks whose price is within two MAs: current price is between the High of 3EMA and Close of 8EMA

Is there a way to create that sort of scan in TOS? I wish I could code that up, but I'm not smart enough. Any help would be greatly appreciated.

Hello all,

I would like to create a scan that lists all stocks whose price is within two MAs: current price is between the High of 3EMA and Close of 8EMA

Is there a way to create that sort of scan in TOS? I wish I could code that up, but I'm not smart enough. Any help would be greatly appreciated.
Here is a start...

Code:
``plot ema2Band = close between EMA2("data" = CLOSE, "prefetch" = 3, "smoothing factor" = 0.1) and EMA2("data" = CLOSE, "prefetch" = 8, "smoothing factor" = 0.1);``

Essentially what I'm trying to do is catch stocks that have last prices in between high of 3EMA and close of 8EMA. For example: price here is 214.57, 3EMA high is 217.62 and 8EMA close is 212.28

Last edited:
Here is a start...

Code:
``plot ema2Band = close between EMA2("data" = CLOSE, "prefetch" = 3, "smoothing factor" = 0.1) and EMA2("data" = CLOSE, "prefetch" = 8, "smoothing factor" = 0.1);``

What does the smoothing factor do?

Also should I be using prefetch? It seems like it refers to historical data. I'm not sure how it will be helpful

So, this is what I've got so far:

Code:
``````input fastprice = high;
input fastlength = 3;
input slowprice = close;
input slowlength = 8;
input averageType = AverageType.EXPONENTIAL;

plot fastma = MovingAverage(averageType,fastprice, fastlength);
plot slowma = MovingAverage(averageType,slowprice,slowlength);``````

but I can't figure out how to spot stock that are in between high of 3EMA and close of 8EMA. Any help will be really appreciated

Power is out due to a storm... I intend to supply another version using a different EMA once power is restored...

Power is out due to a storm... I intend to supply another version using a different EMA once power is restored...

I took a stab at it on TOS scanner function and came up with this. Is someone can confirm if I did this right or suggest a better way to improve it to match my goal that'll be greatly appreciated

Please post the entire block of Thinkscript code by switching to the Thinkscript Editor mode and doing a Copy & Paste within code tags via </> from the toolbar... We need to see the entire code block to give an accurate answer... We can also test it for errors...

Please post the entire block of Thinkscript code by switching to the Thinkscript Editor mode and doing a Copy & Paste within code tags via </> from the toolbar... We need to see the entire code block to give an accurate answer... We can also test it for errors...

I didn't write any code. I added study filters. Is there anyway to convert those to codes?

I didn't write any code. I added study filters. Is there anyway to convert those to codes?
Yes, as I described in my previous post you can access the code using the Thinkscript Editor button...

Yes, as I described in my previous post you can access the code using the Thinkscript Editor button...

Found what you were talking about. Another new thing that I've learned. Thank you. So I have this ---

MovAvgExponential("price" = HIGH, "length" = 3)."AvgExp" is greater than or equal to MovAvgExponential("length" = 8)."AvgExp" within 2 bars and MovAvgExponential("length" = 8)."AvgExp" is greater than MovAvgExponential("length" = 17)."AvgExp" within 2 bars and MovAvgExponential("price" = HIGH, "length" = 3)."AvgExp" is greater than close and MovAvgExponential("length" = 8)."AvgExp" is less than close("priceType" = PriceType.LAST)

And I combined this with 50period simple volume for the last 4 bars:

VolumeAvg()."VolAvg" is greater than 350000 within 4 bars

@dhman06

There you go...!!! I love it when people take nudges and hints and expound upon them in a learning manner... I'm sure it feels much more rewarding than just having results handed to you...

Keep at it...

@dhman06

There you go...!!! I love it when people take nudges and hints and expound upon them in a learning manner... I'm sure it feels much more rewarding than just having results handed to you...

Keep at it...

What do you think about the code though? Do you think I was able to curve up what I'm trying to achieve though?

Have you tested the code...??? I assumed that you had and were getting the desired results... I'll give it a go...

Have you tested the code...??? I assumed that you had and were getting the desired results... I'll give it a go...

I'm not sure how to test the code in TOS. Any hint will be much appreciated

@dhman06

Well, I included the VolumeAvg() with your other criteria and get 746 results... Not sure if you want to filter further or not but it produces results... The code below was copied from the Thinkscript Editor panel and is editable using the Conditional Wizard...

Code:
``MovAvgExponential("price" = high, "length" = 3)."AvgExp" is greater than or equal to MovAvgExponential("length" = 8)."AvgExp" within 2 bars and MovAvgExponential("length" = 8)."AvgExp" is greater than MovAvgExponential("length" = 17)."AvgExp" within 2 bars and MovAvgExponential("price" = high, "length" = 3)."AvgExp" is greater than close and MovAvgExponential("length" = 8)."AvgExp" is less than close("priceType" = PriceType.LAST) and VolumeAvg()."VolAvg" is greater than 350000 within 4 bars``

I'm not sure how to test the code in TOS. Any hint will be much appreciated
I created the code in the Scan > Custom Study > Conditional Wizard and then Ran the Scan...

@rad14733 That's interesting. The code I pasted here returned 355 results. Let me compare results from your code to my code.

@dhman06

Well, I included the VolumeAvg() with your other criteria and get 746 results... Not sure if you want to filter further or not but it produces results... The code below was copied from the Thinkscript Editor panel and is editable using the Conditional Wizard...

Code:
``MovAvgExponential("price" = high, "length" = 3)."AvgExp" is greater than or equal to MovAvgExponential("length" = 8)."AvgExp" within 2 bars and MovAvgExponential("length" = 8)."AvgExp" is greater than MovAvgExponential("length" = 17)."AvgExp" within 2 bars and MovAvgExponential("price" = high, "length" = 3)."AvgExp" is greater than close and MovAvgExponential("length" = 8)."AvgExp" is less than close("priceType" = PriceType.LAST) and VolumeAvg()."VolAvg" is greater than 350000 within 4 bars``

Is it possible to take your code and make an indicator? For example, an arrow sign would show up if the criteria is met and I can set an alert for that arrow?

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