Scan for stocks whose price is between two MAs

D

dhman06

New 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.
 
rad14733

rad14733

Well-known member
VIP
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);
 
D

dhman06

New member


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:
D

dhman06

New member
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
 
D

dhman06

New member
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
 
rad14733

rad14733

Well-known member
VIP
Power is out due to a storm... I intend to supply another version using a different EMA once power is restored...
 
D

dhman06

New member
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

 
rad14733

rad14733

Well-known member
VIP
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...
 
D

dhman06

New member
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?
 
rad14733

rad14733

Well-known member
VIP
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... 💡
 
D

dhman06

New member
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
 
rad14733

rad14733

Well-known member
VIP
@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... (y)

Keep at it... ;)
 
D

dhman06

New member
@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... (y)

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?
 
rad14733

rad14733

Well-known member
VIP
Have you tested the code...??? I assumed that you had and were getting the desired results... I'll give it a go...
 
D

dhman06

New member
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
 
rad14733

rad14733

Well-known member
VIP
@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
 
D

dhman06

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

dhman06

New member
@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?
 

Similar threads

Top