As a scanning example, lets look in detail at one of the predefined scans, the "Bullish MACD Crossover".
You can see the coding for this scan by selecting and inserting it into the Basic Scan page. Open the Basic Scan page and in the lower right, select the desired scan from the drop down menu and use the insert button.
From the StockCharts scan definitions page, just click the link below the scan input form.http://stockcharts.com/help/doku.php?id=support:predefined_scans
"Bullish MACD Crossovers - Stocks whose MACD line crossed above the signal line today after being below the signal line for the previous three days. The MACD parameters used are 26 and 12 and the signal line is a 9-day EMA of the MACD line."
To understand the indicator, click the "About Indicators" just below the indicators section of any sharpchart input page.
Now lets look in detail at the actual scan coding, here's what it looks like in the Basic Scan interface.
And if you hit the "Advanced User Interface" button at the bottom of the page you'll see what the coding looks like in the Advanced version.
Now to make it easier to read and understand I usually add a few line returns to separate each criteria clause onto a separate line. Then I save these blocks of code, with explanation notes to a text file (say MS Notepad), then I can easily reuse any coding by just cutting and pasting it into a new scan.
[type = stock]
and [country = us]
and [daily sma(20,daily volume) > 40000]
and [yesterday's daily macd line(12,26,9) < 0]
and [daily macd line(12,26,9) >= daily macd signal(12,26,9)]
and [yesterday's daily macd line(12,26,9) < yesterday's daily macd signal(12,26,9)]
and [2 days ago daily macd line(12,26,9) < 2 days ago daily macd signal(12,26,9)]
and [3 days ago daily macd line(12,26,9) < 3 days ago daily macd signal(12,26,9)]
and [3 days ago daily macd hist(12,26,9) < 3 days ago daily macd signal(12,26,9) * 0.25]
For analysis of the scan I've identified the various criteria sections as 1 thru 9 on the basic scan page above. So here's the text description of the scan.
1 For the last market close:
2 United States Stocks with...
3 20-day Simple Moving Average of Volume for today is greater than 40000
4 Daily MACD Line(12,26,9) for yesterday is less than 0
5 Daily MACD Line(12,26,9) for today is greater than or equal to Daily MACD Signal(12,26,9) for today
6 Daily MACD Line(12,26,9) for yesterday is less than Daily MACD Signal(12,26,9) for yesterday
7 Daily MACD Line(12,26,9) for 2 days ago is less than Daily MACD Signal(12,26,9) for 2 days ago
8 Daily MACD Line(12,26,9) for 3 days ago is less than Daily MACD Signal(12,26,9) for 3 days ago
9 Daily MACD Histogram(12,26,9) for 3 days ago is less than Daily MACD Signal(12,26,9) for 3 days ago times 0.25
Now here's a little more detail as to what each section means.
1- Sets the scan to use the last EOD market close data
2- Looks for only US Stocks
3- Requires the SMA20 of Volume to be greater than 40,000 shares, thus eliminates all stocks which are thinly traded or haven't traded in some time.
5- This is the cross (or near cross), it requires the MACD today to be greater than or equal to the Signal line.
4 & 6 & 7 & 8
Requires the MACD to be below the 0 line (negative), ie the MACD 12 day EMA is below the 26 day EMA. Also requires the MACD to have been below the Signal line for each of the previous 3 days.
9- This final criteria is a little trickier, it requires that the value of the MACD Hist (3 days ago) to be less than the Signal line *(times) 0.25, IE the Hist is the diff between the MACD and the Signal line (9 EMA of MACD), so we want the diff to be greater than 25% of the Signal, that is we want at least some minimum separation 3 days ago , this eliminates stocks that were very close 3 days ago and have now just crossed, (basically flat line MACD). To see this more readily or to have a greater move, increase the multiplier value to say Signal line *3 and thus we'll have fewer results as the move now has to be much greater.
So here's a chart of ADOBE which was one of the scan results.
Now the above chart might be something you would look at when evaluating stocks but its not much help when evaluating the scan. Below are the chart settings I defined to more easily evaluate and verify this scan. First I set the time frame to be equal to or just slightly longer than the duration of the longest criteria of the scan, then I eliminate everything except what the scan is looking for. In this case the scan is only looking for MACD, MACD HIST and Volume SMA20, note I also made the price invisible and have shown the MACD behind the price, (ignore the values on the right side of the chart as they are the price values of the ADBE stock).
Another trick is to temporarily save these chart settings as your default, then when you run the scan the results can be saved into a new Favorites list and when you review that list all the charts will already be in this format. It makes checking the validity of the scan much easier and after you've confirmed the scan is working as desired you can just switch all the charts to whatever settings you use for the stock analysis.
So here's the Adobe chart with the settings I would use to evaluate the scan and I've annotated it with all the criteria we were looking for. Note with respect to the MACD Line and MACD Signal lines, they appear as continuous lines but really the chart is just connecting the dots from the EOD data for each day, thus I've drawn square boxes around the data points which the scan is actually looking at.
I hope this gives you a little more background to modify an existing scan or create your own from scratch.