I have a simple section of a more complicated scan that doesn't seem to be working properly and I'm not sure if there is an error in the logic or am I missing something ?
The simple part of my scan is looking for the SMA 5 close crossing above the SMA 10 close.
[type = Stock]
and [SMA(5,close) X SMA(10, close)]
I usually run this scan after the close each day and it did pick up several stocks on May 27, but when I look at the charts I don't know why it didn't pick them up days earlier on May 23. Is this an error or am I missing something, here is a close up of a few of the charts and a zoomed in version of a few days before May 27 which clearly shows it crossed on May 23.
Great question and you are not the first one to question this condition. So lets check the chart in question by zooming in on the chart and the data.
First thing we have to realize is the non-trading weekend days (Sat and Sun) are not plotted on the chart, so every weekend we will have 2 blank dates before the next trading day. In this particular case it was a holiday weekend so there were 3 blank days and since this is an EOD (end of day) scan, the next data point is actually after the close on the 4 day. So when comparing the closing values one day to the closing values the next trading day, they can often be several calendar days apart.
Yes, in the chart above, it does visually appear that the SMA's crossed over during the day on May 23. However we have to remember that we are looking at closing values of OHLC and the SMA's represented in a candlestick format and as such we can vary the width of the candlestick by the chart size and candle width settings. It's easy to think of the left side of the candle as the opening at 9:30am and the right side of the candle as the close at 4:00pm, but this is not the case. They are just spread out so we can easily see the type of candle, ( red, black, hollow, filled).
With respect to the SMA's in question we could plot them as a single dot each day or as a sloped line connecting the dots. The line method is popular because it is easy to see the up and down trends. The trend line will look like a sloped line connecting the value yesterday, rising thru the evening, early morning, afternoon and closing higher at the next trading days value. When in actual fact the indicator is not changing overnight or thru the weekend, it is frozen at the current value until the next closing value is finalized / published, ie: we have no way of knowing whether the line should be up / down or sideways until after the close the next trading day. Thus when looking at only a few days, its better to see the chart as single dots or as a step chart, (staircase) as I've drawn below.
With respect to the chart in question I have zoomed in to see the exact closing values on May 23 and although they are very close, the SMA5 is still below the SMA10, thus the criteria for a crossover was not met on May 23.
I hope this answers the question and clears up any confusion as to when a scan should pick up a hit.
To learn more about writing scans I suggest attending ChartCon 2014. Chip and I will be reviewing how to create scans for fun and profit, I'm sure you will learn all sorts of new techniques and tricks for writing great scans. I will also be hosting an After Dark session on how to troubleshoot, verify and fix your problem scans.
For the full list of great speakers and agenda see the ChartCon2014 webpage http://stockcharts.com/chartcon
hope to meet you there, Gord