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.
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]
0
Answers
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!
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.
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.