Do you have any idea why this scan / alert would have alerted me for SPX and SOX but when I confirm by running a scan, it does not. The alert should not pick either of them for a couple of reasons. One is the high today is not > the low one day ago. Also, 1 day ago MACD Hist(2,3,0) was not > 0.0.
[Favorites List is 23]
and [[MACD Hist(1,2,0) < 1 Day ago MACD Hist(1,2,0)] or [[EMA(1) < 1 Day ago EMA(1)] and [1 Day ago EMA(1) > 2 Day ago EMA(1)]] or [[SMA(1) < 1 Day ago SMA(1)] and [1 Day ago SMA(1) > 2 Day ago SMA(1)]]] and [1 Day ago MACD Hist(2,3,0) > 0.0]
and [High > 1 Day ago Low] and [1 Day ago High > 1 Day ago lower BB(20,1)]
and [[EMA(1) < 1 Day ago EMA(1)] or [SMA(1) < 1 Day ago SMA(1)] or [EMA(1) < SMA(1)]]
and [EMA(14) < SMA(14)] and [EMA(14) < 1 Day ago EMA(14)]
and [[EMA(20,RSI(14)) < SMA(20,RSI(14))] and [EMA(20,RSI(14)) < 1 Day ago EMA(20,RSI(14))] and [SMA(20,RSI(14)) < 1 Day ago SMA(20,RSI(14))]]
and [MACD Hist(48,103,36) < 1 Day ago MACD Hist(48,103,36)] and [MACD Line(48,103,36) < 1 Day ago MACD Line(48,103,36)] and [MACD Hist(72,156,54) < 1 Day ago MACD Hist(72,156,54)] and [MACD Hist(72,156,0) < 1 Day ago MACD Hist(72,156,0)]
0
Comments
As you know, if your "or" brackets are not grouped and/or isolated correctly, then only one condition in the entire scan has to be true to trigger a hit.
Also, scans run at different times can have different results because the data has changed.
A grammatically incorrect grouping (odd number of brackets) will trigger a warning and the scan won't run.
A logically incorrect (or maybe I should say unintended) grouping can be grammatically correct, so the scan will run.
You say you require today's high to be above yesterday's low, but if your "or" groupings are off, you can get a hit if even if that's not true, but a different "or" alternative is true.
The results you get could be a clue to where the problem is in your scan.
If you require high > 1 day ago low, but that requirement is not in the results, then the scan engine believes it can ignore that requirement because it has met an alternative requirement, so (because its an "open" "or" statement) it can return a result.
You can see which lines are getting read by checking off which conditions ARE met on the charts in the results.
Another possibility is the scan has more conditions than the scan engine can resolve in one scan. I don't know the limits, so that could be wrong.
Incidentally, ema(1) and sma(1) and "close" are all the same thing. You can test this:
[group is sp500]
and [ema(1) = close]
You will get 500 results, or every stock in the index. So close and ema(1) are the same. Same with sma(1).
So you can simplify your code (and processing by the scan engine) by substituting "close" wherever those terms occur.
The brackets may or may not be where you really want them, and the notes, while they say what the code says, may or may not be what you actually want the line to do. I'm not sure if this helps or not, but worth at try.
[group is sp500]
// Hist 1 is down, or close is down
and [[MACD Hist(1,2,0) < 1 Day ago MACD Hist(1,2,0)] or [close < 1 Day ago close]]
// yesterday's close is down, or today's close is down
and [[1 Day ago close > 2 Day ago close] or [close < 1 Day ago close]]
// yesterday's close is down
and [1 Day ago close > 2 Day ago close]
// yesterday's Hist 2 was above zero
and [1 Day ago MACD Hist(2,3,0) > 0.0]
// today's high is greater than yesterday's low
and [High > 1 Day ago Low]
// yesterday's high is above yesterday's lower BB
and [1 Day ago High > 1 Day ago lower BB(20,1)]
// today's close is down or today's close is down or close is less than close (this needs attention)
and [[close < 1 Day ago close] or [close < 1 Day ago close] or [close < close]]
// ema is less than sma
and [EMA(14) < SMA(14)]
// ema is down
and [EMA(14) < 1 Day ago EMA(14)]
// ema RSI is less than sma RSI
and [EMA(20,RSI(14)) < SMA(20,RSI(14))]
// ema RSI and sma RSI are down
and [EMA(20,RSI(14)) < 1 Day ago EMA(20,RSI(14))]
and [SMA(20,RSI(14)) < 1 Day ago SMA(20,RSI(14))]
// MACD Line and Hist 48 are down
and [MACD Hist(48,103,36) < 1 Day ago MACD Hist(48,103,36)]
and [MACD Line(48,103,36) < 1 Day ago MACD Line(48,103,36)]
// MACD Line and Hist 72 are down
and [MACD Hist(72,156,54) < 1 Day ago MACD Hist(72,156,54)]
and [MACD Hist(72,156,0) < 1 Day ago MACD Hist(72,156,0)]
It seems like you are looking for a tick down that moves all the indicators down also. Am I close?
As far as I know, brackets only affect the logic and execution of the scan when "or" statements are involved.
If you have say 10 "and" statements and you put brackets around them to make two groups of five "and" statements, it does not affect how those statements get executed, as far as I know.
If you use brackets to group things for yourself, so you know what goes together, you could use lines that start with "//" between the groups. The scan engine ignore any line that starts with //.
You can put actual comments on those lines, e.g.
// Hist 48 is lower
or just symbols,
// ******
or anything that helps you know what goes with what in your scheme of things.
I'm not really well versed on how alerts work in practice because I don't actually use them. But, as I understand it, they are meant to trigger the FIRST time the alert conditions change from false to true. The alert conditions can go back and forth from false to true a number of times during the session, but the alert will only trigger once.
For instance, if the alert is close > 50, and at the session start the close (meaning the price as of the first update) is 49, and some time during the session an update close gets to 50.01, you should get an alert.
But suppose on later updates in that same session the close drops back to 49.99. If you run the alert as a scan right after the later updates, it will not pick up the hit that triggered the alert because close > 50 is not true anymore.
Since your scans reference the close, that may be what is happening. But the same thing (the data has changed) could be true of the indicators, too, so that some part of the scan that was true is not longer true when you run the scan.
I'm not sure what happens if the alert condition is already true. For instance, if the alert is close > 50, and yesterday the stock closed above 50 and today it opened above 50 and stayed there all day, I'm not sure if you would get an alert.
You could look at the chart as soon as you get the alert, take a snapshot of it (a print screen, although it may have already changed) and see if it still fits the alert. Or, take a snapshot of the chart before you run the scan to see if it should fit the scan before you run it. Of course, it's changing all the time, so it may not help.