New Members: Be sure to confirm your email address by clicking on the link that was sent to your email inbox. You will not be able to post messages until you click that link.
Options

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

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

Best Answer

  • Options
    markdmarkd mod
    edited July 2016 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.

Answers

  • Options
    Hi markd. As you said: and [min(30, MACD Line(10,30,1)) > 0] is for "AT LEAST" 30 days, but it could also be for more than 30 days.

    Can you write the scan to find stocks when the crossover happens sometime within a MAXIMUM of 30 days, since you may not be interested in the stock if it happens AFTER that time?

    You can tediously cut & paste 1 day ago, 2 days ago, etc. down to 30 days, but is this the only way you can write the scan, to catch a stock that crossovers within a short period of time?
  • Options
    I think you would want to decide what is the optimal number of days for the shorter ema to be above the longer, write the scan for a crossover that number of days ago. then run that scan daily. Or, if that's not feasible, and you are flexible about the optimal number of crossed over bars, you can use the calendar tool to offset the run date for the scan (e.g. as of 1 day ago, two days ago, etc.). Or write a scan for just the crossover itself, and use the offset scan date to review the recent past. That seems easiest and most flexible.
Sign In or Register to comment.