Head & Shoulders, Algorithmically

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

Take the

Bond Challenge!
Use the IBKR Bond Scanner to compare
available yields against those of your broker.

Start Trading Today!


Interactive Brokers Rated #1
Best Online Broker 2019 by Barron’s* ibkr.com/comparechallenge

Member - NYSE, FINRA, SIPC – Supporting documentation for any claims and statistical information will be provided upon request. *Interactive Brokers
rated #1, Best Online Broker according to Barron’s Best Online Brokers Survey of 2019: February 25, 2019. For more information see, ibkr.com/info
Barron’s is a registered trademark of Dow Jones & Co. Inc.
03-IB20-1280CH1278
Traders take many paths to reach their destination.
Can your platform get you there?

Search apps and services to personalize the


NinjaTrader platform to meet your requirements.
Indicators, automated strategies, free tools & more.

Explore now at ninjatraderecosystem.com

Futures, foreign currency and options trading contains substantial risk and is not for every investor. Only
risk capital should be used for trading and only those with sufficient risk capital should consider trading.
Stocks & Commodities V. 31:5 (26-34): Head & Shoulders, Algorithmically, Part 2 by Giorgos E. Siligardos, PhD

Crossing The (Neck)line

Head & Shoulders, Algorithmically


Part 2
In part 1, we looked at how to find important milestone points necessary conditions that these points must meet in order to
BRIAN TAYLOR

in a head & shoulders formation. In this, the second article outline an H&S. Being aware of these conditions will help
of a two-part series, we present an algorithm that will let the you create an identification algorithm.
computer find the formations for us.
Metrics and notations
by Giorgos E. Siligardos, PhD Before delving into the conditions, I will define some of the

In
important points and metrics (see Figure 2):
Figure 1, you can see what I call milestone points for
a completed closing-price head & shoulders (H&S) n V is the highest closing price during the time span
formation — that is, an H&S formation generated by between L0 and H1
the closing price where it has penetrated the neckline. However, n W is the highest closing price during the time span
these milestones are defined regardless of whether there is an between L3 and the last closing price
H&S pattern present. In this article, I will elaborate on the
Copyright © Technical Analysis Inc.
Stocks & Commodities V. 31:5 (26-34): Head & Shoulders, Algorithmically, Part 2 by Giorgos E. Siligardos, PhD

n The time distance (number of bars) between H1


and H will be called Dist1 and the time distance
between H and H2 will be called Dist2
n The time distance between L0 and L1 will be called
Dist1#, the time distance between L1 and L2 will
be called Dist#, and the time distance between L2
and L3 will be called Dist2#
n t1 will be the time distance between H1 and L1 and
t2 will be the time distance between L2 and H2.
Figure 1: milestone points in a head & shoulders formation. The red points are
The conditions milestones for the H&S since connecting them one after the other provides an outline of the forma-
tion. They also facilitate the creation of an identification algorithm.
The first condition has to do with the vertical distance
relationship between H1 and H as well as between H2
and H. We want H1 to be sufficiently higher than
L1, but not too close to H. In addition, H2 must
be sufficiently higher than L2 but again not too
close to H (see Figure 2).

Condition 1
L1+20% · (H-L1) < H1 < H-15% · (H-L1)
and
L2+25% · (H-L2) < H2 < H-25% · (H-L2)

The next two conditions deal with L2 and its


vertical distance relationship to H and L1. First,
we want L2 to be greater than L1 or at least
not too much lower than L1 (thus excluding
those H&S formations having necklines of very
negative slope). L2 must also be closer to the
level of L1 than the level of H. Moreover, if L2
is significantly greater than L1, then we don’t
want the maximum (namely J) of the closing
price during the rightmost one-third time span
between H and L2 to approach the level of H Figure 2: metrics and notation. Several metrics and notations for the H&S pattern are presented here.
The help provided by the milestone points for this task is readily evident.
(see Figure 3).

Condition 2
L1-15% · (H-L1) < L2 < L1+40% · (H-L1)

