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.

MA Moving Closer Together

edited January 2022 in Scanning
Hi trying to write the following scan:
2 moving averages are closer today than they were 3 days ago

I tried PctDiff:
[PctDiff(SMA(50,close), SMA(200,CLOSE)) < PctDiff(3 days ago SMA(50,close),3 days ago SMA(200,CLOSE))]

Is this is right approach? Most of the scan results look right but a couple of the charts appear to show divergence
Thanks!

Comments

  • There are actually four ways MAs can move closer together

    200 MA rising 50 MA above and falling

    200 MA rising 50 MA below and rising

    200 MA falling 50 MA above and falling

    200 MA falling 50 MA below and rising

    If PctDiff produces a negative numbers (I'm not sure whether it does), diverging MAs, although wider apart, will satisfy your condition (e.g. -10 per cent apart is less than -5 per cent apart).

    You could write out each case long hand, including MA directions and difference today vs difference 3 days ago.

    A slightly shorter method might be to use PPO Hist with certain parameters that I can't remember, and compare Hist values three days apart. But that requires testing for cases as well (first hist above 0, first hist below 0). If I can remember those parameters I'll edit this post. (I'm guessing PPO Hist(200,50, 1) but I'm not sure). If someone remembers, please chime in.
  • Hi markd, thanks for the suggestions, will give it a try
  • markdmarkd mod
    edited January 2022
    @BKInvestor This seems to take care of all possibilities:

    and [absval(sma(200)-sma(50)) < absval(3 days ago sma(200) - 3 days ago sma(50))]

    The AbsVal function (which I had forgotten about) always returns a positive number, so relative position of the MAs doesn't matter.
  • Thanks works great!
  • PPO or MACD both show EMA difference, not SMA.
  • @lmkwin oversight on my part re PPO and MACD. Thanks for the correction.
Sign In or Register to comment.