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.

scanning formula for stocks under moving average

I am looking for the scan formula to find stocks that have been below their 50-day moving average for at least 85% of the time over the past two years


  • There are so many ways that could happen, that writing a scan for that specific requirement would pretty complex.

    But, in most normally behaving stocks, the stock would have to be in a long term down trend. This is an off-the-top of my head approach to capture that condition:

    and [ROC(251) < 0]
    and [251 days ago ROC(251) < 0]

    So, in other words, for two years (not necessarily calendar years) in a row, the stock has lost ground between the beginning and end of a 251 day period. That allows for a lot of fluctuation, but overall the trend will be down.

    Very rough and ready, but maybe a useful starting point.
  • how would I add additional criteria such as it is now risen above its 30 day moving average for 30 days
  • Well, if you are ok with emas instead of smas, there is a trick you can use with MACD Hist.

    Set up a chart with MACD Hist(1,30,0) instead of the default parameters. With these parameters, the Hist bar represents the distance between the close and the ema. When the close (ema(1, close)) is above the ema(30, close), the Hist bar is positive (above the zero line).

    To scan for the close above the zero line for 30 days, you would scan for

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

    In other words, the smallest difference between the close and the ema is not less than (or equal to) zero.

    Then you would have to test for the close below the ema 31 days ago, so

    and [30 days ago close < 31 days ago ema(30)]

    or you could say

    and [31 days ago MACD Hist(1,30,0) < 0]

    same thing.
  • so to conclude i join these two formulas and [ROC(251) < 0]
    and [251 days ago ROC(251) < 0] and [30 days ago close < 31 days ago ema(30)]
  • You also need the MACD Hist. Also, days ago should both be 31 for close and ema.
Sign In or Register to comment.