Price below ema for specified period then crossing above


Category:
0
0

Hi Pete, I am trying to create a script that will find stocks that have been below the 50 Ema for at least 75 bars, but have crossed back over and have remained above the 50 EMA for at least 5 bars.

I came across a scanner you had posted before to scan for stocks that were above the SMA for at least 3 bars and tried to mess with it, but ended up getting pretty stuck so I came here.

Thanks for the help!

Marked as spam
Posted by (Questions: 2, Answers: 0)
Asked on December 8, 2020 5:39 pm
248 views
1
Private answer

I updated the title of your question to something that is more likely to be used by someone searching for this specific solution. User inputs have been included to allow others to adjust this to fit their own needs.

input barsBelow = 75;
input barAbove = 5;
input maLengthOne = 50;
input maTypeOne = AverageType.EXPONENTIAL;
input maPriceOne = close;
def maOne = MovingAverage(maTypeOne, maPriceOne, maLengthOne);
def consecutiveBarsBelow = Lowest(close < maOne, barsBelow) > 0;
rec countBarsAbove = if close < maOne then 0 else if consecutiveBarsBelow[1] and close > maOne then 1 else if countBarsAbove[1] > 0 and close > maOne then countBarsAbove[1] + 1 else countBarsAbove[1];
plot scan = countBarsAbove > barAbove;

Marked as spam
Posted by (Questions: 37, Answers: 4079)
Answered on December 9, 2020 9:29 am
0
Hi Pete, What if I wanted the scan to reflect stocks that have NOT CLOSED above the 50 EMA for 75 bars? Thank you!
( at June 17, 2021 8:41 pm)
0
I do not see a way that can be achieved with this code by adjusting any of the user inputs. So you should consider posting this as a new question.
( at June 17, 2021 8:52 pm)
0
Hi Pete, I changed the inputs to these settings for Bollinger Band but it's not working. I'm getting a whole bunch of stocks that crossed above the mid-line days ago. Ex: MRK, BAC, AMD, NVDA, etc Thanks! input barsBelow = 5; input barAbove = 1; input maLengthOne = 20; input maTypeOne = AverageType.SIMPLE;
( at October 15, 2021 9:59 pm)
0

Change the last line of the scan as follows:

plot scan = countBarsAbove[1] == barAbove and countBarsAbove > barAbove;
( at October 15, 2021 10:08 pm)
0
Sorry Pete, but it's still not working. Still showing results of already crossed for a few days.
( at October 16, 2021 12:48 pm)
0
Sorry about that. For some reason the code I included in that last comment was destroyed by the process of saving the comment. I think I have found a way to force that through without it being destroyed. Try it again.
( at October 16, 2021 5:09 pm)