Condition 3
If L2 > L1+20% · (H-L1) then J < L2+70% · (H-L2)

Conditions 4 and 5 take care of the shoulders’ vertical lengths


(Figure 2). On the one, the difference between the shoulders’
lengths must not exceed the lower of them and on the other, we
don’t want the shoulders’ lengths to be much shorter than the
head’s length or, if they are, then they must have significant
time duration in relation to the time distance between the lows
L1 and L2 (| · | denotes the absolute value):

Condition 4
| (H1-L1)-(H2-L2) | < Min( H1- L1, H2-L2 )
Figure 3: the third condition. J is the maximum of the
closing price during the right-most one-third time span between
Condition 5 H and L2 (cyan area). If L2 is much higher than L1, then we don’t
( (H1-L1) > 25% · (H-L1) and (H2-L2) > 25% · (H-L2) ) want J to approach the level of H so that the right shoulder is
distinguished from the head.

Copyright © Technical Analysis Inc.


Stocks & Commodities V. 31:5 (26-34): Head & Shoulders, Algorithmically, Part 2 by Giorgos E. Siligardos, PhD

Figure 4: putting restrictions in price swings between Figure 5: restrictions in price swings
the left shoulder and the head. If A is the highest closing price during the right shoulder. For the eighth
in the left half between L1 and H (pink area) and B is the lowest closing condition we divide the time span between L2 and
price in the right half (cyan area), then we don’t want the vertical distance H2 in three equal parts. If Q is the maximum of the
between A and B to exceed the half of the vertical distance between L1 closing price inside the first part (cyan area) and S
and H. This is the seventh condition for the algorithm and ensures that is the minimum of the closing price inside the third
there will be no large price swings in the left part of the head and so that part (pink area), then we don’t want Q to be close to
the head and the left shoulder are clearly distinguishable. H2 and S to be close to L2 at the same time.

or or
Min (t1, t2 ) > 25% · Dist# S ≥ L2 + 0.4*(H2–L2)

The next condition puts restrictions in some time distances. The final condition, condition 9, has to do with the V and W
The maximum of Dist1 and Dist2 must be less than 2.5 times points defined at the beginning of this article (see Figure 2).
the minimum of them. Also, the maximum of Dist1# and We don’t want W to be too high relative to the level of H2,
Dist2# must be less than three times the minimum of them and V to be too close to the level of H.
(Figure 2):
Condition 9
Condition 6 W < L3+(H2–L3)/3
2.5 · Min(Dist1, Dist2) > Max(Dist1,
Dist2) and
V < H – 0.15*(H–L1)
and
3 · Min(Dist1#, Dist2#) > Max(Dist1#, The identification of milestone points presented last month
Dist2#) in part 1 and the nine conditions presented here give you the
information necessary for a recognition algorithm for H&S
Condition 7 has to do with price swings between L1 and formations.
H. We don’t want the vertical distance between A and B to be
greater than half of the vertical distance between L1 and H Outlining the H&S
(see Figure 4). It is possible to roughly outline an H&S formation identified
Condition 7 by the algorithm using the graph of a function. A relatively
simple function f that you can use is provided in the sidebar,
|A – B| < (H-L1)/2
“A Function To Outline The H&S on page 33).” Note that f is
merely used to outline the formation and it is not stringent.
Similar to the previous condition, the next one, condition
8, places restrictions in price swings between L2 and H2
(Figure 5). We don’t want the closing price to come close to
Applying the algorithm
The algorithm is not a trading system. It is merely a pattern-
the level of H2 right after passing from L2 (and way before
recognition tool. Its usefulness is threefold. First, chart pattern
H2) and then come back down to the level of L2 right before
lovers can use it to scan baskets of stocks, find those that
passing from H2. For this, we divide the time span between
recently formed H&S formations, and add them to watchlists.
L2 and H2 in three equal parts (1), (2), and (3); we denote Q
Second, it can be used as a research tool to check the reliability
the maximum of the closing price inside (1); and we denote
and potential profit of the formation in conjunction with other
S the minimum of the closing price inside (3):
tools (volume, moving averages, fundamentals, and so on).
Condition 8 Third, it can be used as a basket of ideas for researchers to
Q ≤ L2 + 0.8*(H2-L2) create their own pattern-recognition methods.
The algorithm does not use loops per se, so it can be

