Daily 8 EMA below 21 last 3 months


Category:
0
0

Hi Pete,

How would I scan for stocks where the daily 8 EMA has been below the 21 EMA for the previous 3 months?

Thanks again!

Marked as spam
Posted by (Questions: 20, Answers: 27)
Asked on March 20, 2020 7:25 am
66 views
0
Private answer

Here is the code for that:

input numberOfDays = 63;
input maLengthOne = 8;
input maTypeOne = AverageType.EXPONENTIAL;
input maPriceOne = close;
input maLengthTwo = 21;
input maTypeTwo = AverageType.EXPONENTIAL;
input maPriceTwo = close;
def maOne = MovingAverage(maTypeOne, maPriceOne, maLengthOne);
def maTwo = MovingAverage(maTypeTwo, maPriceTwo, maLengthTwo);
def undesirableCondition = maOne > maTwo;
plot scan = Highest(undesirableCondition, numberOfDays) < 1;

Be sure to apply this to a daily time frame. I'll take a few minutes to explain some of this.

  1. User input numberOfDays defaults to 63 because on average there are 21 trading days in any giving month
  2. undesriableCondition is the fast ema above the slow ema (the condition we do NOT want to appear in the previous x number of bars). Its either a 1 (fast ema above slow ema) or a zero (fast ema below the slow ema).
  3. The scan signal checks for the highest value of that undesirable condition in the previous x number of bars.  So as long as highest value for that number of bars is less than 1, we know that the undesirable condition has not been true during that span of bars.
Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on March 20, 2020 1:17 pm
0
Thank you Pete! How would I add either close is less than or within 1% of the 8 EMA?
( at March 20, 2020 9:54 pm)
0
def withinPercent = close < maOne and close >= maOne * 0.99;
( at March 21, 2020 8:24 am)
0
The scan return SPR, DD, GT, DK but none is within 1% of its 8 EMA. Would you know why this is?
( at March 21, 2020 1:00 pm)
0
none of those show up in my scan results. Are you running this on a Daily time frame? Did you include the new criteria in the final plot statement? plot scan = withinPercent and Highest(undesirableCondition, numberOfDays) < 1;
( at March 21, 2020 3:22 pm)