Recently (on May 6th actually), we received the following message in our support queue:
The above chart (PCG) should be found by the following scan, but is not. Can you tell me what is wrong with the last line of code? Each of the lines are true but the last line is not working. I tested it by adding a line at a time. Syntax is correct, but it is not finding all valid charts. Is this a problem with the scan engine?
[type = stock] and [country = us] and [optionable is true]
and [close >= 10] and [close <= 200]
and [today's sma(50,volume) >= 500000]
and [Slow Stoch %K(8,3) <= 40.0]
and [[daily max(65,high) - daily min(65,low)] / close > 0.30]Thanks,
Name Withheld
Have you ever encountered something similar? It is a very common issue for people who create their own scans. Here was our response:
Dear Name,
Thank you for sending us that question.
When researching this kind of issue, the first step is to determine which clause in your scan is excluding PCG. The next step is to create a chart with the data that the scan engine is looking at. Finally, plug in the data from the chart into the problematic clause to see what is going on.
To find out which clause is causing the problem, first place each clause on a separate line starting with the "and" the joins the clause to the rest of the scan. You've already done that.
Next, add "//" to the front of the bottom clause to "comment out" that clause and re-run the scan and see if PCG appears:
[type = stock] and [country = us] and [optionable is true]
and [close >= 10] and [close <= 200]
and [today's sma(50,volume) >= 500000]
and [Slow Stoch %K(8,3) <= 40.0]
//and [[daily max(65,high) - daily min(65,low)] / close > 0.30]In this case, PCG does appear which means that the bottom-most clause is the problem. (If it didn't appear, we'd comment out the next-to-last clause and try again.)
Next, we need to create a chart that shows the data for that clause. Using the "Starting ___ days ago" box on the Scan Workbench, you can quickly determine that January 31st was 65 trading days ago. Thus we need a daily chart going from January 31st to May 6th. Here's an example:
http://stockcharts.com/h-sc/ui?s=PCG&p=D&st=2013-01-31&en=2013-05-06&id=p53729067476
Next, we can use the "Inspect" feature to determine the highest high (48.50) and lowest low (40.57) and current close (46.50) on that chart.
Finally, we plug that information into the formula in the clause:
[[48.50 - 40.57 ] / 46.50 > 0.30]
which becomes
[ 7.93 / 46.50 > 0.30 ]
which becomes
[ 0.1705376344086 > 0.30 ]Which is false. Which is why PCG was excluded from your scan results.
Thanks again for using StockCharts.com,
Cole Johnson
StockCharts Support
http://stockcharts.com
And, sure enough, Name later confirmed that he had meant to use a less than sign "<" instead of a greater than sign ">" in that final clause.
If you ever find yourself in a similar situation, try following Cole's steps for finding the issue:
- Determine which clause is causing the problem.
- Create a chart that contains all the "data points" for that clause.
- Plug-in those data points to the clause to see what's going on.
- Chip
Posted by: Mark Dobbins May 08, 2013 at 17:51 PM