Scan for price touching moving average in ThinkorSwim

jas

New member
I need a Thinkorswim scanner which scan stocks whose last few previous daily bar's open, close, low or high touches or almost too close to desired moving averages means act as support or resistance. Can also able to scan for at least 2 different moving averages in a scan so that scan will return stocks which touches either of 2 moving averages.
 

tomsk

Well-known member
VIP
I'll respond on behalf of @BenTen

Scanning for stocks need to be very clearly defined. Your description above is imprecise and won't mean anything to the scanner
For example you can say something like the close crosses above the 34 EMA during yesterday's close
Once you have a clear definition, scanning for that will be easy
Help us so that someone can help you
 
Last edited:

jas

New member
Hi Tom,

Basically looking stocks whose previous last 1-4 daily bar's open, close, high or low is very close to particular moving average which means that it acts as base.

XXAPRsFg.jpg


Please check image and I have highlighted points
 

tomsk

Well-known member
VIP
You really need to define "very close" because different traders have different interpretations of what "very close" means to them
That said, assume you want to scan for stocks with a price within $0.50 of say the 21 EMA
Here is your scan code to do so.

Code:
def EMA = ExpAverage(close, 21);
plot scan = between(close, EMA-0.50, EMA+0.50);
 

jas

New member
Hi Tom,

Actually looking for scan which return stocks whose previous one to four daily candles either open, close, low or high touches desired moving average. Also I need unusual volume in scan and distance between 2 moving average is narrowing. Please see image below for reference as I highlighted for what I am looking for?

wk8Z1VU.jpg


Thanks
 

tomsk

Well-known member
VIP
Having these sorts of moving averages criss-crossing each other does not give any clear signal
Worse it may give you false positives. Probably better to wait for a clearer direction.

However since you wanted it, here is an EMA Convergence scan using 8,13,21 periods
I obtained 218 results on the scanner, scanning against the S&P 500.

Code:
# EMA Convergence Scan
# tomsk
# 12.5.2019

# Scan for convergence between EMA 8,13,21

input length1 = 8;
input length2 = 13;
input length3 = 21;

def ema1  = ExpAverage(close, length1);
def ema2  = ExpAverage(close, length2);
def ema3  = ExpAverage(close, length3);

def cond1  = between(ema1, close * .995, close * 1.005);
def cond2  = between(ema2, close * .995, close * 1.005);
def cond3  = between(ema3, close * .995, close * 1.005);

plot scan = cond1 + cond2 + cond3;
# End EMA Convergence Scan
 

jas

New member
Thanks Tom,

Actually, I am looking for scan where daily candle's either high, low, close or low is touching desired moving average. For reference, please see picture below.

5I0ixIh.jpeg
 

tomsk

Well-known member
VIP
Unfortunately I need to move on to other pressing projects. You weren't clear from the get go. I really don't see the point of the request.
 

BenTen

Administrative
Staff member
Staff
VIP
Lifetime
Like @tomsk said, you were not specific about your request from the beginning. That makes it harder for us to help. After reading your questions multiple times, I hope I understand it correctly. You can scan for stocks that are crossing a moving average. @jas I believe you can do that using the default Scanner in ThinkorSwim. You just have to build one using their Scan Editor. It's as simple as the following:

T2K35Gg.png


The snippet for that would be:

Code:
close crosses SimpleMovingAvg("length" = 21)."SMA"

When running this on the daily chart, it will return any stocks with the close crossing above or below the 21 simple moving average.
 

ezrollin

Member
How would I scan for price touching the 50 SMA on the daily but is staying above it? Thanks

close is equal to SimpleMovingAvg("length" = 50)."SMA" within 1 bars
 
Last edited:

cdjohnson73

New member
My question is: is there a way to modify the second code so that it can highlight the setup of my first code?
Code:
close("period" = AggregationPeriod.MIN, "priceType" = PriceType.LAST) crosses above MovAvgExponential()."AvgExp" within 2 bars
I have another code for seeing the percent change over 1 minute which is:
Code:
def bk = close; def change = 100*(1-bk/bk[1]); plot signal = change; signal.AssignValueColor (Color.BLACK); AssignBackgroundColor( if change > 10 then color.green else if change >5 then color.light_green else Color.light_GRAY);
 
Last edited by a moderator:

Pensar

Well-known member
VIP
Lifetime
Hey all, apologies for the confusion and thank you for taking the time to tell me what I was missing. My current code is:
Code:
close("period" = AggregationPeriod.MIN, "priceType" = PriceType.LAST) crosses above MovAvgExponential()."AvgExp" within 2 bars
I have another code for seeing the percent change over 1 minute which is:
Code:
def bk = close; def change = 100*(1-bk/bk[1]); plot signal = change; signal.AssignValueColor (Color.BLACK); AssignBackgroundColor( if change > 10 then color.green else if change >5 then color.light_green else Color.light_GRAY);
My question is: is there a way to modify the second code so that it can highlight the setup of my first code? Sorry for doing it wrong I hope this is correct
@cdjohnson73 Where are you trying to use this code?

If in a scan, try close crosses above expaverage(close,14) within 2 bars and select the necessary aggregation to scan from the dropdown menu. The default length you are referencing for the EMA is 14, in case you're wondering why I chose that length. Remember that scans only update every 3 minutes or so at best, so using a 1 min agg might not work very well.

If in a watchlist column -
Code:
def data = close crosses above expaverage(close,14) within 2 bars;
AddLabel(1,if data then "Crossing" else "", if data then color.green else color.black);
AssignBackgroundColor(if data then color.green else color.black);
This will color both the text and the background green when the conditions are true. you can change the quoted text in the label to display whatever you want, as well as the color. Select the necessary aggregation for the column from the dropdown menu.

I havent tested any of this code, so make sure it works.
 

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