Copyright © Technical Analysis Inc.


Stocks & Commodities V. 31:5 (26-34): Head & Shoulders, Algorithmically, Part 2 by Giorgos E. Siligardos, PhD
PATTERN RECOGNITION
Eastman Kodak Co. (daily)

implemented in most technical analysis


platforms. In software that doesn’t provide
looping functions, you can use it in a static
fashion to scan and find H&S formations
for a specific date. If your platform offers
loops, you can use it to recursively apply
the algorithm and at a glance, see how it
performs historically in a chart. You can
also use loops to successively apply various
parameter values to the algorithm. This will
increase its effectiveness.

Examples
As I stated at the beginning of this article, the
algorithm identifies H&S formations gener-
ated by the closing price where the price has
penetrated the neckline. In Figure 6, you can
see an example of the algorithm in action. A
389-bar H&S formation was identified in a
daily chart of Kodak (EKDKQ) for March

MetaStock
3, 2011, after a severe price decline. The red
curve outlining the formation is generated by Figure 6: a continuation H&S. The algorithm identified a 389-day H&S formation for March 3, 2011. The forma-
the graph of function f mentioned earlier. tion took place after a severe decline in the stock price and led prices down further.
In Figure 7, you see another example
where a 91-bar H&S formation was identi-
fied for March 3, 2011, in Comerica (CMA).
This H&S took place during a sideways
price movement. In particular, the H&S
was the second top inside a double-top Comerica Inc. (daily)
reversal formation.
On the chart of Monsanto (MON) in Figure
8, you see an H&S after a price plunge. Two
things must be stressed in this example. First,
the H&S is not easily caught by the eye un-
less the time axis of the chart is condensed,
because the shoulders are somewhat tall with
respect to the head. Second, the H&S wasn’t
able to continue the previous decline right
away. More precisely, right after the iden-
tification of the formation by the algorithm,
the price bounced and rose swiftly near the
top of the second head before plummeting
again into new lows. This is indicative of
what the algorithm can do: merely identify
the formation. It is by no means a trading
system. Note also that since the algorithm

Here is a relatively simple


yet powerful algorithm Figure 7: a H&S hidden inside a double top. The algorithm identified a 91-day H&S formation on March 3,
to automatically detect 2011. This H&S was actually hidden as the second top of a double-top formation that finally led prices down to $22
H&S formations the way a in the months that followed.

technical analyst detects


them with his eyes.
Copyright © Technical Analysis Inc.
Stocks & Commodities V. 31:5 (26-34): Head & Shoulders, Algorithmically, Part 2 by Giorgos E. Siligardos, PhD
PATTERN RECOGNITION

Monsanto. (Daily)
spots H&S formations after the neckline is broken, it is not
Monsanto. (Daily) unusual for the price (which is usually oversold) to bounce
upward before deciding where it wants to go.
On the daily chart of Pfizer (PFE) in Figure 9, the algorithm
spotted two short-duration H&S patterns. The early H&S (not
outlined by the red curve but encompassed by a black ellipse),
although bearish in nature, didn’t produce a price decline, while
the second H&S became a reversal top.
In Figure 10, you can see that the algorithm works well in
time frames other than the daily. It identified a 182-bar H&S
on the weekly chart of DR Horton (DHI).
In the sidebar, “Head & Shoulders Code For MetaStock,”
available at http://www.traders.com/files/Siligardos-Meta­
stock.html, you will find the MetaStock code used in these
examples. This code uses a simplified version of the algorithm
I discussed last month in part 1 of this article regarding the
identification of milestone points (see “Related reading”).
This simplification was necessary because of the limitations
in MetaStock’s formula editor. However, the reduction in the
quality and quantity of the H&S formations recognized due
MetaStock

