Some of you might recognize this example from a CSTA webinar I did last Dec, but I thought it was a good time to update and share it with all StockCharts users. The example starts with a simple predefined scan and shows how it can be modified, step by step.
(Note the techniques described use the advanced scan interface for writing custom scans, thus you will require at least a Basic membership to create these scans).
When reviewing the charts for the S&P500 index we see that the index closed above the Feb and April levels. Now individual stocks don't always follow the index exactly but we can use the scan engine to find which are leading or lagging the index. Also we have to be aware that the $SPX is the S&P 500 market cap weighted index, ie Exxon and Apple account for 6% of the index. We could also look at the $SPXEW which is the equal weighted S&P-500 index where each of the 500 stocks accounts for 0.2%, this index exceeded the Feb highs in April and exceeded the April highs today.
So lets find out how the individual stocks in the index are doing. We'll limit our initial scan to the S&P-500 and insert one of the predefined scans "New 52 week high".
Now running this scan yields 98 hits, but I'm more interested in closing values than the daily highs and really only interested in looking back into Jan. Now we could change only todays high to a close above the previous intra-day high but in this case I'll change both the "highs" to "close" and just look for the previous maximum back say 90 days instead of 260 trading days.
[type = stock]
and [group is SP500]
and [today's close > yesterday's daily max(90,close)]
This gives us 113 hits.
But I know some stocks in the index may not have had a new high close today, they may have had a new high a few days ago and pulled back a few cents today. So lets look for a new high close anytime during say the last 5 days which is higher than the highest close for the previous 90 days (starting 6 days ago).
[type = stock]
and [group is SP500]
and [max(5, close) > 6 days ago daily max(90,close)]
This gives us 163 hits, which corresponds to 32% of the stocks in the S&P-500 hitting a recent new high close in the last 5 days. But I'm also interested in what the Small and Mid cap stocks are doing so I'll add them to the list and by using the comment prefix of // or #, we can turn these individual clauses ON and OFF. (any line prefixed with // or # is considered a comment and not evaluated)
[type = stock]
// and [group is SP500]
and [group is SP400]
// and [group is SP600]
and [max(5, close) > 6 days ago daily max(90,close)]
This yields the following hits;
SP500, 163
SP400, 113
SP600, 111
Total = 387
Now we also have another option if we wanted to look at the Large, Mid and Small caps simultaneously, we could create a grouped "OR" clause, enclosed by an extra set of square brackets. Note this function is only available in the advanced scan engine interface and I have turned OFF the individual clauses. (Note the S&P-1500 is currently not available in the scan engine as a predefined group, but you can chart it under the symbol $SPSUPX)
[type = stock]
// and [group is SP500]
// and [group is SP400]
// and [group is SP600]
and [ [group is SP500] or [group is SP400] or [group is SP600] ]
and [max(5, close) > 6 days ago daily max(90,close)]
This gives us the same 387 hits as the individual scans.
Now if we look at the $SPXEW-500 Equal Weight index, we see that it is about 1% above its recent highs, so lets limit our scan to only stocks which significantly exceed that. Lets try 5% above the past highs and lets use the S&P-1500 group, (use the multiplier function).
[type = stock]
//and [group is SP500]
//and [group is SP400]
//and [group is SP600]
and [[group is SP500] or [group is SP400] or [group is SP600]]
and [max(5, close) > 6 days ago daily max(90,close) * 1.05 ]
This gives us 45 hits.
In summary I verify each section (clause) before proceeding to the next clause. I find the quickest way is to review 10-20 charts to see if they meet the scan criteria and I try to make this as visual as possible, (its just quicker). So before I run the scan I set up a simple chart for only the time frame of the scan and only plot what the scan is looking for. In this case the chart covers Feb till now and is a performance type chart which makes the min 5% gain easy to see. I save this chart as my default style and after I run my scan I can easily dump the output into my "00 Temp" fav list (it’s the first list so its already in the drop down box, just hit go) and all the charts will be created with this chart style.
Note; if for some reason you need to keep your default chart style you can also change the chart style after you have dumped the group to a new fav list, just set up a new style on one of the charts and then use the "Apply Style to All" button, but this will take a few more steps and you will have to redo those steps every time you run and dump new scan results.
At this point you can also click on the table headers and sort by "Sector" or "Industry" to see where most of the hits are coming from.
Then select the 10 per page view and quickly scroll thru 10-20 charts to verify the scan is finding what you asked for, or what you thought you asked for. If necessary go back and modify the coding. Then select differnt indexes or add more specific technical criteria.
The following is a graphical representation of the scan which is often helpful when developing and laying out scans, especially the more complicated ones.
I hope this discussion has given you some new ideas on creating, modifying and testing your own customs scans.
Happy scanning,
Gord
(note: I don't work for StockCharts, I'm just a long time user always trying to learn more and willing to share what I've already learned. If you have comments related to this article I'll try to answer them here, if you have other comments or suggestions send them directly to StockCharts thru the support page).