Need Scan to find close between 50/21 moving averages

philsy13

New member
I'd like to find a code that will allow me to scan for price trending between two moving averages. EMA 50 and 21. Essentially, it would find stocks within two moving averages prior to a significant move in either direction. Any help would be most appreciated!
 

amcno03

New member
Hi @philsy13 here is the link with the scanner you've asked for: https://tos.mx/xcWRsK9



and also an indicator to show the candles that meet the criteria: https://tos.mx/I77rEEE

And the code. Bear in mind that it shows candles closing above EMA21 and below EMA50. IF you want it to show candles closing above EMA50 and below EMA21, just change the "def con1" for this line: def cond1= close is greater than AvgExp50 and close is less than avgexp21;

Code:
input price = close;
input length = 21;


plot AvgExp21 = ExpAverage(price, length);

input price1 = close;
input length1 = 50;


plot AvgExp50 = ExpAverage(price1, length1);

def cond1=  close is greater than AvgExp21 and close is less than avgexp50;
plot signal = cond1;
signal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_aRROW_UP);
signal.SetDefaultColor(Color.White);
signal.SetLineWeight(5);

signal.DefineColor("signal", Color.darK_ORANGE);

AssignPriceColor(if signal == 1 then signal.color("Signal") else Color.CURRENT);



Hope It helps,
Best regards.
ps: English is not my mother tongue; please excuse any errors on my part.
 
Last edited:

philsy13

New member
Hi @philsy13 here is the link with the scanner you've asked for: https://tos.mx/xcWRsK9



and also an indicator to show the candles that meet the criteria: https://tos.mx/I77rEEE

And the code. Bear in mind that it shows candles closing above EMA21 and below EMA50. IF you want it to show candles closing above EMA50 and below EMA21, just change the "def con1" for this line: def cond1= close is greater than AvgExp50 and close is less than avgexp21;


Code:
input price = close;
input length = 21;


plot AvgExp21 = ExpAverage(price, length);

input price1 = close;
input length1 = 50;


plot AvgExp50 = ExpAverage(price1, length1);

def cond1=  close is greater than AvgExp21 and close is less than avgexp50;
plot signal = cond1;
signal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_aRROW_UP);
signal.SetDefaultColor(Color.White);
signal.SetLineWeight(5);

signal.DefineColor("signal", Color.darK_ORANGE);

AssignPriceColor(if signal == 1 then signal.color("Signal") else Color.CURRENT);



Hope It helps,
Best regards.
ps: English is not my mother tongue; please excuse any errors on my part.

You did a great job! Thank you! I'm adapting it to my trading style.
 

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

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?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Top