to this simplification is minimal.


Figure 8: an example of H&S with undesired consequences. An H&S was
identified by the algorithm on February 11, 2009. The H&S lasted 203 days and immediately Checking historical
after its identification, the price bounced and rose near the top of the second head in only performance
two months before plummeting again into new lows. That is why the algorithm — being
merely an identification tool — should not be used as an automatic trading system. Its
I have already pointed out that recursively applying the al-
timing is not always good. gorithm backwards (dropping the current last bar every time
Pfizer Inc. (daily)

Pfizer Inc. (daily)


Second H&S identified
on Feb 4, 2010
DR Horton Inc. (daily)
Second H&S identified
on Feb 4, 2010

First H&S identified


on Feb 11, 2010
First H&S identified
on Feb 11, 2010

Figure 9: identifying short-lasting H&S. The algorithm identified a very short- Figure 10: H&S On A weekly chart. On July 13, 2007, an H&S formation lasting 182
lasting H&S (only 19 days) on February 11, 2009 (enclosed in a black ellipse). The formation bars (weeks) was identified by the algorithm on the weekly chart of DR Horton. This H&S
appeared after a multimonth uptrend and led prices even higher. Later, on February 4, is special since the head & shoulders were H&S patterns themselves.
2010, the algorithm identified a 22-day H&S (see red curve produced by the function f ),
which resulted in a severe price decline.

Copyright © Technical Analysis Inc.


Stocks & Commodities V. 31:5 (26-34): Head & Shoulders, Algorithmically, Part 2 by Giorgos E. Siligardos, PhD

Boyd Gaming Corp. (daily)

S&C-H&S recursive
AMIBROKER

Figure 11: using the algorithm in a RECURSIVE fashion. The upper chart shows the daily closing price of Boyd Gaming and the bottom chart shows the
S&C-H&S recursive indicator in red. Eight H&S formations are identified by the algorithm, and seven of them produced price declines. The blue vertical lines mark the
identification dates.

a new application of the algorithm is performed) is an easy The code for the S&C-H&S recursive indicator used in this
way to check its historical performance in a chart and backtest example can be found in the sidebar, “Recursive Indicator
strategies and ideas related to H&S. This can be accomplished Code For AmiBroker” on page 34, and is available at http://
if you use software that offers looping functions. www.traders.com/files/Siligardos-Amibroker.html. Note that
You can see an example on the daily chart of Boyd Gam- when you recursively apply the algorithm thousands of times
ing (BYD) in Figure 11 plotted in AmiBroker. The bottom in a program, you should use speed-optimized code, otherwise
chart has the S&C-H&S recursive indicator plotted in red. the calculations will be extremely slow.
This indicator recursively applies the identification algorithm I should also stress that although Figure 11 shows very
(starting by using all the data of the chart and then recursively promising results for bearish implications of H&S formations
eliminating the “each time-last bar”) and returns the duration (only the fifth one didn’t produce a price decline), things
of the H&S it finds. So, the value of the indicator for a bar are not always that good. If you check the reliability of the
is the duration of the H&S it found using data up to that bar. H&S using the algorithm presented here you will notice that
If no H&S is found for a bar, then the corresponding indica- the H&S pattern is often tricky and not that powerful on its
tor’s value is zero. As can be seen, the algorithm was able to own to initiate significant price declines. Additional filters
identify eight H&S formations for the time span shown in the and information must be used before stepping in to take the
chart (depicted by blue rectangles): short side of the market, and pure technical analysts must use
price targets (usually a fraction of the head’s distance from
the neckline) and stop-loss levels.
H&S duration
# Date identified
(bars) Estimating targets
1 February 15, 2008 18 Technical analysts usually measure the distance between the
2 March 20, 2008 23 head’s high and its vertical projection to the neckline. Then
3 February 3, 2009 32 starting from the projection point they subtract percentage
4 October 28, 2009 57 multiples of this distance to derive price targets. In the sidebar
“Estimating Price Targets,” you can see how you can plot
5 February 25, 2010 14
necklines and estimate percentage targets using the milestone
6 June 4, 2010 27 points L1, L2, and H for the H&S formations identified by
7 November 8, 2010 26 the algorithm.
8 October 2, 2011 147 In Figure 12, you can see an example where the formulas for
determining the neckline and 50% target are applied in the daily
chart of Host Hotels & Resorts (HST) for December 23, 1997,
Copyright © Technical Analysis Inc.
Stocks & Commodities V. 31:5 (26-34): Head & Shoulders, Algorithmically, Part 2 by Giorgos E. Siligardos, PhD
A FUNCTION TO OUTLINE THE H&S

