Scanning Technically

SCAN - Q: Why didn't may scan pick this up days sooner?

Question:

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.

Answer

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

 

Developing a Scan; Define Your Universe....

The first few lines define your development scan universe and these are mostly primary database variables.  The scan base is basically; Open, High, Low, Close & Vol, everything else has to be calculated.  So it helps the scanning speed and reduces the server load by using primary data first to limit the number of heavy calculations.

I treat Development scans a little differently than finished research scans.  For Development I'm basically only interested in single stock issues, no mutual funds or commodity contracts, no indexes or baskets of stocks (ETF's).   Thus my opening filter is;

[type = Stock]

Now for a development scan I need to make sure I will get enough hits (100-200), so I usually don't select a region/country or define any exchanges.  This way by default I cover all the exchanges in the USA and Canada.  If you're only a US trader you may want to restrict your scans to the US, but for development leaving it open gives you the option of more hits.

            and [country is US]

I also want stocks that behave well under Technical Analysis, so I will set a minimum price, (not interested in pennies as they are often manipulated and trade heavily on news or on pump & dumps rather than the Technicals), and I will also set an upper limit to be used for reducing the number of hits.  So lets say $1 min. and $20 max, there are a ton of stocks in this price bracket so I usually don't have any trouble getting hits.

            and [ close > 1 ] and [ close < 20 ]

I also want to eliminate any stocks which are very thin traders, so lets set a min volume greater than 500,000

            and [ volume > 500000 ]

Now here at the end is where you place your technical scan criteria, all the calculated stuff like SMA's, BollingerBands, MACD's etc.  Thus the heavy scan calculations are only preformed on a much reduced list of possible candidates.  This could be your own scan or parts copied and pasted from predefined scans.

Depending on your scan you may get 999 hits, in this case I just reduce the price bracket, sometimes even as low as say $10.00 to $10.25, what I want is about 100-200 hits.  I then start reviewing the charts with a chartstyle I have set up specifically to verify this scan.  I eliminate everything on the chart except what's critical in the scan and shorten the time frame down to maybe just a few days, that way it's easy to visually see the data.  For future reference I also put a link to this chartstyle in the scan as a comment, this eliminates having to recreate it again at some future time.

Here are two charts; 12 months, vs 20 days, with the SMA 20 X SMA 50, on the 12 month you gotta look at the numbers, but on the 20 day you can just scroll by to verify. 

Now I use the 10 / page mode to quickly scroll thru and visually check for compliance.  Now if there's a mistake in the logic I will usually see it in the first 10 or 20 charts.  IE charts which don't meet all the criteria, at this point there's no need to review any more charts.  Remember what part of the charts didn't meet the criteria and just go back check and adjust the criteria, then re-run the scan.  For simple scans once I see correct results for 20-30 charts I usually stop, but to increase your confidence in the scan just review more charts.

Optional Criteria:

- You may want to use a basket rather than a price bracket, so add S&P500 or S&P1500 as comments, that way its easy to just turn them on if you want, just remove the"//".

            // and [ group is S&P500 ] 
           // and [ [ group is SP500 ] or [ group is SP400 ] or [ group is SP600 ] ]

The last thing you want to do is save this scan so you can use it again and again as a starting point for scan development.  I have several basic scan intro's for different purposes, as this is a Development scan I would name it " 0 ADV DEV", 0 so its at the top on my list, ADV because its an Advanced Workbench scan and DEV because its for Developing scans.

Hope this gives you some new ideas,
cheers Gord

Why Do My "After the Close" Scan Results Change?

Q: Why do I get different results when I run a scan at the close, a few minutes later and then a few hours later.  The scan criteria is the same and the mathematical formulas are the same.  How can the timing of my after the close scan change the math and give me different results ?

A:  Very good question, it doesn't happen often but if you run alot of scans you will occasionally come across this situation.  There are multiple reasons for this, lets look at some of the common causes.  Note this is only a general overview of the basics.


1) Alot happens right at the close and within the next few minutes, the exchanges are very busy trying to accurately close out the day before after hours trading begins.

 - The books are balanced, any errors are corrected and the closing price is set.
 - All the EOD (trade at close) orders, account swaps, EOD block trades etc are processed, this won't change the closing price but it will change the volume.
 - The shareholders of record are determined, this is important for the distribution of dividends or splits etc which will be occuring EOD for specific stocks.
 - Official EOD numbers are set.

All of the above should happen before the after hours trading market opens.

2) Stockcharts begins their updates after step 1 is complete.

 - Once the official numbers are released Stockcharts can then start updating their databases.
 - For stocks which have gone EX dividend the historic data will be adjusted
 - For stock spits or consolidations the historic price and volume are adjusted

All of the above is done manually and may take a couple of hours depending on the volume of adjustments.  The end of the month and in particular end of the quarter tend to be very busy times for dividend & split adjustments.

For recent data adjustments you can check the "Recent Data Adjustments" link on the right side of the FreeCharts page under the "Other Tools" menu.

http://stockcharts.com/freecharts/adjusthist.html

For more indepth reading on data accuracy see this article.

http://blogs.stockcharts.com/chartwatchers/2012/07/on-data-accuracy-at-stockchartscom.html

Thus in summary when running scans just after the close, a few minutes later or even several hours later be careful how you interpret the results.  The math doesn't change but the underlying databases used for the calculations can change.  The closing price is the same however the closing volume may change and with dividend adjustments the historic prices and volume may also change.  These changes will also affect the values calculated for the indicators and overlays which are contained in your scan, which is why the results may occasionally change during this period between the close and completion of all the update adjustments. 

Cheers,
ord


 

Writing a Scan, How Does "YOUR" Mind Think?

Have you ever read the scanning documentation or reviewed someone else's scan coding and thought this  just doesn't make sense to me, well you are not alone it happens to all of us.  We are not identical computers running the same version of software, we are individual, (and thats a good thing).

Scans are mathematical relationships between various variables and by default we all think of those relationships a little differently.  Here's a few examples to get you thinking outside of "YOUR" box.

In the following case A is greater than B, but from the other side B is less than A, what was Your first thought?

A B blocks

Now lets review some of the mathematical relationships between A & B and the various ways we could write them.  Remember mathematical relationships are usually read from left to right, ie A is greater than B, (A > B) however the converse is also true, as read right to left, ie B is less than A, (B < A).  Here's a table of just a few of the relationships we could write about the A & B example shown above.  Note they all describe the same thing, just stated in different ways from a different point of reference and if used in a scan they would all yield the same results.

Math formulas

Now lets apply this to a couple of chart scan examples and we'll be looking for < or >, rather than = , and we'll also replace A & B with actual technical variables.

1- Looking for todays close to be more than 25% above todays SMA-50 of the close.  [ A > B * 1.25 ]

    and [Close > SMA(50, Close) * 1.25]

This is the chartstyle I would use for laying out the scan and maybe a slightly shorter period for checking the scan.  Note the use of the SMA envelopes to easily see the +/- 25% lines around the SMA-50

http://stockcharts.com/h-sc/ui?s=MPAA&p=D&st=2013-04-18&en=2014-02-14&id=p70098512834&a=336935179

Chart close 125%

2- Or looking for the same thing using a different formula we could use the following.  [ A < B * 0.8 ]

    and [SMA(50, Close) < Close * 0.8 ]

Similar layout and checking chart, although in this case we are looking for the +/- 20% lines around the closing price.  We can still use the SMA envelopes, the trick is to set the SMA to a value of 1 period, (ie the close).

http://stockcharts.com/h-sc/ui?s=MPAA&p=D&st=2013-04-18&en=2014-02-14&id=p30976225021&a=336939351

Chart close 80%

