Algorithmic Detection of Head-and-Shoulders Chart Patterns
Summary
The discussion explains ways to turn visual chart patterns into rules a program can evaluate. It presents a head-and-shoulders definition based on five consecutive local extrema: the middle peak is higher than the outer peaks, while the two shoulder values and the two intervening troughs are each close to one another. The inverted pattern reverses the peak and trough relationships. The quoted definition uses a stated 1.5 percent tolerance for these comparisons.
Other suggestions include dynamic time warping, neural networks, wavelets, and general image-recognition methods. The discussion also points to research on computational technical analysis and empirical pattern evaluation. Contributors disagree about the trading value of such patterns: some cite studies of potential profitability, while others caution that pattern recognition does not demonstrate a profitable strategy. The criteria are a starting point rather than an exhaustive specification, and any trading use would require separate empirical validation, including attention to the gap between detecting a shape and earning returns from it.
Key ideas
- A head-and-shoulders pattern can be represented as an ordered sequence of five local extrema.
- The stated rule compares the central peak with the shoulders and applies tolerances to paired extrema.
- An inverted pattern uses the corresponding reversed relationships between peaks and troughs.
- Dynamic time warping and machine-learning methods are alternative approaches to recognizing chart shapes.
- Recognizing a pattern does not establish that trading it will be profitable.
Tags
Full text
# How to identify technical analysis chart patterns algorithmically?
# How to identify technical analysis chart patterns algorithmically?
I'm working on a small application that will provide some charts and graphs to be used for technical analysis. I'm new to TA but I'm wondering if there is a way to algorithmically identify the formation of certain patterns. In most of the TA literature I've read the authors explain how to identify these patterns visually. Is there a way to algorithmically determine these patterns so that I could, for example, examine the prices in code and identify a possible Head and Shoulders pattern?
## Answer by Tal Fishman (score 29, accepted)
https://quant.stackexchange.com/a/1938
As mentioned elsewhere on this site, Lo, Mamaysky, and Wang (2000) do exactly what you're talking about, namely algorithmic detection of head and shoulders patterns. Their definition:
> Head-and-shoulders (HS) and inverted head-and-shoulders (IHS) patterns are characterized by a sequence of five consecutive local extrema $E_1,...,E_5$ such that $$ HS \equiv \begin{cases} E_1 \text{ is a maximum} \\ E_3 > E_1, E_3 > E_5 \\ E_1\text{ and }E_5\text{ are within 1.5 percent of their average} \\ E_2\text{ and }E_4\text{ are within 1.5 percent of their average,} \end{cases} $$ $$ IHS \equiv \begin{cases} E_1\text{ is a minimum} \\ E_3<E_1, E_3 < E_5 \\ E_1\text{ and }E_5\text{ are within 1.5 percent of their average} \\ E_2\text{ and }E_4\text{ are within 1.5 percent of their average.} \end{cases} $$
## Answer by NPE (score 20)
https://quant.stackexchange.com/a/1939
I would recommend that you read "Evidence-Based Technical Analysis" by David Aronson.
Firstly, I am mentioning it because it is a highly worthwhile book.
Secondly, on pp151--161 he attempts to "objectify subjective TA", using the head-and-shoulders pattern as an example.
## Answer by MarianP (score 19)
https://quant.stackexchange.com/a/3966
Dynamic Time Warping, recursive, time-delayed feedforward neural networks, wavelets, empirical mode decomposition, ..., there's plenty of it.
BUT If you want my advice, don't go this way, I wasted too much time doing things like that. Neither big nor small players (profitably and consistently) trade this way and for a good reason. Technical analysis is a technology of prehistoric pre-computer era and those patterns are only there after the fact. All those websites, books etc. on that is just a way of incapable people trying to make money on the market in a secondary way. There's few empirical reasons for anyone to share his trading knowledge if it works. Once you have your own stuff, you surely won't be giving it away. And if, why would you as a successful trader try to sell expensive books or trading recommendations? Most of the stuff, starting with technical analysis, is basically a scam or useless spam. You certainly won't make money if you do things too many people know about, that's in the nature of what market is. Go real science.
## Answer by vonjd (score 7)
https://quant.stackexchange.com/a/25980
One idea is Dynamic time warping (DTW).
There is an R package for that: dtw
Here is the vignette: Computing and Visualizing Dynamic Time Warping Alignments in R: The dtw Package by Toni Giorgino
And here is an example from Systematic Investor with full code: Time Series Matching with Dynamic Time Warping
## Answer by Sidharath (score 2)
https://quant.stackexchange.com/a/7396
Regarding trading, it depends upon one's style and temperament. Don't rely solely on Aronson's book and his views and a phrase quoted by Andrew Lo in his study. The formula posted by Tal Fishman of Head and Shoulders as quoted by Lo, Mamaysky and Wang (2000) is not exhaustive. There is a lot of scope for further improvement.
However, there are many studies which have proved that profits can be made trading the patterns. You can read them. They are as follows:
- Bulkowski, T.N. (2000) Encyclopedia of Chart Patterns, John Wiley and Sons, NewYork.
- Laedermann, S. (2000), “Head-and-Shoulders Accuracies and How to Trade Them.” IFTA Journal, Vol. 2000 Edition, pp 14-21
- Lo, A., Mamaysky, H. and Wang, J. (2000), “Foundations of Technical Analysis: Computational Algorithms, Statistical Inference, and Empirical Implementation.” Journal of Finance, Vol. 55, pp. 1705-1765
- Osler, C. L., and Chang, P. H. K., (1995) “Head and Shoulders: Not Just a Flaky Pattern.” Federal Reserve Bank of New York, Staff Reports, Report No. 4.
## Answer by Robert Jakubowski (score 1)
https://quant.stackexchange.com/a/7443
Well pattern recognition and image processing is so developed these days. This is cutting edge in CS now and if we could identify cancer or brain tumor on a hazy image or a suspect face on an industry cam then recognizing head and shoulders on a chart is really really easy.
Support Vector Machines or entropy come to mind but there is a myriad of technologies and they are easily available and so is the processing power for the job.
However there is a big leap between recognizing the pattern and using it as a base for successful trading. You could put a lot of effort and computer power (mind the CO2 it generates) into vain.
Very educational approach though. At least for me it was.Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.