A visually nice and easy way to roughly outline the stems of an H&S
formation in a chart is by using the graphs of semi-ellipses. The
graph of the following function f generally gives good results for the
formations identified by the algorithm:
The algorithm will be useful
as a tool to create watchlists
⎧ b1 2
⋅ a12 − (x − c1 ) , if x 0 ≤ x ≤ x1 of securities, test the reliabil-
⎪L1 +
⎪ a 1 ity of H&S with other filters,
⎪ b 2
and create trading plans.
f ( x) = ⎨L2 + ⋅ a 2 − (x − c ) , if x1 ≤ x ≤ x 2
⎪ a
� a2
�⎪L3 + 2b×2 a 2 �2(x � c 2 ) ,2 if x 2 � x � x 3
�⎪ L3 +b a ⋅ 2a 2 − (x − c2 2 ) , if x 2 ≤ x ≤ x 3
�⎩ a
2
Power of the pattern
f ( x) = �L2 + × a 2 � (x � c ) , if x1 � x � x 2 While there are academic papers that discuss the identification
b variable, x0, x21, x2, x3 are the time moments of
where x �is the time
L0, L1, L2� and L3, and backtesting of H&S formations, they don’t usually use
a1 respectively, and:
�L1 + × a1 � (x � c1 ) , if x 0 � x � x1 versatile recognition algorithms and often miss formations a
� b1 # 2 2
technical analyst would catch. This article provides a relatively
 a1 = Dist1 / 2  b2 = 1.1* (H2–L3)
 a = Dist# / 2  c1 = (x0+x1) / 2 simple yet powerful algorithm to automatically detect the ma-
jority of H&S formations in price charts the way a technical
 a2 = Dist2# / 2  c = (x1+x2) / 2
analyst detects them with his eyes. The algorithm will be useful
 b1 = (H1+3*V) / 4 – L1  c2 = (x2+x3) / 2 as a tool to create watchlists of securities, test the reliability of
 b = 1.1 * (H–L2) H&S with other filters, and create trading plans. You can also
use it as a basket of ideas to create your own pattern-recognition
algorithm for H&S.

and in the sidebar, “Head & Shoulders Code For MetaStock,” you Giorgos Siligardos holds a doctorate in mathematics and a
can find the MetaStock code that plots them automatically. Market Maker certificate from the Athens Exchange. He is a
Note that since the milestone points L1 and L2 are not always financial software developer, coauthor of academic books in
prominent minima, the targets derived by the above formulas are finance, frequent contributor to Technical Analysis of Stocks
just rough estimates of what a technical analyst would compute & Commodities, and scientific contributor in the Department
as precise targets.

Increasing its
effectiveness
Although versatile and applicable Host Hotels & Res. (daily)
when using the default values for
its parameters, the algorithm is not
a panacea and it will occasionally
miss some nice-looking H&S. To
decrease its false-negative rate and
make it more versatile and effective,
you can use loops to successively ap-
ply it for various contiguous values
for its parameters. Recall from part
1 of the article that two parameters
are used: the positive integer n with
a default value of 5, and the real
positive number factor with a de-
fault value of 1. You can therefore
successively apply the algorithm for
various integer values of n greater
than 1 (the higher the n, the more
long-lasting H&S will be on your
METASTOCK

radar) and you can also successively


