scan stocks 13 ema always above 34 ema for the past 100 or 200 days


Category:
0
0

Hi Pete

Is it possible to scan for stocks that meet the following criteria:

– 13 ema is always above 34 ema for the past 100/200/300 days. 

Thanks a lot!

Marked as spam
Posted by (Questions: 1, Answers: 2)
Asked on May 24, 2020 4:00 pm
123 views
0
Private answer

The code below includes user inputs so that you can change all aspects of the moving averages. So this can be applied to virtually all variations users may want to deploy.

The trick is to use the exact opposite of the condition you want. The scan statements in the code below check if the opposite condition has been false for all of the previous x bars. These use a default value of 100 bars. Adjust that value to whatever length you require.

input maLengthOne = 13;
input maTypeOne = AverageType.EXPONENTIAL;
input maPriceOne = close;
input maLengthTwo = 34;
input maTypeTwo = AverageType.EXPONENTIAL;
input maPriceTwo = close;
def maOne = MovingAverage(maTypeOne, maPriceOne, maLengthOne);
def maTwo = MovingAverage(maTypeTwo, maPriceTwo, maLengthTwo);
def stackedAbove = maOne > maTwo;
def stackedBelow = maOne < maTwo;
# use this to scan for maOne above maTwo for previous x bars
plot scan = Highest(stackedBelow, 100) == 0;
# use this to scan for maOne below maTwo for previous x bars
#plot scan = Highest(stackedAbove, 100) == 0;

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on May 24, 2020 5:01 pm
0
works like a charm. thnx a ton!
( at May 24, 2020 9:29 pm)
0
interestingly I found that the scan missed some stocks. for example, 13 ema is always above 34 ema on the weekly chart of MSFT but MSFT does not show up in the scan result. not sure what causes this. although there are a few bars where the 13 ema of MSFT is very close to 34 ema.
( at May 24, 2020 10:00 pm)
0
Depends on the number of bars you are using to check for this condition. On a weekly time frame the scan engine only has access to 2 years of historical data. So anything more than 104 weekly bars it beyond the reach of scans using the weekly time frame on Thinkorswim.
( at May 25, 2020 10:28 am)