COMPUTERIZED SCREENING FOR "CUP WITH
HANDLE" PATTERNS
by Rick Martinelli & Barry Hyman
Haiku Laboratories Technical Memorandum 980601
Copyright (c) 1998
Note: this document has been published essentially unchanged in the October 1998 issue of Technical Analysis of Stocks and Commodities, under the title Cup-With-Handle and the Computerized Approach.
CANSLIM STOCKS
CUP WITH HANDLE PATTERNS
SCREENING AND RANKING PATTERNS
SOME EXAMPLES
CONCLUSIONS
ACKNOWLEDGMENT
REFERENCES
CANSLIM Stocks
In the book entitled "How to Make Money in Stocks", William O'Neil describes an
approach to investing called the CANSLIM method. This method combines technical and
fundamental analysis to identify some of the best stocks in a cycle. Each letter in the
acronym CANSLIM stands for some characteristic of a stock or the market in which it is
traded. For example, C stands for the stock's "current quarterly earnings" while
M stands for "market direction". The letter I stands for "institutional
sponsorship" which is an indication of money flow into or out of a stock, a major
aspect of the CANSLIM method.
According to the system, only those stocks meeting a set of quantifiable criteria are candidates for purchase. In addition, a stock must exhibit one of three or four different chart patterns that summarize less quantifiable aspects of the system.
Manually screening for stocks which meet all these criteria is a daunting task. To be successful at this system, it is advisable for the investor or money manager to use either The O'Neil Database® or Daily Graphs®, as well as Investor's Business Daily. For the serious investor using this system, at a minimum Daily Graphs is a must. But in addition to using these references, one must still screen through hundreds of stocks daily to find stocks that have "set-up", and then monitor each of the stocks one finds for days or weeks waiting for them to "break out" before buying. Visually screening the more than 2,400 stocks in the Daily Graphs each week and then watching them daily is a full time job. And, equally important, the manual approach misses many stocks as they break out, and misses others which do not make it into these publications.
If one could first screen for acceptable chart patterns amongst the data of the more than 10,000 stocks that some of the data-download services provide daily, and let the computer narrow the list down to a manageable number of stocks to watch, it would be immensely time-saving. This was the motivation for developing a computer algorithm to do such a screening.
"Cup-with-Handle" Patterns
The most common chart pattern used in the CANSLIM system is called a
"cup-with-handle". This pattern has been concisely described by Gregory Kuhn in
a series of articles entitled "Back to Basics Trading Stocks", "The
Cup-With-Handle Pattern", and "Trading with the Cup-With-Handle", and is
also discussed by one of us in "Pattern Recognition in Time Series", all of
which appeared in this Journal. The pattern is so named because, when viewing a stock's
price chart, it appears roughly like a cup. The price rises to a peak then falls, forming
the left side of the cup. From there the stock trades sideways for some time, then rises
to form the right side of the cup. After completion of the cup, before the stock breaks
out to new highs, the price often hits resistance there and pulls back a little. This
pullback forms what looks like a handle on the cup. The peak at the right side of the cup
defines the buy or breakout point called the pivot price. (The details of why this common
pattern forms and why it is so often the precursor to big advances in a stock's price is
detailed in O'Neil's book .)
But price action itself is not sufficient to determine whether a breakout is prone to
succeed or fail. Constructive volume action is imperative. "Big money"
(Institutional money) must be flowing into a stock for a breakout to succeed. The CANSLIM
approach requires, for example, that the volume on the breakout be at least 50% above the
50 day average volume prior to the breakout. Another indication that institutional money
is flowing into a stock occurs when a stock's rising days generally have much higher
volume than on down days. One of the best clues of institutional buying prior to a
breakout appears in the price-volume interaction. First the volume on the rising days in
the right hand side of the cup is much higher than both the volume in the falling days and
the 50 day average volume. Then the volume in the falling days of the handle "dries
up", or diminishes, well below the volume on the rising days of the right side of the
cup, which pushed the price up. Using considerations like these, we were able to include
both price and volume requirements into a single algorithm
Figure 1 shows a highly idealized price-volume chart of the cup-with-handle pattern. There are 5 main points on the chart denoted by K, A, B, C, and D. The actual cup-with-handle pattern is located between points A and D; the point K denotes the beginning of a setup phase. Starting at point K, the stock's price rises, peaking at Point A, defining the top, or left side, of the cup. Point A is the highest point on the chart. After peaking at A, the price drops and begins to build the bottom of the cup which ends at point B. After point B the price rises on increasing volume, forming the right hand side of the cup, accompanied by a similar rise in volume. As the price and volume rise together forming the right side of the cup and fall together forming the handle, the price and volume should give the appearance of shadowing each other. Point C is the highest point in the right-hand-side of the cup, the pivot point, completing the cup formation. Then, as the price pulls back on lighter volume, a handle is formed with the most recent day being point D. The cup-with-handle pattern is now complete and the buy point will occur when the price breaks above the value at point C, on large volume. This is indicated by point E in the Figure.
With a computer program that screens for such patterns, the user is provided a list of
stocks whose charts are the best cup-with-handle candidates on a purely technical basis.
It is then up to the user to research these stocks to determine which have the qualifying
fundamental criteria. This list is a "watch" list, not a "buy" list.
The user must not buy stocks from the list yet, as many stocks which complete the cup with
handle set up, do not break out. From point D they often roll over forming the right
shoulder of a head-and-shoulders topping pattern and fail disastrously. Using the CANSLIM
system from this point the user must wait for these stocks to break out on significant
volume to actually buy them. The power of a computer program lies in the ability to
screen more than 10,000 stocks every day, narrowing them down to a the best candidates to
watch, and its ability to uncover and monitor each new qualified chart that emerges daily.
Screening and Ranking Patterns
These, then, are some of the technical requirements that a stock's price-volume chart
should meet before it becomes a candidate for a CANSLIM stock. To begin quantifying these
requirements, let PK, PA, PB, PC and PD
represent prices at the points K through D, respectively, in Figure 1.
We can write the requirement that the price at point A exceeds the price at point K as PK
< PA We may also write the requirement that the price at point C
cannot exceed the price at point A by PC <= PA. In a similar
manner we may summarize the five price requirements described above as follows:
PK < PA, PB < PA,
PC <= PA, PB < PC,
PD <= PC
In order to eliminate stocks whose handles have fallen too far, an additional requirement is that point D, the last point on the handle, has not dropped below the 80% mark between points B and C. This sixth requirement is written as
PD > 0.8 PC + 0.2 PB
Lastly we must consider the cup pattern itself. Between points A and C, the only requirement is that no price in this interval exceeds the price at point C. This is our seventh requirement:
PJ < PC for all points J between A and C.
To quantify the volume requirements we define a new chart variable called the relative-price-volume, or RPV, which captures a stock's price-volume interaction. A stock's daily RPV value is the change in its closing price from the previous day multiplied by the volume that was traded that day. A chart of RPV values for the idealized data in Figure 1 is shown in Figure 2 , along with a moving 50-day RPV average. Notice that RPV values are positive on up days and negative on down days. The average of the positive values over a particular time segment is called the up-relative-price-volume, or URPV, for the segment. Similarly, the DRPV, the down-relative-price-volume, is the average of the negative values. Table 1 shows a list of time frames of interest. We require that the ratio
alpha = URPV / DRPV
in frame 3 be larger than one, guaranteeing that up-volume exceeded down-volume while the right side of the cup formed. Similarly, we require that the ratio beta of the URPV in frame 3 to DRPV in frame 4 also be greater than one. (If the DRPV happens to be zero, we use a 50-day RPV average instead.) Thus we have the eighth and ninth requirements:
alpha > 1 and beta > 1.
Assuming the locations of the points K, A, B, C and D are known, these nine criteria are easily verified by the algorithm, and any pattern not meeting them all is ignored. Experience and experimentation with successful stocks have led us to establish minimum and maximum values for the length of (number of days in) each time frame. These are summarized in Table 1. The algorithm scans for all possible length-combinations that are within these limits: a total of 510,255 possibilities (a step size of 2 days is used in frame 2).
Depending on market conditions, screening a database of 10,000 or more stocks may yield from as few as ten to as many as one hundred successful candidates, and the need to rank these candidates arises. Each successful chart is ranked according to the ratios alpha and beta , which indicate how much more up-volume there is over down-volume, and a third ratio defined as
delta = PA / PK
which gives an indication of how strong the setup phase was. These are combined in one
parameter called Gamma and written
Gamma = Log(alpha) + Log(beta) + delta
Logarithms of alpha and beta must be taken because these ratios involve volumes and are generally so much larger than delta as to swamp its effects completely. The effect of the logarithm is to reduce the sizes of alpha and beta in a uniform way. Whenever a chart has more than one successful candidate pattern, the algorithm selects the one with the largest Gamma and prints its symbol, its Gamma value, and the lengths of the four time frames. The user may then inspect the stock's chart to see why this pattern was selected by the algorithm.
Some Examples
A database of 10,139 stocks was screened on February 10 of 1998, and fourteen stocks were
selected by the algorithm. Experience had shown that stocks with Gamma's exceeding 3.5
were the best candidates for breakout. Ten stocks of the fourteen had Gamma's exceeding
3.5, and are shown in Table 2 . Of these ten, seven subsequently
broke out on sufficient volume, with an average price increase from breakout to their peak
of 28%. Charts for four of these seven are shown in the figures below. Figure
3 shows the cup-and-handle pattern for BSTE as seen on the screening date 2/10/98. The
indicated surge in volume occurs during formation of the right side of the cup. Figure 4 shows the same pattern including the buy point and breakout
period, with the indicated surge in volume occurring near the buy point. Figure 5 and Figure 6 show the cup-and-handle
pattern for ARX. In Figure 6 , the indicated volume spike on 3/11
drove the stock through the $12.25 pivot (buy) point. This is followed by a 20% rise over
the next seven trading sessions. Figure 7 and Figure
8 show the cup-and-handle pattern for STS. In Figure 8 the
stock tries to break above the pivot price a few times in mid February, but the volume was
not sufficient to qualify it as a breakout. On 2/26 the stock broke soundly through the
$11.25 pivot point on nearly three times the 50 day average volume easily meeting the buy
criterion. Figure 9 and Figure 10 show the
cup-and-handle pattern for LCOS. The pivot price set on 2/3 was $43.63 (point C). In Figure 10, the stock tries to breakout on 2/17 at $43.75, but
reverses and closes down that day at $41.63. After a couple more aborted attempts, the
price finally clears and holds above $43.75 on 3/9, with sufficient volume to meet the buy
criterion. Using a tight sell-stop, the stock would have been sold on 3/17 at $40.50. The
pivot point would then have been reset to $43.75 (3/10's price) and the stock would have
been repurchased on 4/1 as it broke the new pivot point on sufficient volume as indicated.
Conclusions
These examples demonstrate the usefulness of computerized screening methods when
quantifiable chart patterns, and a large database of stocks are available. Although not a
perfect substitute for the human eye and mind, computerized screening can be an excellent
and efficient tool in the trader's arsenal.
However like any tool, in the hands of the inexperienced, it can be dangerous. Using O'Neil's CANSLIM approach, the buy region is very narrow, and very strict buy and sell disciplines are absolutely mandatory to be successful using this approach. One must wait until a stock breaks above its pivot point, and that breakout must be accompanied by sufficient volume. However because this approach requires a very tight stop loss, of 7 or 8 percent below the buy price, it is also critical to stick to the discipline of not paying more than a few percent above the pivot price. The combination of these two requirements often restricts the timeframe during which a stock can be bought to a single day or even a short window within a day.
Since new candidates emerge daily, and window during which those which breakout is so
short, a semi-automated combination of a daily computerized screening program together
with a live systems of price and volume alerts are extremely powerful tools in the hands
of a trader using the CANSLIM approach.
Acknowledgment
The authors wish to thank Bruce Cohen of BB&DD, Inc. for optimism and persistence that
such a program could be written and his technical assistance in carrying out the many
actual screenings over the years during which this algorithm was being developed.
References
1. O'Neil, William J. [1994]. How to Make Money in Stocks, McGraw-Hill.
2. Kuhn, Gregory J. [1994]. "Back to Basics Trading Stocks" Technical Analysis
of Stocks & Commodities, December.
3. Kuhn, Gregory J. [1995]. "The Cup-With-Handle Pattern", Technical Analysis of
Stocks & Commodities, March.
4. Kuhn, Gregory J. [1995]. "Trading with the Cup-With-Handle" Technical
Analysis of Stocks & Commodities , July.
5. Martinelli, Rick [1998]. Pattern Recognition in Time Series, Technical
Analysis of Stocks & Commodities, January.

Figure 1. An idealized price-volume chart of a cup-with-handle pattern

Figure 2. RPV values for the data in Figure 1 are shown by the columns.
The moving 50-day RPV average is indicated by the line.
Frame Number |
Location |
Name |
Minimum Length |
Maximum Length |
1 |
K - A |
Setup |
2 |
30 |
2 |
A - B |
Cup-leftside |
20 |
120 |
3 |
B - C |
Cup-rightside |
3 |
25 |
4 |
C - D |
Handle |
2 |
30 |
Table 1. Allowable time frames for the cup-with-handle pattern.
| Stock Symbol |
Gamma |
Setup (Days) |
LeftCup (Days) |
RiteCup (Days) |
Handle (Days) |
| HRB | 5.924 |
22 |
28 |
3 |
3 |
| STS | 5.799 |
22 |
70 |
3 |
7 |
| ARX | 5.598 |
28 |
70 |
4 |
3 |
| AGN | 4.460 |
30 |
80 |
3 |
3 |
| BSTE | 4.183 |
18 |
72 |
3 |
2 |
| REIN | 3.908 |
30 |
66 |
5 |
2 |
| ANV | 3.854 |
30 |
112 |
5 |
2 |
| LCOS | 3.737 |
24 |
20 |
3 |
4 |
| EQS | 3.634 |
30 |
72 |
3 |
4 |
| TKTM | 3.616 |
26 |
68 |
3 |
5 |
Table 2. Results of a search of 10,139 stocks on 02/10/98, ordered by
Gammas.
Figure 3. Cup-and-Handle pattern for BSTE as seen on the screening date 2/10/98. The
indicated surge in volume occurs during formation of the right side of the cup
Figure 4. Cup-and-Handle pattern for BSTE including the buy point and
breakout period. The indicated surge in volume occurs near the buy point
Figure 5. Cup-and-Handle pattern for ARX as seen on the screening date
2/10/98. The indicated surge in volume occurs during formation of the right side of the
cup
Figure 6. Cup-and-Handle pattern for ARX, including the buy point and breakout period.
The indicated volume spike on 3/11 drove the stock through the $12.25 pivot (buy) point.
This is followed by a 20% rise over the next seven trading sessions.
Figure 7. Cup-and-Handle pattern for STS as seen on the screening date 2/10/98. The
indicated surge in volume occurs during formation of the right side of the cup
Figure 8. Cup-and-Handle pattern for STS, including the Buy point and breakout period.
The stock tried to break above the pivot price a few times in mid February but the volume
was not sufficient to qualify it as a breakout. On 2/26 the stock broke soundly through
the $11.25 pivot point on nearly three times the 50 day average volume easily meeting the
buy criterion.
Figure 9. Cup-and-Handle pattern for LCOS as seen on the screening date 2/10/98. The
indicated surge in volume occurs during formation of the right side of the cup
Figure 10. Cup-and-Handle pattern for LCOS, including the buy point and breakout
period. The pivot price set on 2/3 was $43.63 (point C). The stock tried to breakout on
2/17 at $43.75 but reversed and closed that day down at $41.63. After a couple more
aborted attempts, the price finally cleared and held above $43.75 on 3/9, with sufficient
volume to meet the buy criterion.