Making a 13 over 30 Crossover Scan

L

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.
 
BenTen

BenTen

Administrative
Staff
VIP
You can use the ToS scanner and build one. Here is an example:

 
L

leonrossi

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

BenTen

Administrative
Staff
VIP
@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.
 
L

leonrossi

New member
For uptrend - price trading above 30 EMA but doesn't close below it.


For downtrend - price trading below 30 EMA but doesn't close above it.
 
L

leonrossi

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

BenTen

Administrative
Staff
VIP
But I thought you wanted to find crossovers?
 
L

leonrossi

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


Thanks for fast response. I really appreciate your feedback.

Leon
 
L

leonrossi

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

Pensar

Active member
VIP
@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
 
W

WOLVES

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

Rayanmjr

New member
I would love to see that on a scanner realtime and working any way we can build one? Did you also happen to try building that in stockcharts?
 

Similar threads

Top