So in summary there is almost always more than one way to write a scan.  I like " [ A > B * 1.25]", but some like to see it as " [ B * 1.25 <  A ]" or "[ A * 0.8 > B ]", all depends on how "Your" mind thinks.  Just get comfortable with your prefered format and when you save someone else's scan for future reference just modify it to your way of thinking and maybe add a few comment notes.

happy scanning

Gord

 --------------------------------------------------------

 

** Addendum notes, additional details

With my engineering background I have been working with mathematical relationships for over 50 years, thus the above comes easily without even thinking about it.  However if this is not your background you may find these extra notes will help get you on the right track.

 Part I, defining the relationship graphically

First when thinking about mathematical relationships define a scale that works for you in determining the relationship graphically.  It doesn't really matter what scale as long as you use the same one for both sides, A&B.  Then ignore the greater than or less than signs, just work on how to make them equal, you can move on to the , < or > signs later.

1) Lets start with numbering the blocks 1, thru 5.  Thus if A is 5 blocks and B is 4 blocks, then we could write the equation, A times 4/5 = B.   Looking at it from the other side if B is 4 blocks and A is 5 blocks, we could write B times 5/4 = A.

                        A * 4/5 = B                 B * 5/4 = A

Now lets simplify this a bit,  4/5 = 0.8   and  5/4 = 1.25,  so the above can be rewritten as;

                        A * 0.8 = B                 B * 1.25 = A

2) Lets try a different scale numbering system, we'll make the value of A = 100, thus the five blocks of A become 20, 40, 60, 80, 100 and using this scale B = 80.  Thus the relationship could be written as A times 80/100 = B  or B times 100/80 = A.

                        A * 80/100 = B           B * 100/80 = A

Again lets simplify this a bit,  80/100 = 0.8   and  100/80 = 1.25,  so the above can be rewritten as;

                         A * 0.8 = B                 B * 1.25 = A

3) Lets try a different scale numbering system, this time we'll make the value of B = 100, thus the four blocks of B become 25, 50, 75, 100 and using this scale A = 125.  Thus the relationship could be written as B times 125/100 = A  or A times 100/125 = B.

                        B * 125/100 = A         A * 100/125 = B

Again lets simplify this a bit,  125/100 = 1.25   and  100/125 = 0.8,  so the above can be rewritten as;

                        B * 1.25 = A               A * 0.8 = B

Notice how even when using different scales, the mathematical relationships still simplify to the same basic formulas.  The scaling method you use just depends on which way your mind likes to think and whether you want to define A in terms of B, or B in terms of A.

Now you may also want to brush up on a little high school Algebra, just Google it there are lots of tutorials.  But basic Algebra also lets us manipulate the formulas once we have one valid relationship.

The basic premise is that as long as we do the same thing to both sides of the equation, the equation is still valid.  So lets start with;

            B * 1.25 = A

Divide both sides by 1.25

  B * 1.25 /1.25 =   A / 1.25     simplify    B * 1 =   A /1.25  simplify    B  = A * 0.8   or   A * 0.8 = B             

So again we arrive back at the same formulas we developed graphically above but this time we've used some basic algebraic manipulation.  I could continue, but I'll let you do your own DD.

Part II, the charts used for verifying and troubleshooting the scan.

I find when verifying and troubleshooting a scan, the quickest and easiest way is to create a chartstyle that highlights only what is in the scan.  This is not a chartstyle I would use for Technical Analysis, its focused on just the scan parameters I want to verify and I want to see them graphically so I can visually check at least 50 charts in a few seconds without having to look and compare individual numbers on each chart.

Limit the chartstyle to only the key parameters in the scan.  If the scan involves things that happened in the last 5 days, do not look at a 12 month chart, look at a 10 day chart.

Use indicators and overlays set up to highlight the parameters of your scan, performance charts are also helpful when the scan involves percent change.

For review I use the 10 per page view and I can quickly scroll thru 50 charts in a couple of minutes.  If the scan is fairly simple and the parameters can be seen on a small chart I'll save a CandleGlance chartstyle and then can review 30 charts per page quickly.
 

Cheers ,
Gord

Scanning to Find Stocks with Selling Climaxes



A selling climax occurs when a stock falls sharply on extremely high volume. As the name infers, a selling climax suggests that selling pressure has peaked and traders should expect some sort of rebound. Think of this selling pressure as a stretched rubber band, which cannot stretch forever. At some point, the rubber band either breaks or snaps back. In chart terms, a rubber band break would be the equivalent of a complete meltdown in prices. A snap back implies an oversold bounce that retraces a portion of the prior decline.

With a high-volume decline over the last few weeks, several stocks have experienced selling climaxes that could give way to oversold bounces. Though not perfect, chartists can find some these stocks by devising a scan to capture this high volume decline. The scan criteria below are designed to find stocks that became oversold on high volume and are still trading near their lows. Chartists can copy and paste this code into the advanced scan workbench.

[type = stock] AND
[country = US] AND
[Daily SMA(20,Daily Close) > 10] AND
[Daily SMA(20,Daily Volume) > 40000] AND
[Daily SMA(2,Daily Volume) > Daily SMA(250,Daily Volume) * 2] AND
[BB Width(10,2) > Daily SMA(250,BB Width(10,2)) * 2] AND
[Daily MIN(5,RSI(14)) < 25] AND
[Fast Stoch %K(14,3) < 10]

The first four lines simply qualify the symbol universe. The type is set for stocks, the country is the US, the 20-day price average is above $10 and the 20-day volume average is above 40,000 shares.

[Daily SMA(2,Daily Volume) > (Daily SMA(250,Daily Volume) * 2)]
Line four looks for stocks where the average volume of the last two days is at least twice the 250-day average for volume. This insures extremely high volume.

[BB Width(10,2) > Daily SMA(250,BB Width(10,2)) * 2]
Bollinger Band Width is a measure of volatility. In this example, we are looking for the BB Width (10,2) to be at least twice the 250-day average of BB Width (10,2). This insures that we have seen an expansion in volatility.   

[Daily MIN(5,RSI(14)) < 25]
Line six looks for stocks where 14-day RSI dipped below 25 at some points in the last five days. This insures that the stock moved lower and became oversold over a 14-day period, not just for a few days. Note that 30 is normally used for oversold readings. Using 25 insures an extra degree of oversold-ness.

[Fast Stoch %K(14,3) < 10]
Line seven looks for stocks with the Fast Stochastic Oscillator below. The Stochastic Oscillator measures the level of the close relative to the high-low range over the last fourteen days. A Stochastic Oscillator below 10 insures that the current close is near the low end of this range. This last criterion is used to cancel out stocks that have already bounced.

140206whr780
Click this image for a live chart

The chart above shows Whirlpool (WHR) meeting these scan requirements on Monday, February 3rd. Notice that WHR did not meet these requirements with the big decline two days earlier. Even though volume and the Stochastic Oscillator met the requirements, RSI did not break below 25 to confirm an oversold condition. Keep in mind that these are just guidelines and chartists can tweak the settings to fit their scanning needs.

What's Wrong with this Bearish MACD Crossover scan?

 
Question:

I inserted a predefined scan in the advanced scan workbench for a "Bearish MACD Crossover", however I'm not sure it's right.  I just cleared out all the default criteria and then selected and inserted the predefined Bearish MACD Crossover.  Here is the actual coding.

Scan code

 The coding seems to make sense until the last line which I think may contain some typos.  I understand there is a numerical relationship between signal and line, but what is the relationship between signal and histogram?  Also could someone explain what *0.25 means in the last line…  thanks.

 Answer:

 Actually this scan is correct for what it's doing, it's just a little more sofisticated than a basic crossover scan. In its simpilest form the scan could be just the first 4 lines.   However in this case, to eliminate picking up weak crossovers the scan adds the last 3 lines to ensure some stability and actual separation of the line and signal before the cross.  Note you can also modify this scan to suit your own needs and save it to your scan list.

 First lets be clear on what the MACD Histogram is.  It's just the numerical difference between the MACD Line and the MACD Signal, but it's plotted as a bar histogram along the "zero" line.  Here's a graphical representation.

