#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# "EMA(10) > EMA(30) for X Days"

How do I write a scan function to find "EMA(10) > EMA(30) for X Days" ? ........ Thanks

• edited July 2016 Accepted Answer
If I remember correctly an old answer from @gord, you can determine the position of one ema to another using MACD. So the shorter ema would be above the longer ema when MACD Line is greater than zero

and [MACD Line(10,30,1) > 0]

So, the test for the short ema above the long ema for AT LEAST x days would be a minimum MACD Line value above zero for that length of time.

and [min(30, MACD Line(10,30,1)) > 0]

That says, MACD LIne has been above zero for at least 30 days.

If you want to get the stocks that crossed over EXACTLY x days ago, add this line:

and [min(31, MACD Line(10,30,1)) < 0]

Both conditions together say that MACD Line was below zero exactly one day before (x+1 days ago) it was above zero for the next 30 days.