apply the algorithm for various
values of factor ranging from 0.80 Figure 12: A Daily chart with neckline and target plotted automatically. The neckline (in green) and
the 50% target level (in blue) are calculated and plotted automatically by MetaStock. The f function, which outlines the H&S
to 1.20 to capture less symmetrical formation, is also plotted in red. The 50% target of $10.07 was actually reached at the very next candle (not shown in this
H&S formations. chart). A 100% target was attained several months later, only after the price challenged the right shoulder’s top again.

Copyright © Technical Analysis Inc.


Stocks & Commodities V. 31:5 (26-34): Head & Shoulders, Algorithmically, Part 2 by Giorgos E. Siligardos, PhD
RECURSIVE INDICATOR CODE FOR AMIBROKER

The following code for AmiBroker is for the S&C-H&S recursive indica- L3=LastValue(ValueWhen(BarIndex()==L3b,price,1));
tor shown in Figure 11. This code uses the logic from the MetaStock L0b=LastValue( ValueWhen(Ref(price,-LastValue(BarIndex()-H1b))<=L1+0.2*(H1-
L1), BarIndex(),1)-LastValue(BarIndex()-H1b));
code given in the previous sidebar and is used mainly for illustration L0=LastValue(ValueWhen(BarIndex()==L0b,price,1));
purposes. It is not optimized for speed performance in AmiBroker. // start conditions
Conditions[0]=0;
_SECTION_BEGIN("S&C - H&S recursive"); //condition 1
SetBarsRequired( sbrAll, sbrAll ); Conditions= (H1>(L1+0.20*(He-L1))) AND
//by Giorgos Siligardos, 2011 (H1< (He-0.15*(He-L1))) AND
//parameters (H2>(L2+0.25*(He-L2))) AND
Lookbackbars=1500; (H2< (He-0.25*(He-L2))) AND
LastLLVparam=5; //n //conditions 2 and 3
factor=1; //factor (L2<(L1+0.40*(He-L1))) AND
//Global constants & indicators IIf(L2>L1+0.20*(He-L1),LastValue(HHV(Ref(price,-LastValue(BarIndex()-L2b))
LastIndex=BarCount-1; ,LastValue(int(Max((L2b-Heb)/3,1)))))<L2+0.7*(He-L2),1) AND
InertiaIndex=LastIndex-Lookbackbars; (L2>(L1-0.15*(He-L1))) AND
//alogorithm //condition 4
for (j=0; j<=LastIndex; j++) {HSperiod[j]=0;}; abs((H1-L1)-(H2-L2))<Min(H1-L1,H2-L2) AND
for (i=Max(1500,InertiaIndex); i<=LastIndex; i++) //condition 5
{ (((H1-L1)>0.25*(He-L1) AND (H2-L2)>0.25*(He-L2)) OR Min(L1b-H1b,H2b-
price= Ref(C,-LastIndex+i); L2b)>0.25*(L2b-L1b)) AND
//reference points //condition 6
p1=LastValue(LLV(price,LastLLVparam)); 2.5*Min(Heb-H1b,H2b-Heb)>Max(Heb-H1b,H2b-Heb) AND
He=LastValue(HHV(price,LastValue(Max(1,BarsSince(price<p1))))); 3*Min(L1b-L0b,L3b-L2b)>Max(L1b-L0b,L3b-L2b) AND
Heb=LastValue(ValueWhen(price==He,BarIndex(),1)); //condition 7
RHalf=LastValue(Max(1,BarIndex()-Heb)); abs( LastValue( HHV(Ref(price,-LastValue(int(RHalf+(Heb-
LHalf=factor*RHalf; L1b)/2))),LastValue(int((Heb-L1b)/2)))) - LastValue( LLV(Ref(price,-LastValue(int(
b0=LastValue(Min(BarIndex()-RHalf-LHalf,BarIndex()-BarsSince(price<p1))); RHalf))),LastValue(int((Heb-L1b)/2)))))<(He-L1)/2 AND
tL1=LastValue( LLV(Ref(price,-RHalf),LastValue(Max(1,int(2*LHalf/3)))) ); //condition 8
tL1b=LastValue(ValueWhen(Ref(price,-RHalf)==tL1,BarIndex())-RHalf,1); (LastValue(HHV(Ref(price,-LastValue(BarIndex()-H2b+int(2*(H2b-
H1=LastValue(HHV(Ref(price,-LastValue(BarIndex()- L2b)/3))),LastValue(Max(1,int((H2b-L2b)/3))) ))>(L2+0.8*(H2-L2)) AND
tL1b)),LastValue(Max(1,tL1b-b0)))); LastValue(LLV(Ref(price,-LastValue(BarIndex()-H2b)), LastValue(Max(1,int((H2b-
H1b=LastValue(ValueWhen(Ref(price, -LastValue(BarIndex()-tL1b L2b)/3)))))<(L2+0.4*(H2-L2)))==0 AND
))==H1,BarIndex(),1)-LastValue(BarIndex()-tL1b)); //condition 9
eltimi=LastValue(LLV(Ref(price,-LastValue(BarIndex()-tL1b)), LastValue(Max(1,tL1b- LastValue(HHV(price,LastValue(Max(1,BarIndex()-L3b))))<L3+(H2-L3)/3 AND
H1b)))); (LastValue(HHV(Ref(price,-LastValue(BarIndex()-H1b) ),LastValue(Max(1,H1b-
L1b=LastValue(ValueWhen(Ref(price,-LastValue(BarIndex()-tL1b))<=((tL1+2*eltimi)/3 L0b)))) < (He-0.15*(He-L1))) AND
),BarIndex()-LastValue(BarIndex()-tL1b),1)); //end conditions
L1=LastValue(ValueWhen(BarIndex()==L1b,price,1));
L2=LastValue(LLV(Ref(price,-LastValue(int(RHalf/3))),LastValue(Max(1,2*int(RHal IsEmpty(LastValue(L0b))==0;
f/3)))) ); HSperiod[i]=LastValue((L3b-L0b)*Conditions);
L2b=LastValue(ValueWhen(Ref(price,-LastValue(int(RHalf/3)))==L2,BarIndex(),1)- }
LastValue(int(RHalf/3))); Plot(HSperiod, "S&C - H&S recursive", colorRed );
H2=LastValue(HHV(price,LastValue(Max(1,BarIndex()-L2b)))); _SECTION_END();
H2b=LastValue(ValueWhen(price==H2, BarIndex(),1));
L3b=LastValue(ValueWhen(Cum(BarIndex()>H2b AND price<=L2)==1,BarIndex(),1) );