MACD Hist
 
Now lets look at a graphical presentation of the whole scan, I find it often makes more sense than just looking at the math coding.  I've annotated each line of the code onto the chart for each of the days in the past.

Bear MACD cross

 Now lets look at the coding in question, the last line.

 and [3 days ago macd hist > 3 days ago macd signal * 0.25]

 Remember the Histogram is just the difference between the Line and the Signal, in this case we want some significant separation, ie 25%.  Still confused ? how about if the last line was coded differently, like the following.

 and [3 days ago macd line > 3 days ago macd signal * 1.25]

 For many users this might seem to make more sense, however its the same as the previous line, just stated in a different way, (getting from one to the other just takes a little algebra).  Our minds all think a little differently and what is the default for one person, seems backwards or just plain confusing to another.  It all depends on how you view numerical relationships.  Some people think "A" is BIGGER than "b", while others will instantly think "b" is smaller than "A".

Looking at just the last line here is a graphical representation of 4 different ways the same coding could be written, (and there are more).

MACD to Signal var

 Now for those who are still not sure, here's the algebra behind how we get from one coding line to the next.

  Algebraic

 I hope this  gives you a different view on the subject of scanning and writing code.

Cheers,
Gord

How can I see exactly what a predefined scan is doing and can I modify it?

 Well the short answer is yes, if you have an Extra level subscription or higher.  Basic or Free members can only review the output list of predefined scans.

 In the Standard Scan workbench there are two ways to add a predefined scan.

 1 - Under the "Global Filters" section just select the predefined scan in the drop down box.  This will add only the filter title, it does not show you the coding details and does not allow modifications.

or

2 - Under the "Additional Technical Expressions" section, select and insert the scan.  This is the method you want in order to see the coding details and allows you to modify them.

Method 1 -

1

Method 2 -

 2

As you can see the coding is inserted in the "Technical Expression" workbench section and also displayed in the Criteria summary at the top.

    • 50-day Simple Moving Average of Close for today is greater than 200-day Simple Moving Average of Close for today
    • 50-day Simple Moving Average of Close for yesterday is less than or equal to 200-day Simple Moving Average of Close for yesterday

Now you might notice that this is the long hand version of the cross-over function, "X" and this scan could have been written more simply as shown below.  3

 However the long version offers us a few more options.  Say you really want something on a little shorter time frame, the SMA-20 crossing above the SMA-50, well just change the 50 & 200 to 20 & 50.

4

But we only want crossovers that are significant, not the ones in the noise level that are bouncing around and crossing by tiny tiny amounts.

Let's say rather than just being greater than today, we want the SMA-20 to be at least 1% greater.  So we would multiply the SMA-50 by 1.01 which will add some significance to the cross.

Now we could also modify the pre-cross section to ensure that it was significantly below in the past.  Lets go back 2 days instead of 1 and require the SMA-20 to be at least 1% less than the SMA-50 at that point.  So we would change the 1Days to 2Days and multiply the SMA-50 by 0.99 (which reduces it by 1%)  6

When I ran this scan as of the close Jan 9th 2014, the modifications narrowed the hits from 113 to 18.

 Finally one of the best ways to review, analyze and verify your scan is to look at it graphically.  This is also a great method to use when planning out and developing a scan as it helps visualize breaking up a large scan into smaller sections of code.

 5

http://stockcharts.com/h-sc/ui?s=END&p=D&st=2013-12-13&en=2014-01-09&id=p81238557250&a=331269852

Happy scanning and always verify your scan outputs with a review of the charts, as what you think you asked for is not always what you really asked for. 

Gord Greer

 

Modify, Develop and Test a Custom Scan

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 an Extra level 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.

SPX SPXEW

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".

1 input

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.

1 output

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.

2 output

The following is a graphical representation of the scan which is often helpful when developing and laying out scans, especially the more complicated ones.

Scan graphic

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). .

 

Is It Possible to Change the Default Scan Definitions?

 

Right now, whenever I open up the Advanced Scan Workbench, I get this default benchmark definition for the universe of securities to scan:

[type = stock] and [daily sma(20,daily volume) > 40000]

This is hopelessly broad in that it includes boatloads of thinly traded stocks, penny stocks, foreign stocks and the like — securities I would never trade in, myself. I have my own definition of a securities universe, which looks like this:

[type = stock] and [[exchange is NYSE] or [exchange is AMEX] or
      
[exchange is NASDAQ]] and [daily sma(50,daily volume) > 200000] and [Close > 10]

This is my personal universe, and it works for me, but the point is, I would like to change the default securities universe to be that, rather than forcing me to manually change the overly broad universe that's already baked in, every time I log in.

Is there a way to make that change?

–chasfh

   

The short answer is “No.” The default scan page isn't customizable.

However, there is a workaround. You just have to change how you access the scan engine. Normally, I use the links on the Members page. You can use the right-hand link to “Create a New Scan,” which takes you to the Standard Scan Workbench. Then you hit the Advanced Scan button to get to the Advanced Scan Workbench page with the standard default starting point.

There is another link on the left, though, that you can use to pull up one of your saved scans and run it or edit it. This is the method I use, as I am either running a saved scan, editing a saved scan, or creating a new scan from scratch. Why not have the scan engine open directly in the scan where you want it to be, rather than open the default and then pull up your saved scan?

For a new scan with “MY Standard Default” intro settings, I just pull up one of my standard intro templates. These are scans I've created with different default settings that I use as a starting points. Their names start with “0” so they are always at the top of the drop-down menu list.

Changedefaultscan
 

One more thing, its always good to put the primary database criteria first — Symbol, Open, High, Low, Close and Volume — and put the secondary calculated criteria second. Your scans will run faster if the heavy calculations are done after the universe of stocks has already been reduced.

In other words, don't ask the scan engine to calculate EMAs, Stochastics, and Bollinger data on the entire 30,000 stocks in the database, and then ask it to scan the results for stocks between $5 and $10. Make the pool of stocks to be scanned as small as possible first. Then, run the heavy calculations. Your scans will run much, much faster.

Cheers Gord

–Gord

How to Use the Elder Impulse System to Trade

 

To experienced users of the Elder Impulse system for trading: What parameters for entering and exiting a trade have you found most useful using this system. For example do you exit a trade immediately when the daily 13 day ema chart shows a change from a green price flag to a blue, or do you wait until a red price flag is generated or what?

–JHuber8383

   

Before choosing chart settings, if you are an Elder follower, you will need your “Triple Screen.” I would suggest starting with hourly, daily and weekly. Personally, I just work from a feel for each chart. For my own trades, technically, I rely more on patterns, drawn lines, and fib level responses to price action (than the signals on the Elder Impulse). I saw a comment once from Elder that he uses 13, 65 and 200 EMA's, so I have been using that as a default chart for myself. Here is an example:


Zz-elderdaily

 

If there is a clear trend, then I favor ADX. If there is not, then I favor an oscillator like RSI. When I place indicators on the chart, I usually shift the setting towards fibonacci numbers (3, 5, 8, 13, 21, 34, 55, etc). For example, on the chart I posted above, the ADX trend is down and the RSI reading is still bearish. However, what is more impressive to me is that second Head and Shoulders pattern developing within the bearish flag and the confirmation of the bearish flag this last week. The next level to watch is the 2011 low near 10604 (kind of like an upside down break out) and then an A = C measured extension on a weekly chart. Here is the A = C extension on a weekly.

