Making a 13 over 30 Crossover Scan

leonrossi

New member
Hi All,
I'm new to thinkscript. I would like to create a scan to detect EMA 13 over 30 crossover on the hourly time frame in TOS. I would also like to incorporate the parameter of a stock in an uptrend or downtrend for about 2 weeks before they cross over. I have tried to do this in TOS but i do not get good results. The part that I struggle with is how to capture the stock either in an uptrend or downtrend for about 2 weeks. The idea behind this scan is to spot a momentum stock when it's reversing. Does anyone know how to do this? any help would be greatly appreciated.
 
You can use the ToS scanner and build one. Here is an example:

nZHwdmH.png
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

hi Ben,
That's what I did but I'm not getting good results. The part that I need help with is how do I program to identify stocks that made a strong uptrend or downtrend for about 2 weeks and that's when the momentum is shifting. I wish I could send you an example but I can't upload the image.
 
@leonrossi What is your definition for "strong uptrend or downtrend for about 2 weeks" ? Identify that first. Post a screenshot of your scanner setting. Click here to see instructions for that.
 
these are strong momentum stocks and the plan is to decipher when that momentum is changing and then short it (Put options for a few days) on the pull back and then do the opposite when the cross over happens again.
 
yes, it is to find crossovers but only after the stock has been trending for a while (~about 2 weeks). For example with MTCH above and SPY below, the stock has been on a uptrend for about 2 wks before the cross over happens.
qfwAPr9.png


Thanks for fast response. I really appreciate your feedback.

Leon
 
also, what i find interesting is that momentum stocks tends to find support at the 200 hr moving average (SMA). they tend to bounce off of it and then continue higher.
 
@WOLVES Looks like you've been wanting something like this for a bit. Try this scan code; it should find 13/30 crossovers after two weeks of trend, please read the notes in the code.
Code:
# Hourly Scan for 13/30 Crossover After 2 Weeks
# Scans for crossovers in both directions
# Choose hourly aggregation - Do NOT include extended hours

# 70 is the number of hourly bars that total two weeks - adjust as desired
input bars_since_cross = 70;

# allows a bit of room to scan for the cross - 7 is within the current day
input max_bars_since_cross = 7;

def ma1 = average(close,13);
def ma2 = average(close,30);

def cross_up = ma1 crosses above ma2;
def cross_dn = ma1 crosses below ma2;

def count_after_cross_up = if cross_up and !cross_up[1] then 1
                           else count_after_cross_up[1]+1;
def count_after_cross_dn = if cross_dn and !cross_dn[1] then 1
                           else count_after_cross_dn[1]+1;

def long_entry = count_after_cross_up > bars_since_cross
                 and cross_dn within max_bars_since_cross bars;
def short_entry = count_after_cross_dn > bars_since_cross
                  and cross_up within max_bars_since_cross bars;

plot scan = long_entry or short_entry;

# end scan code
 
@Pensar Thanks for responding. The scanner gives an error:
def long_entry = count_after_cross_up > bars_since_cross
and cross_dn within max_bars_since_cross bars;
def short_entry = count_after_cross_dn > bars_since_cross
and cross_up within max_bars_since_cross bars;

the complier says: no such variable bars_since_cross at 17:42

thanks
 
@Pensar - this is helpful thanks! I was looking for something similar but for Simple Moving Average. I can update the code to reflect this.
The part I am not clear about is the following:

How are you defining 70 as a two week period? Are weekends and pre/post market included in the 70 hour count? Or will this only include the last 10 TRADING DAYS over a 2 week period (excluding pre/post market).

***********************************
"# 70 is the number of hourly bars that total two weeks - adjust as desired
input bars_since_cross = 70;"
 
@omar__naeem The 13/30 crossover scan code already uses the Simple Moving Average (written as "average"), no need to change it.

How are you defining 70 as a two week period? Are weekends and pre/post market included in the 70 hour count?

There are 7 hourly bars each day (when not including extended hours), so I multiplied that number by 10 (the number of trading days in two weeks) to get 70. You can always adjust the code to scan for a different number of bars. No weekends (the stock market is closed). To only scan regular trading hours, you must make certain to de-select the "EXT" box when creating your scan. Hope that helps! :)
 
@Rayanmjr Try creating a scan with this code in ThinkorSwim, then populate the results to a watchlist column. It should update every 3-5 mimutes. I have no idea if custom scan/indicator codes can even be used in StockCharts.
 
Thanks @Pensar. Confirming if it is working correctly - I set the value of input bars_since_cross = 49. However, as you can see in the image below, the cross over is still happening prior to 49 bars...in this case it is 47 and 46 bars and I am seeing quite a few cases that are showing this. Do you know why this would be the case?

Ek4RKZY.png

7fcTTiH.png
 
@omar__naeem The code finds crossovers within a certain amount of bars. So where it says . . .
Code:
# allows a bit of room to scan for the cross - 7 is within the current day
input max_bars_since_cross = 7;
. . . try changing it to 1 instead of 7, let me know if that fixes it.
 
Isn't max_bars_since_cross only for the right side of the cross-over? I.e. Bars since the 2 MAs crossed <= 7? I love that the code accommodates for this. Reducing it below 7 will impact the results but more to do with the right side of the cross-over vs the left which is what I am unable to solve for. Not sure if that makes sense?
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
279 Online
Create Post

Similar threads

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.
Back
Top