Copyright © Technical Analysis Inc.


Stocks & Commodities V. 31:5 (26-34): Head & Shoulders, Algorithmically, Part 2 by Giorgos E. Siligardos, PhD
ESTIMATING PRICE TARGETS
To derive price targets from the milestone points L1, L2, and H, according
to classic technical analysis, you must first find point M (green point in
sidebar Figure 1), which is the vertical projection of H down to the neckline
connecting L1 and L2. If d1 denotes the distance between L1 and H, and
d2 denotes the distance between H and L2, then:
(L2 − L1)
M = L1+ ⋅ d1
(d1 + d2)

You can then calculate % targets (technical analysts usually consider


50% and 100% ones) by subtracting percentage multiples of the distance
between H and M from M. That is, an r% target is defined as:

M − r% ⋅ (H − M )

To plot the neckline of the formation you can use the math formula for plot-
ting a line from two known points. The neckline can therefore be expressed
as a function of time x as:
(L2 − L1)
Neckline(x) = L1+ ⋅ (x − x1 ) SIDEBAR Figure 1: popular price targets. The green point M is the vertical
(x 2 − x1 )
projection of H down to the neckline. Two common price targets of 50% and 100% can
be derived by respectively subtracting 50% and 100% multiples of (H-M) from M.
where x1, x2 are the time moments of L1, L2, respectively.

