Trading Harmonic Patterns 2
Trading Harmonic Patterns 2
would be discussed afterwards. The study aims to investigate the occurrence of the common bullish
harmonic patterns in the US stock, Forex, and Crypto markets and the profitability of trading with
these patterns in a single instrument. Two algorithms of scanning harmonic patterns will be examined,
in terms of their accuracy, followed by analyzing the profitability.
In Section 3, the data, tools, and evaluation metrics for the profitability of trading harmonic patterns
are described. Next, Section 4 explains the details of each harmonic pattern and the process flow of a
backtesting program. In Section 5, the accuracy of the first pattern matching algorithm and the
drawback are discussed. In Section 6, the second pattern matching algorithm is introduced and is used
to evaluate the profitability of the bullish Gartley pattern in different markets. Thereafter, Section 7
analyzes other popular bullish harmonic patterns, including the butterfly, the bat, and the crab, and
Section 8 concludes the work.
3.1 Data
Mainly three instruments are used throughout the study:
The SPDR S&P 500 ETF Trust tracks the Standard & Poor’s 500 Index, which is comprised of 500
large companies listed on the stock exchanges in the United States and represents the stock market’s
performance. The second instrument, the currency pair EUR/USD, indicates how many US Dollars are
needed to purchase 1 Euro while the BTC/USD pair shows the price of 1 Bitcoin in US Dollars. The
three instruments are the most-traded ones in the US stock, Forex, and Crypto market, respectively,
and are chosen to be the representative of these three markets.
The data used in the study are obtained from the historical data feed of the Dukascopy Group. Since
the earliest data of SPY and the BTC/USD pair that can be extracted from the platform is in 2017, the
hourly data of the three instruments from 01/09/2017 to 01/09/2021 are used. The close price in each
data frame is extracted for data processing.
6
3.2 Tools
Algorithm implementation and backtest are conducted in Python 3.9 using numpy, pandas, and
matplotlib. In addition, two other third-party libraries, TA-Lib and ZigZag, are also used to introduce
some technical analysis indicators and identify relative extreme points of a time series in Section 6 [6].
TA-Lib introduces the average true range, a market volatility indicator, which is for defining the price
target and stop-loss in the program. The average true range is defined as follows [7]:
TRi is the true range at a particular time, which is the maximum of ‘high minus low’, ‘the absolute
value of high minus previous close’, and ‘the absolute value of low minus previous close’. ATR is the
moving average of true range TR, usually using 14 for n.
The library ZigZag introduces a simplified version of the Zig Zag indicator. A typical Zig Zag
indicator is customizable in 3 parameters– the deviation, depth, and backstep:
1. The deviation is the minimal price change required for the indicator to define a new extreme
and to plot a swing high (a local maximum) or a swing low (a local minimum) on the chart. It
is equivalent to a threshold of identifying a new extreme point.
2. The depth sets the minimal time interval where the indicator will define a new extreme if the
threshold is passed. It is usually expressed in the unit of candlesticks.
3. The backstep specifies the minimum number of bars that have an opposite direction to the
current bar between 2 extrema to be plotted. For example, if the value of backstep equals 3,
after a new swing high, there should be at least three red candlesticks to have a new swing low
been formed.
In the library ZigZag, only the parameter deviation is considered, and it is expressed in terms of the
percentage change of price. For example, if an instrument has a price of $1000 per unit at a swing low,
and the deviation is set to be 5%, a local maximum point is identified only if the price increases over
$50 to at least $1050. If it is a swing high, a local minimum point is identified only after the price
drops under $950.
7
3.3 Evaluation Metrics
The number of trades, the success rate of predicting price movement (abbreviated to success rate),
compound annual growth rate, and maximum drawdown are the four key indicators to evaluate the
profitability of trading harmonic patterns.
𝑛𝑝
𝑟=
𝑛𝑡
𝐸𝑛𝑑𝑖𝑛𝑔 𝑣𝑎𝑙𝑢𝑒 1
𝐶𝐴𝐺𝑅 = ( )𝑛 − 100%
𝐵𝑒𝑔𝑖𝑛𝑛𝑖𝑛𝑔 𝑣𝑎𝑙𝑢𝑒
8
4 Methodology
9
Figure 4b: The second Gartley pattern
Other harmonic traders also consider ‘leg CD being 0.786 retracement of leg XA’ and ‘AB=BC’
(which means the leg BC has a similar number of candlesticks as the leg AB) as confluence, which
signals a higher probability of success when trading with the Gartley pattern. However, this study may
not cover all of these because the trade opportunity is limited.
10