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

Close together MA's

I've been trying to write a scan that looks for Moving Averages that have collapsed together today and also 5 days ago and not more the .5% difference. My results preset about 400 candidates but only some of my results meet this criteria and most do not. I compare the 9EMA to the 20 EMA, the 20 EMA to the 50 SMA & then the 9 EMA to the 50 SMA. Can anyone point out what I'm missing in the scan below.

[type = stock] AND [Daily SMA(20,Daily Volume) > 500000]
and [country is US]
and [group is not LSE]
and [group is not NSE]
and [optionable is true]

// Here I want the Underlying to Be Above $15
and [Daily Close > 15]

// Here I want the difference between the 9,20 EMA & 50 SMA to be less or equal to 1/2 Percent over past 5 days
and [[PctDiff(EMA(9, close), EMA(20, close))] <= .5]
and [[5 days ago PctDiff(EMA(9, close), 5 days ago EMA(20, close))] <= .5]and [[PctDiff(EMA(20, close), EMA(50, close))] <= .5]
and [[5 days ago PctDiff(EMA(20, close), 5 days ago EMA(50, close))] <= .5]
and [[PctDiff(EMA(9, close), EMA(50, close))] <= .5]
and [[5 days ago PctDiff(EMA(20, close), 5 days ago EMA(50, close))] <= .5]

and [PE ratio > 0]
and [EPS > 0]

Answers

  • Options
    markdmarkd mod
    edited December 2021
    and [[PctDiff(EMA(9, close), EMA(20, close))] <= .5]

    This is not a valid statement. If you have the Advanced Editor on, it should flag it with a red box with a white "x" in it. If you roll your cursor over the red box, it will tell you an operator is needed, because it thinks you want to compare the first expression (PctDiff) to the second expression (EMA( )]

    That's not what you want to do, so you need to figure out why you get that error. I think the reason is, you have an extra set of brackets [ ] around PctDiff.

    I think what you want is

    and [PctDiff(EMA(9, close), EMA(20, close)) <= .5]

    By removing the extra set of square brackets, the error goes away.

    Try that with the rest of the statements and see if it helps.

    Also, I think this one

    and[[5 days ago PctDiff(EMA(20, close), 5 days ago EMA(50, close))] <= .5]

    should be

    and [ PctDiff(5 days ago EMA(20, close), 5 days ago EMA(50, close)) <= .5]

    That would apply to the rest of them, also.

    However, that would looks at only the difference from five days ago, not all the days in between. Unfortunately, to get each day's difference, you have specify each separate day (four days ago, three days ago, etc.)

    Or, you could try

    and [max(5, PctDiff(ema(20,close),ema(50,close)))<= .5]

    but I'm not sure if PctDiff( ) works inside max( ). Try it!

  • Options
    markd, I revised my scan per your suggestion by removing the extra brackets plus modified it put the put the '5 days ago' statement inside the PctDiff parenthesis. This did clear up the red box syntax errors. However this scan still return 390 candidates. I sampled the first 9 candidates and at least 66% of them did not meet this PctDiff criteria. I also tried using the 'max' argument as you suggested and that produced 900 candidates. In both cases, these scans have returned too many candidates that did not meet my desired gaol. Any further suggestions.
  • Options
    markdmarkd mod
    edited December 2021
    I'm just guessing, but "<=.5" would allow negative results greater than 1/2 per cent, assuming PctDiff can return negative numbers.

    Maybe include an additional condition that the difference has to be greater than zero. Or, maybe greater than minus a half percent ">= -.5", depending on what you are looking for (one MA above the other (>0), or one MA within a half percent of the other either way - i.e. plus or minus a half per cent).

    So maybe something like

    and [ PctDiff(5 days ago EMA(20, close), 5 days ago EMA(50, close)) <= .5]
    and [ PctDiff(5 days ago EMA(20, close), 5 days ago EMA(50, close)) >= -.5]

    I didn't check this through syntax, but I think it should be OK.
  • Options
    markd, tired your latest suggestion of,

    and [ PctDiff(5 days ago EMA(20, close), 5 days ago EMA(50, close)) <= .5]
    and [ PctDiff(5 days ago EMA(20, close), 5 days ago EMA(50, close)) >= -.5]

    with much greater success. I think you might be on the right track. This scan returned 107 candidates (vs. 400 using my approach) and these candidates are much closer to what I'm looking for.

    I'll now try variations on this theme and try to fine-tune my parameters.

    Thanks for the assist.
  • Options
    Great. Good luck!
Sign In or Register to comment.