Indicators are Rarely "Equal" in the Eyes of the Scan Engine
A member wrote in today asking why a stock was not returned in his scan results when, according to the chart he was looking at, it should have been.
In this case, the chart clearly showed that for this stock, the 12,26,9 version of the MACD had the same value (12.02) as the 20,36,9 version of the MACD. And yet, his advanced scan didn't return the stock in question. He's the scan he was using:
[type = stock] and [close > 10] and [MACD Line(12,26,9) = MACD Line(20,36,9)]
So what was going on?
When we looked into the issue, we quickly discovered that the user was correct - despite the fact that the chart showed identical values for both MACD Lines, the Scan Engine did not return the stock in question. But why?
It turns out that the values displayed on the chart are rounded to a certain number of decimal points (typically 2 or 3) for display purposes. The values used by the Scan Engine are not rounded and are therefore usually not exactly equal. In this case, one MACD had a actual value of 12.020345 and the other had a value of 12.023424 and therefore, in the eyes of the Scan Engine, the two values were not "equal."
So, how can we "fix" this?
We fix this problem buy replacing the "equals" clause with two other clauses like so:
[type = stock] and [close > 10] and [MACD Line(12,26,9) > [MACD Line(20,36,9) - 0.01]] and [MACD Line(12,26,9) <= [MACD Line(20,36,9) + 0.01]]
That gives us a "buffer" around the values of 0.02. As long as the MACD values are within that buffer, they are "close enough" to be considered "equal" by our scan.