of Finance and Insurance at the Technological Institute of See the Traders’ Tips section beginning on page 50 for commentary
Crete. Material from his course writings on derivatives has and implementation of Giorgos Siligardos’ technique in various
been used in educational texts for bank managers. His aca- technical analysis programs. Accompanying program code can be
demic website is http://www.tem.uoc.gr/~siligard and he may found in the Traders’ Tips area of Traders.com.
The code provided in this article for MetaStock can be found at
be reached at siligard@tem.uoc.gr.
our website at www.traders.com/files/Siligardos-Metastock.html.
The code provided in this article for AmiBroker can be found at our
Related reading website at www.traders.com/files/Siligardos-Amibroker.html.
Siligardos, Giorgos [2013]. “Head & Shoulders, Algorithmi-
cally (Part 1),” Technical Analysis of Stocks & Commodi- ‡MetaStock, ‡AmiBroker
ties, Volume 31: April.

Copyright © Technical Analysis Inc.


Powerful Signals for Stocks & Commodities

Long Term & Short Term

Works with stocks, commodities, futures, options, FOREX, bonds for intra-day or position trading
Triple Confirmed Buy/Sell Signals

Traders Rave Over AbleTrend

SINCE 1994
ABLETREND 7.0 COLLECTED BY

Test-drive it to See All the Signals!

THESE RESULTS ARE BASED ON SIMULATED OR HYPOTHETICAL PERFORMANCE RESULTS THAT HAVE CERTAIN INHERENT LIMITATIONS. UNLIKE THE RESULTS SHOWN IN AN ACTUAL PERFORMANCE RECORD, THESE RESULTS DO NOT
REPRESENT ACTUAL TRADING. ALSO, BECAUSE THESE TRADES HAVE NOT ACTUALLY BEEN EXECUTED, THESE RESULTS MAY HAVE UNDER-OR OVER-COMPENSATED FOR THE IMPACT, IF ANY, OF CERTAIN MARKET FACTORS, SUCH AS
LACK OF LIQUIDITY. SIMULATED OR HYPOTHETICAL TRADING PROGRAMS IN GENERAL ARE ALSO SUBJECT TO THE FACT THAT THEY ARE DESIGNED WITH THE BENEFIT OF HINDSIGHT. NO REPRESENTATION IS BEING MADE THAT ANY
ACCOUNT
ACCOUN WILL OR IS LIKELY TO ACHIEVE PROFITS OR LOSSES SIMILAR TO THESE BEING SHOWN. THE TESTIMONIAL MAY NOT BE REPRESENTATIVE OF THE EXPERIENCE OF OTHER CLIENTS AND THE TESTIMONIAL IS NO GUARANTEE
OF FUTURE PERFORMANCE OR SUCCESS. TECHNICAL ANALYSIS OF STOCKS & COMMODITIES LOGO AND AWARD ARE TRADEMARKS OF TECHNICAL ANALYSIS, INC.
Because you
can never have
too many
PowerTools

17 is Here
Featuring the NEW OptionScope™
and QuoteCenter™ PowerTools
Discover the latest features at metastock.com/whats-new
subscribe or renew today!
Every Stocks & Commodities subscription
(regular and digital) includes:
• Full access to our Digital Edition
The complete magazine as a PDF you can download.
• Full access to our Digital Archives 8999
1 year.................
$
That’s 35 years’ worth of content!

2 years............ 149
• Complete access to WorkingMoney.com $ 99
The information you need to invest smartly and successfully.

3 years............ 199
• Access to Traders.com Advantage $ 99
Insights, tips and techniques that can help you trade smarter.

PROFESSIONAL TRADERS’ STARTER KIT


A 5-year subscription to S&C magazine that includes
everything above PLUS a free* book, Charting The Stock
Market: The Wyckoff Method, all for a price that saves
you $150 off the year-by-year price! *Shipping & han-
dling charges apply for foreign orders.

5 years..........
$
29999
That’s around $5 a month!

Visit www.Traders.com to find out more!


Email: Circ@Traders.com • Phone: 206-938-0570 facebook.com/STOCKSandCOMMODITIES @STOCKSandCOMM

You might also like