Z-elderweekly

Notice that the daily (your primary trading time frame) and weekly (your big picture) charts work together using the Elder-suggested Triple Screen. All you would need to do is form an hourly chart (e.g., your entry) for your trade. Most all of this is discussed in Elder's book, Come Into My Trading Room. However, he does not discuss patterns very much in that book.

–Anonymous

Scanning for Stocks that Outperform their Indexes

 

Is it possible to use the scan engine to pull out stocks contained within an index that are outperforming that index? I would like to run a scan for stocks in the S&P 500 that are outperforming the S&P 500 as a whole. Thanks!

–relaycharger

 

Here is a link to an article I wrote for the Scanning blog which should answer your question with even a few more ideas you may not have thought of.

For those who don't want to follow the link, I'll give you just a couple of snippets from that article. The very simple scan was as follows.

(Note you could turn on or off any of the individual groups by removing the double //, or just us the clause with the "OR" conditions to get the whole S&P 1500 index.)

In this case, there where two previous Highs in the $SPX index some time ago, and we were looking for stocks in that index that had now, during the last 6 days, exceeded their previous Highs during that time and were also more than 5% higher than those previous Highs.

[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 ]

Now for these types of scans, it is often helpful to see it in graphical form, so here are the conditions and criteria which had to exist to satisfy the scan and return a result.

Gordscan

I hope this gives you some other ideas.  Again, if you find this interesting, please read the entire article which contains much more information.

Cheers!

Gord

 

How to Scan for Stocks in an Uptrend Just as the 13-Day EMA Crosses Above the 26-Day EMA

 

I've been reading a lot and still haven't quite found the scan code I'm seeking. I'm looking for a scan that will bring up stocks at the beginning of an uptrend where the 13-Day EMA crosses above the 26-Day EMA.

As a side note, I follow the Elder Impuse System, and I like to trade within Keltner Channels.

I see a lot of crossover code on this forum, but when I run these scans, invariably, the stocks are already well into their uptrend and, sometimes, even too far above the 13-Day EMA for me to go long — so they just go into a watch list for a possible pullback to the 13/26 EMA zone.

So here is what I came up with:

[type = stock] and
[country = us] and
[daily volume > 500000] and
[close > 20.00] and
[close < ema(13)] and
[close >= ema(26)]

Can you help me tweak it so I get better results?

BearTrader

 

Hi BearTrader,

A couple of comments. Are you matching your scan parameters to your trading time frame? If you want to capture the very beginning of a trend the 13 and 26 EMAs won't work because it takes quite a few days to turn them. On the other hand, once turned, they may be good choices for longer-term trades. If you want to get in early, you could try much shorter-term crossovers, e.g. 3x13,

and [ema(3,close) x ema(13,close)].

To get in even earlier, test for a Close crossing a falling EMA,

and [close x ema(13,close)] and [ema(13,close) < 5 days ago ema(13,close)].

To further put things in your favor, also test for a rising, longer-term moving average,

and [ema(50, close) > 10 days ago ema(50,close).

I've also noticed recently, although I haven't tested it extensively, that a Close above the lowest Open when the short-term MA is falling can be followed by a change of trend, sometimes after a test of the Low, so,

[group is sp500] and [ema(13,close) < 5 days ago ema(13,close)] and [close > open] and [close > 1 day ago min(7, open)].

A final note, I'm defining trend here really as a leg or a swing in a larger uptrend, assuming that's what your are looking for. Also, I've noticed higher-volume, higher-priced stocks tend to form more regular patterns (most of the time). If you want the lower-price bang for the buck, the percent changes for in-the-money options can be pretty good, although that cuts both ways.

–markd

Create "AND/OR" Criteria with the Advanced Scan Workbench

 

The Standard Scan Workbench can apply a criteria to just ONE single day, such as just today or just yesterday. It cannot search both today and yesterday. However, the SC support staff says that the Advanced Scan Workbench has the capacity for a 2-day search by using the “and/or” criteria to run the criteria against today's data OR yesterday's. But I cannot find the OR button anywhere. Can anyone tell me how to write criteria for an advanced scan in which the Plus DI line crosses above the Minus DI line for either today OR yesterday?

–Bill Scott

 

You are correct there is no button for the OR function. By default, the And function is used whenever you insert something into your scan. Just manually change it to OR. However, be careful how you use it.

Here's an example. Note how I nested the OR inside an extra set of brackets so it applies only to the two DI clauses.

Also, I used a price bracket—Close between 10 and 20—just for scan checking: it reduces the output. Running it now, I get 216 stocks that crossed today, and then running it with today's or yesterday's crosses, I get 422 stocks.


[close > 10]
and [close <20]
and [ [Plus DI(14) x Minus DI(14)] or [1 day ago Plus DI(14) x 1 day ago Minus DI(14)] ]

 

I hope this gives you some other ideas.

–Gord

How Can I scan for the "Pocket Pivot" Setup?

 

Does anyone have a scan for the “Pocket Pivot” that they would be willing to share?

–TicoBob

 

My scan is based on the definition used by Chris Kacher (who came up with the concept). See his book or his website for details.

There are some fundamentals and situational criteria that need to be addressed, but the following will narrow the possibilities:

// Criteria to only scan leading stocks

[type = stock] and 
[daily sma(40,daily volume) > 500000] and
[daily sma(40,daily close) > 10] and
[daily close > daily sma(200,daily close)] and

// Criteria to verify the day's volume should be larger than the highest down volume day over the prior 10 days
[daily volume > 1 days ago daily volume * 1 days ago ROC(1) /absval(1 days ago ROC(1))* -1] and

[daily volume > 2 days ago daily volume * 2 days ago ROC(1) /absval(2 days ago ROC(1))* -1] and
[daily volume > 3 days ago daily volume * 3 days ago ROC(1) /absval(3 days ago ROC(1))* -1] and
[daily volume > 4 days ago daily volume * 4 days ago ROC(1) /absval(4 days ago ROC(1))* -1] and
[daily volume > 5 days ago daily volume * 5 days ago ROC(1) /absval(5 days ago ROC(1))* -1] and
[daily volume > 6 days ago daily volume * 6 days ago ROC(1) /absval(6 days ago ROC(1))* -1] and
[daily volume > 7 days ago daily volume * 7 days ago ROC(1) /absval(7 days ago ROC(1))* -1] and
[daily volume > 8 days ago daily volume * 8 days ago ROC(1) /absval(8 days ago ROC(1))* -1] and
[daily volume > 9 days ago daily volume * 9 days ago ROC(1) /absval(9 days ago ROC(1))* -1] and
[daily volume > 10 days ago daily volume * 10 days ago ROC(1) /absval(10 days ago ROC(1))* -1] and

//Criteria to see jump through 10 or 50 d SMA
[[yesterday's daily close < yesterday's daily sma(10,daily close)] and [daily close > daily sma(10,daily close)]

or

[yesterday's daily close < yesterday's daily sma(50,daily close)] and [daily close > daily sma(50,daily close)]]

Once you've run this scan, then you'll need to visually inspect the candidates. You're looking for either an early buy point within a consolidation or a consolidation buy point for a leading stock already firmly entrenched in a strong uptrend. (This is very easy to do visually, but would be very tough to program into the scan.) The scan found 6 symbols tonight, but none had charts that visually matched these criteria. Not surprising, since you don't expect to find pocket pivots very often.

MarkK

How Can You Find the Industry a Stock Is In on the StockCharts.com Website?

 

Is there a way to find out what Industry/Sector a stock is in through stockcharts.com? And is there a way to find out what stocks are in a given Industry/Sector? I know the PerfCharts list about 10 stocks, but I'd like to see them all.

–Money1957

 

There are several ways to see which industry or sector a particular stock is in. The easiest might be to just create a SharpChart for that stock and turn on the Full Quote option. The sector/industry information (if we have it) will be in the upper left-hand corner of the Full Quote box.

To see which stocks are in a given industry/sector is slightly more work. You need to create and  run a scan that only returns stocks in the sector/industry you are interested in. For example, using the Advanced Scan Workbench, you'd use:

[group is BasicMaterialsSector]

Use the Sectors and Industries dropdown menu in the Scan Builder to get the proper syntax for the sector/industry you are interested in.

Note: Since his approach requires access to the custom scan workbenches, it will only work for Extra and ExtraRT members.

—Chip

Stochastic Pop and Drop Scan

Developed by Jake Berstein, modified by David Steckler and tweaked at StockCharts, here is a scan that uses the Stochastic Oscillator to idenfity price pops and price drops. The bullish Stochastic Pop looks for stocks with a long-term Stochastic Oscillator above 50, an ADX value below 20 and a short-term Stochastic Oscillator surge above 80.

Bullish Stochastic Pop:

  [type = stock]
  and [today's sma(20,volume) > 40000]
  and [today's sma(60,close) > 20]
  and [Slow Stoch %K (70,3) > 50]
  and [ADX Line (14) < 20]
  and [today's Slow Stoch %K (14,3) x 80]

The bearish Stochastic Pop looks for stocks with a long-term Stochastic Oscillator below 50, an ADX value below 20 and a short-term Stochastic Oscillator plunge below 20.

Bearish Stochastic Drop:

  [type = stock]
  and [today's sma(20,volume) > 40000]
  and [today's sma(60,close) > 20]
  and [Slow Stoch %K (70,3) < 50]
  and [ADX Line (14) < 20]
  and [20 x today's Slow Stoch %K (14,3)]

Extra! users can copy this scan code and paste it in the Advance Scan Workbench. There is also a ChartSchool article with detailed examples.

 

Scanning for 'Scooters' (SCTRs)

Over the past week or so you've probably seen announcements introducing the new StockCharts Technical Rank.  The StockCharts Technical Rank is a way to rate the technical strength of a stock.  The short-hand form is the SCTR, or 'Scooters' as they have been quickly dubbed.  The StockCharts.com home page now has a section for the Top 10 rankings of three different SCTR groups.  SCTRs are still in test mode and we invite your feedback.

You can click here to see the announcement posting.

We won't dive into the technical details about how the score is created in this posting.  If you would like more information on how the SCTRs are calculated, you can read the ChartSchool article here.

One of the first things to know about SCTRs is that a stock could potentially have many of them.  SCTRs are a ranking within a grouping of stocks.  A group could be the S&P 500, NYSE stocks, ETFs,  all Canadian stocks or even stocks that start with the letter 'A'.  The possibilities are limitless. 

For example Apple could have a SCTR score for the S&P 500, Nasdaq and US stocks.  Each score would be different because the members it is being ranked against is different. 

When using SCTRs one must keep in mind what the overall group that SCTR is ranking.  A stock with a high score in the S&P 500 group may not have a corresponding high score in another grouping if the rest of the group has stocks out performing the S&P 500.

Within a group, each stock is given a score based on a number of technical parameters.  The entries are then ranked by score and given a StockCharts Technical Rank from 0 to 99.9.  Scores > 90 represent the best of the group and scores near 0 represent the worst.

This brings up another aspect to remember: the SCTR is a relative score.  If the group as a whole goes down 2% but one stock manages to simply stay at the same price that day, it's score will go up even though it hasn't necessarily had an upward price move.  It went up by virtue of the fact that everyone else went down.  One must bear this in mind when you see a stock with a large move in it's SCTR but the price change doesn't appear to support it.

Initially there are five SCTRs covering the S&P 500, S&P 400, S&P 600, US ETFs and stocks listed on the Toronto exchange.  Currently no stock will have more than one SCTR score as the above group memberships happen to be mutually exclusive. 

This will likely change as more SCTR groups are created in the future.  Thus only stocks in these 5 groups will have SCTR values initially.  Stocks outside these groups will have no SCTR value.

In the case of the ETFs and Toronto exchanges, we're choosing only stocks that trade above $1 and have volume greater than 40,000 shares using a 20 day simple moving average.

 

Standard User Interface

In the Standard interface there is now a new section for SCTRs right below the Group list.  This list contains pre-defined ranges for the five SCTR groups mentioned above (note, the picture below only shows the S&P 500 entries.  The other SCTRs have the same ranges available).

Screen shot 2011-12-15 at 1.37.01 PM

 

Here's a tip for Standard UI users (I know because I did this myself!), if you're looking for TSX SCTRs, don't forget to change the Group setting.  By default you'll be scanning for Toronto SCTRs in the United States.  That will give you zero results every time!  Change the Group to Any, or Canada or TSX, or TSX 300 to ensure you don't create a mutually exclusive set of parameters.

 

Advanced User Interface

The Advanced interface also has a new section: Price, Vol and Sctrs.   The technical indicators are now in their own list called Technical Indicators:

Screen shot 2011-12-15 at 2.46.08 PM

 

In the Price, Volume and SCTRs list are the 5 SCTRs:

S&P 500 = SCTR.sp5
S&P 400 = SCTR.sp4
S&P 600 = SCTR.sp6
US ETFs  = SCTR.us.etf
Toronto = SCTR.tsx

To scan for S&P 500 stocks that are technically strong you could use the following:

[SCTR.sp5 >=90] 

to find weak small-cap stocks, look for lower SCTR values in the S&P 600:

[SCTR.sp6 < 10]

 

More on SCTRs

We hope that, in conjunction with your existing scans, SCTRs will offer a new way to help find great performing stocks.  Be sure to keep an eye on the StockCharts blog postings to see where else SCTRs will be turning up on the site.

Happy Holidays!

Scan coding sample blocks

Hi all from the 3rd floor of the Red Lion in Seatle, ChartCon has been wonderful and educational.  I hope all who are in attendance are enjoying it as much as I am, many many thanks to Chip and the whole team for putting on this exceptional event.  I'm sure the next one will be even better, but I'm not sure how you're going to do that Chip.

This mornings sessions covered the scanning engine and there were many questions on how to set up scans and whether there were any libraries of standard scan coding.  There are many predefined scans on the website which you can look at and learn from, I recommend you study them closely.

However in order to help get you started here are a few Advanced scan coding sections, these are provided just to get you thinking of different things you can do and how the general format of the coding is set up.

These sections of coding can be modified and grouped into an advanced scan as you see fit, these are only examples they are not necessarily scans which would be applicable to your investment / trading style.  Just cut and paste into the scan engine and start creating your own library.  (all info provided is subject to change without notice, use at your own risk)

Happy scanning
Gord Greer


Advanced Scan Code Sections,
Just a Few Examples
( // indicates comment lines)


// Sample scan layout, generic
[type = stock]
and [1st criteria]
and [2nd criteria]
and [ [3rd criteria] or [4th criteria] ]


[country = us]
[country = canada]
[country = uk]


// Type
[type = stock]
[type = index]
[type = fund]

// Exchange
and [exchange = NASDAQ]
and [exchange = NYSE]
and [exchange = AMEX]
and [exchange = PINK]
and [exchange = TSE]
and [exchange = CDNX]
and [exchange = LSE]


and [group is SP500]
// or for S&P 1500, large, mid and small cap
and [ [group is SP500] or [group is SP400] or [group is SP600] ]


// Fav lists, numbers will be different for each user, note extra brackets grouping the "OR" clauses together
//
[[favorites list = 13]
or [favorites list = 24]
or [favorites list = 63]
or [favorites list = 64]
or [favorites list = 67]
or [favorites list = 68]
or [favorites list = 70]
or [favorites list = 71]]


// Liquidity  SMA of average dollars traded per day > $500,000
[type = stock]
and [SMA(50,close) * SMA(50,volume) > 500000]


// Price bracket, used to restrict the output when developing scans, also min close used to eliminate stocks which are not marginable and not likely to have options, or stocks which have a price which would require a board lot trade to be above your position size. (ie if your max position size is say $10K then 100 shares of a $100 stock would be at your limit of $10K,  100 shares of Google would be $60K,  this is important if you broker requires you to trade in board lots when inputting conditional orders)
//


and [Close >=10] and [Close <=20]


// Uptrend: for 75 days the min RSI(14) value >= 40
and [Min(75,RSI(14)) >= 40.0]


// Downtrend:  for 75 days max RSI(14) value <= 60
and [Max(75,RSI(14)) <= 60.0]


// Uptrend: MACD positive for 130 days (~ 6 months)
and [Min (130, MACD Line (12,26,9)) > 0.0]


// MA Price convergence long term,
// SMA-20, 100 & 200 all within +/-1% of the SMA-50
and [daily sma(20,daily close) >= daily sma(50,daily close) * 0.99]
and [daily sma(20,daily close) <= daily sma(50,daily close) * 1.01]
and [daily sma(100,daily close) >= daily sma(50,daily close) * 0.99]
and [daily sma(100,daily close) <= daily sma(50,daily close) * 1.01]
and [daily sma(200,daily close) >= daily sma(50,daily close) * 0.99]
and [daily sma(200,daily close) <= daily sma(50,daily close) * 1.01]


// MA Price convergence short term,
// SMA-3, 10 & 40 all within +/-1% of the SMA-20
and [daily sma(3,daily close) >= daily sma(20,daily close) * 0.99]
and [daily sma(3,daily close) <= daily sma(20,daily close) * 1.01]
and [daily sma(10,daily close) >= daily sma(20,daily close) * 0.99]
and [daily sma(10,daily close) <= daily sma(20,daily close) * 1.01]
and [daily sma(40,daily close) >= daily sma(20,daily close) * 0.99]
and [daily sma(40,daily close) <= daily sma(20,daily close) * 1.01]


// Price convergence consolidation mid term,
// Max / Min daily close for last 20 days,
// contained within +/-2% of the current SMA-20
and [max (20, daily close) <= daily sma(20,daily close) * 1.02]
and [min  (20, daily close) >= daily sma(20,daily close) * 0.98]


// Price convergence consolidation short term,
// Max high / Min low, for last 10 days,
// contained within +/-2% of the current SMA-10
and [max (10, daily high) <= daily sma(10,daily close) * 1.02]
and [min  (10, daily low) >= daily sma(10,daily close) * 0.98]


// Price channel convergence,
// Max / Min daily close for last 20 days,
// contained within +/-3% of the current close
and [min(20, daily close) > close * 0.97]
and [max(20, daily close) < close * 1.03]


// Consolidation then breakout,
// 30 days prior to yesterday Max/Min close within +/-3% of yesterdays SMA-20,
// then breakout, close today 5% above yesterdays SMA-20
and [1 day ago max (30,  close ) <= 1 day ago sma(20, close) * 1.03]
and [1 day ago min (30,  close ) >= 1 day ago sma(20, close) * .97]
and [close > 1 day ago sma(20, close) *1.05]

//Note last line could be modified to look for a break in either direction,
and [[close > 1 day ago sma(20, close) *1.05] or [close < 1 day ago sma(20, close) *0.95]]


// Fav lists scan for unusual activity, select Fav lists grouped with "OR" clause; watch, hold and sector lists. 
//Then define several criteria for today, yesterday, day before etc, based on close, high, low, volume etc etc,
// and then group them with "OR" so any individual criteria will select a stock.
//
[ [favorites list = 1]
or [favorites list = 3]
or [favorites list = 5]
or [favorites list = 6]
or [favorites list = 10]
or [favorites list = 13]
or [favorites list = 61]
or [favorites list = 70] ]
and [[0 days ago volume > 1 day ago sma (60, volume)*1.25]
or [1 days ago volume > 2 days ago sma(60, volume)*1.25]
or [2 days ago volume > 3 days ago sma(60, volume)*1.25]
or [0 days ago close > 1 day ago close * 1.05]
or [1 days ago close > 2 day ago close * 1.05]
or [0 days ago high > 1 days ago close * 1.05]
or [1 days ago high > 2 days ago close * 1.05]]

end

Gord Greer

Scanning for an overlay of an indicator

Question:

Is it possible to use an EMA of an indicator in a scan? For example, If I wanted to know when RSI(5) is above a 3-period EMA of RSI(5)?
I know you can use sma(60,volume), for example, but volume doesn't have a parameter. When I try to introduce an indicator parameter to similar phrasing, I get syntax errors. It doesn't "get" RSI(5,5) or EMA(5,RSI(5)).
Any help would be appreciated.

 

Answer:

Yes it is possible and its one of the scan coding items that many people have trouble with.  I assume the following chart explains the type of thing you are looking for.  Note for this example I've just choosen a stock and adjusted the EMA and RSI time frames to get a crossover in the last few days in order to check my scan coding, you can change the parameters to your own needs.


Scan ema of rsi

Now here is the coding I set up to look for this cross.

[type = stock] and [country = us]
and [Close >=48] and [Close <=49]
and [RSI(7) X EMA(14,RSI(7))]

Note in order to check the scan I know this cross happened 3 days ago for GG (Goldcorp), so when I run the scan with a start date of 3 days I should get GG which will verify that the scan is working. (note I narrowed the price range specifically to home in on GG)

Scan gg

Note we did pick up GG, you might notice that the price range for GG on the above list is outside the price range in the scan, however the list above is todays price range, the scan was for 3 days ago.

I hope this helps, happy scanning.

 

 

Building a Scan, Q&A

Question

"...I'm hoping someone can help me with some criteria for setting up a scan.... I came up with a description in words, but other than item 1 and 2, not sure how to input things into stockcharts.com.

1. Stock must trade over 500,000 shares average for last 20 days
2. Greater than $5
3. Stock must have traded above the 200 DEMA for 20 days or more
4. Stock must be in decline
5. Stock must trade at less than 105% of the 200 DEMA

I define the pivot as the following, using candlesticks:
A down bar, followed by a bar that opens lower and closes higher, and the final bar opens down or equal to the previous bar’s close, and closes higher on the day.

I'm probably asking a lot for the pivot part and I'm cool with eye balling that part if necessary...."

Answer

Great question,
I've been away for a few weeks unplugged, (ie without internet).  Back now,  currently at the Chartcon conference out in Seattle.  The short answer is yes you can scan for all of what you are looking for.

Let’s break it up into sections and review each in a little more detail.

- 1. Stock must trade over 500,000 shares average for last 20 days

and [daily sma(20, daily volume) > 500000]

- 2. Greater than $5

and [Close > 5]

This requires today’s close to be greater than $5, but we could also expand this to require that the average close for the last 20 days be greater than $5.

and [daily sma(20, daily close) > 5]

We could also require the min close for the last 20 days to be greater than $5.

and [Min(20, daily close) > 5]

Or we could require that the min daily low be greater than $5.


and [Min(20, daily low) > 5]


- 3. Stock must have traded above the 200 DEMA for 20 days or more

This one is a little tricky, lets look first at some of the things which won't work.

and [close > ema(20, close)]
This requires only today’s close to be above today’s value of the ema20.

and [min(20,close) > ema(20,close)]
This requires the min close over the last 20 days to be above today’s value of the ema20.

and [min(20,close) > max(20, ema(20,close))]
This requires the min close over the last 20 days to be above the max value over the last 20 days of the ema20, however not necessarily on the same day.

In summary the above criteria are close to what we are looking for but none of them require the close on every individual day to be above the ema20 for that same individual day.

One way to accurately check for a few days is to just write the criteria for each day, as follows.

and [close > ema(20,close)]
and [1 day ago close > 1 day ago ema(20, close)]
and [2 day ago close > 2 day ago ema(20, close)]
and [3 day ago close > 3 day ago ema(20, close)]
etc,
etc,
etc,
and [20 day ago close > 20 day ago ema(20, close)]

While the above method is OK for a few days it can become lengthy for longer time frames and luckily there is another method.  We need to start by becoming familiar with the formulas for all the indicators we use on our daily charts.  In this case the MACD indicator is of interest, Moving Average Convergence Divergence.  The MACD line which is plotted is the raw difference between two exp moving averages, the typical default values are 12, 26.  Normally there is also a signal line plotted which is typically a 9 ema of the MACD line.

In our case we are looking at the close being above the 200ema, the trick to remember is that a 1 day ema or sma is actually the closing price for each day.  Thus if we plot the Macd 1,200 we are actually plotting the difference between the daily close and the daily value of the ema200 for each individual day.  The value is positive when the close is above the ema200 and negative when the close is below the ema200.  Thus we only need to scan for the min  value to be positive, (greater than 0), for the last 20 days, as follows.

and [Min (20, MACD Line (1,200)) > 0.0]


-4. Stock must be in decline

Lots of ways to this so lets just say in the medium term the 20SMA is below the 50SMA.

and [sma(20, close) < sma(50, close)]



- 5. Stock must trade at less than 105% of the 200 DEMA
Here we simply have to require the close to be less than the ema200 times 1.05

and [Close < ema(200, close)*1.05]

- 6. "I define the pivot as the following, using candlesticks:
A down bar, followed by a bar that opens lower and closes higher, and the final bar opens down or equal to the previous bar’s close, and closes higher on the day".

In this case we just need to look at each day and define the criteria for the open and close each day, note as far as the scan engine is concerned today is day zero "0" and counts back in time.  See the following chart which identifies the criteria for each day.

Pivot


and [2 days ago close < 2 days ago open]
and [1 day ago open < 2 days ago close]
and [1 day ago close > 1 day ago open]
and [open <= 1 day ago close]
and [close > 1 day ago close]

 

hope this gives you some new scanning ideas

good luck

Futures Contracts Added

Following on the tails of Chip's announcement about the addition of futures contracts (click here), the Scan Engine now supports futures as well.  There are two new indexes and a new instrument type to choose from.

Futures symbols will start with the “^” character.  For example: ^GCG12 for the Gold – Feb 2012 (EOD) contract.

In the Advanced UI you can find futures via:

[type = future]

The new exchanges are the CME and ICE.  To target specific exchanges use the following:

[exchange = CME]
[exchange = ICE]

The 'type' and 'exchange' fields can be selected from the Ticker Properties list in the Scan Builder section:

Screen shot 2011-07-19 at 3.21.18 PM

 

To scan for futures contracts In the Standard UI, first change the drop down list to display 'Futures':

Screen shot 2011-07-19 at 9.47.58 AM
If you wish to look at a particular exchange, the Group list in the Global Filters section has entries
for both the ICE and CME exchanges:

Screen shot 2011-07-19 at 9.49.38 AM

Note that if 'Futures' is not selected first, as shown in the previous image, searching for ICE and CME symbols will yield no results.

As Chip mentioned in his posting, StockCharts will continue to add even more futures symbols over the coming weeks!

Percentage Change Function Added To ScanEngine

Knowing the percentage change of an indicator can be a very powerful tool in finding stocks which are outperforming other stocks or indices.  In an effort to make finding these stocks easier, the PctChange function has been created.

In the Advanced UI, the function can be found in the Price, Volume and Indicators list:

Screen shot 2011-05-11 at 1.39.25 PM

PctChange takes two parameters, a time period and an expression.  For example:

PctChange(10,close)

which calculates the percentage change over the last 10 trading periods using the closing price.  To find stocks which have gained more than 15% in the last 10 days we would have:

[PctChange(10,close) > 15]

and for stocks that have gone down more than 15%:

[PctChange(10,close) < -15]

PctChange can be used to find stocks which are outperforming or underperforming various indicators.  If we know the S&P has gained, say 8% in the last 3 months, we can now quickly find stocks outperforming the benchmark.

Another application would be to scan a favorites list to find items in that list which have a higher or lower percentage change than others.  For example, if you have a favorites list which contains the Dow-Jones sectors and industries, Fidelity sector funds,  International ETFs, etc.  PctChange can show which of those are doing better or worse than the others over a given time period.  Your scan may look something like:

[favorites list is 50] and [PctChange(10,close) > 30]

But the PctChange function is not limited to only price data.  It will also accept other expressions such as MACD lines, moving averages, channel values; virtually any expression that can be found in the Price, Volume and Indicators list when using the Advanced UI.  Here are a few examples:

PctChange(10,MACD Line (12,26,9))
PctChange(10,Fast Stoch %K (14,3))
PctChange(10,Aroon Up (25))
PctChange(10,SMA (50,volume))
PctChange(10,BB Width (20,2))
PctChange(10,Volume)

Keep in mind that oscillators will tend to have larger swings on a percentage basis and in cases where values are near 0, the percentage change can go quite high.  As with all scans, you may need to adjust your parameters to get a result set that is manageable.

In the Standard UI, there are 2 options for PctChange listed under the Additional Technical Expressions area - PctChange Close and PctChange Vol:

  Screen shot 2011-05-11 at 1.44.30 PM

Both default to a period of 10.  So in the Standard UI to find stocks that have a 15% or better gain in the last 10 days, the parameters would like like this:

  Screen shot 2011-05-11 at 8.59.23 AM

Happy Scanning!

Scans, Where is the "Crosses Below" function ??

Q:  I've used the crosses above function but I can't find the crosses below function, where is it ??

A: Don't feel frustrated, this is just part of the learning curve and it's one of the most frequently asked questions on scanning.  Many articles have been written on the subject but as it keeps coming up I'll try to put a little different slant on the subject.

Actually the crosses below function is reduntant, we just have to think of the crosses above function from the other point of view.  It all just depends on what your mind likes to think of as the reference point.  When "A" crosses ABOVE "B" we have to remember that from the other point of view "B" is crossing BELOW "A".

Here's an example to help get you thinking of different ways to read the coding:

and [Close > 10.00]

- Read from left to right, this clause looks for stocks where the close is greater than $10.00
- Read from right to left, this clause looks for stocks where $10.00 is less than the close.

We could also find the same stocks by writing the clause as follows, it just depends on how your mind likes to think of it, both clauses achieve the same result.

and [ 10.00 < Close ]

Now lets look for stocks where the 20 SMA has crossed ABOVE the 50 SMA

and [ SMA(20, close) X SMA(50, close) ]
or we could write it as
and [ SMA(20, close) Crosses SMA(50, close) ]

- Read from left to right, this clause looks for stocks where the 20 day SMA of the close has crossed ABOVE the 50 day SMA
- Read from right to left, this clause looks for stocks where the 50 day SMA of the close has crossed BELOW the 20 day SMA

Thus to find stocks where the 20 SMA crosses BELOW the 50 SMA, just write it as the 50 SMA crossing ABOVE the 20 SMA, as follows;

and [ SMA(50, close) X SMA(20, close) ]
or we could write it as
and [ SMA(50, close) Crosses SMA(20, close) ]

1spx crosses


Sometimes we need to think outside the box and sometimes we just need to look at the box from the other side.

Final note on the crossing function,  when scanning for "A" crossing "B" we need to remember this is actually the short form of the following two clauses, (less than or equal to yesterday, and greater than today).

and [ "A" one day ago < = "B" one day ago ]
and [ "A" today > "B" today ]

Now the scanning engine calculates and compares these values to several decimal points, so in order to avoid picking up very small crosses I often use the two line method and I require the cross to be greater than say 1%  (use the multipier function on the second parameter).

and [ "A" one day ago < = "B" one day ago ]
and [ "A" today > "B" today * 1.01 ]

Happy scanning

Gord

Note: Free and Basic level members have access to hundreds of pre-defined scans, but in order to create and modify your own custom scans as above, you will need at least an Extra level StockCharts.com membership.

Candlestick Building Blocks

Scanning for candlestick patterns has been a staple of the scan engine for quite some time.  The current selection of candlestick scans contains single day patterns as well as multi-day patterns.  Multi-day patterns are generally built up from a sequence of smaller patterns.  In effect these smaller duration patterns act as building blocks for larger patterns.

In an effort to allow more control over scanning for your own patterns, nine new 'building block' patterns have been added:

Doji
Uptrend
Downtrend
Long Body
Short Body
Marubozu
Star
Spinning Top
Engulfed

These scans are more generic than their familiar counterparts.  For example Engulfed will be true for a Bullish or Bearish engulfing pattern.  A Doji will be true for a Gravestone Doji, a Dragonfly Doji or any other Doji pattern.

If you'd like a refresher on what some of these candlestick patterns are, click here.  If you really want to dive into candlestick patterns, we suggest Gregory Morris' Candlestick Charting Explained which you can find in the bookstore here.

In the Standard UI these are listed under the Predefined Chart Patterns section.   The Advanced UI's list is under the Candlestick Patterns menu and is in the same order.

Screen shot 2011-03-16 at 8.51.51 AM

In the Advanced UI these patterns are evaluated as true or false values like the rest of the candlestick scans, so the syntax in the Advanced UI will look similar to the following:

[Star is true]
[Long Body is false]

Happy Scanning!

Middle Price Channel Scans Now Available

In addition to scanning for upper and lower Price Channels, it is now possible to scan for the middle Price Channel.  The middle Price Channel is simply the midpoint between the upper and lower Price Channels.

In the chart below, the middle Price Channel is represented by the blue dotted line:

Screen shot 2011-01-20 at 8.56.35 AM

In the Standard UI you can choose the middle Price Channel from the Indicators drop down list in the Additional Technical Expressions area:

Screen shot 2011-01-20 at 9.46.40 AM

In the Advanced UI, look under the Price, Volume, and Indicators drop down list:

Screen shot 2011-01-20 at 9.44.31 AM

For more information on Price Channels, see the article in ChartSchool here.

Welcome Pink Sheets to the Scan Engine

The scan engine has been updated so that Pink Sheet symbols are now included in scan results.

To scan specifically for Pink Sheets in the Standard Scan user interface, simply choose PINK from the Group menu in the Global Filters area:

Screen shot 2011-01-10 at 2.54.22 PM

In the Advanced user interface, specify the exchange as 'PINK' (without quotes) in your scan expression:

[exchange is PINK]

Conversely, if you'd rather not see those stocks, you can choose to omit them by using the 'not' keyword:

[exchange is not PINK]

We are also working on splitting off the OTC (Over the Counter) and BB (Bulletin Board) stocks.  That work should be finished soon.  When complete, one can specifically scan for, or eliminate, that subset of stocks as well.  Stay tuned to the Scanning Stocks blog for updates!

Happy New Year!

Laying Out a Scan

Q:  Can I scan for a stock that has 5 consecutive days down, then an inside day on the 6th day.

A:  Yes, its its a little longer than most scans but its really not difficult, just break it up into sections.  First think about the criteria which must be met today and what criteria must be met in the previous several days. It often helps in the beginning to blow up and print out a chart which has the characteristics you are looking for.  If you can't find such a chart just draw one, it doesn't have to be pretty or accurate, it just has to show the concept you are looking for.  The drawing can then be annotated with the required data formulas.

Here's your basic scan in an annotated drawing. (Note we will keep it simple at this point and just use the open and close data, ie ignoring the candle tails, highs and lows).

Vscan3m

It does takes a few minutes but just start from the beginning and enter each criteria element one at a time. Here's what it would look like in the basic scan engine.

1 scanm

Click here to open the above scan in a new window

Once the above scan is loaded into the Basic scan page you can use the "Advanced User Interface" button at the bottom to see the coding in the Advanced scan engine.  Note I've added a few line returns to break up each section onto its own line, makes it a little easier to follow.

[type = stock]
and [daily sma(20,daily volume) > 40000]
and [daily close > daily open]
and [daily close < yesterday's daily open]
and [daily open > yesterday's daily close]
and [yesterday's daily close < yesterday's daily open]
and [yesterday's daily close < 2 days ago daily close]
and [2 days ago daily close < 2 days ago daily open]
and [2 days ago daily close < 3 days ago daily close]
and [3 days ago daily close < 3 days ago daily open]
and [3 days ago daily close < 4 days ago daily close]
and [4 days ago daily close < 4 days ago daily open]
and [4 days ago daily close < 5 days ago daily close]
and [5 days ago daily close < 5 days ago daily open]

Now if I was to create this scan directly I would use the Advanced scan interface which allows you to copy and paste, this makes it much quicker for any scans which have alot of repetition and similar clauses.  I would also not use the term "daily" in any of the clauses, its the default time frame so really isn't necessary in this scan.  Also I prefer to use the term "1 day ago" rather then "yesterday", just makes it a little easier to follow the flow of the scan.

[type = stock]
and [sma(20, volume) > 40000]
and [ close >  open]
and [ close < 1 day ago open]
and [ open > 1 day ago close]
and [1 day ago close < 1 day ago  open]
and [1 day ago close < 2 days ago close]
and [2 days ago close < 2 days ago open]
and [2 days ago close < 3 days ago close]
etc,  etc.

Hope this gives you some ideas to get started scanning.

cheers

 

Calendar Helps With Scan Offset Dates

One of the features available in both the standard and advanced scan engines is the ability to run your search relative to a specific number of days in the past.  But sometimes trying to map the offset to a specific day can be a bit tricky.  We've all probably spent time looking at calendars and counting backwards trying to get the date we wanted.

To help with this process we've added a calendar control which will appear when you click in the offset edit field.  The control has two features which will aid in making sure your scan is using the date you think it is. 

First, when you click on the calendar control it will take the offset number you have in the edit field and initialize the offset date of the calendar to the appropriate date based on the current date.  It will also adjust for whether or not you have the Last Intraday option vs Last Market Close option selected.

In the example below, we have an offset of 3 days relative to the Last Market Close (Oct 21).  As  you can see in the calendar, the offset day maps to October 18th.  If we choose Last Intraday Update (and the market is still open), then the offset date is October 19th.  The offset date in the calendar has a white background and orange text.

  Example2

The second feature allows you to pick a date and the offset value will be provided for you.  Assuming we run this on October 22nd and you choose October 6th relative to the Last Market Close, the offset field will be set to 11.

To exit the calendar control without making a change, simply click anywhere on the page outside the control.  If you do not wish to use the calendar, you can still manually type in your date offset and
press Enter, click on the Done button, or click anywhere outside the calendar control to override the calendar's value.

The range of the calendar is set to as many dates as are available for daily scans, which is generally about 780 days and in this case stretches back to September 19, 2007.  Note of course that setting your offset back that far may not be practical in some cases as you will need a certain amount of data to accurately calculate common indicators such as moving averages.

Other StockCharts Blogs

Subscribe to this blog