You are on page 1of 8

Detection of Repetitive Forex Chart Patterns

Yoke Leng Yong(&), David C.L. Ngo, and Yunli Lee

Department of Computing and Information Systems,


Sunway University, Bandar Sunway, Malaysia
14071856@imail.sunway.edu.my, dclngo@ieee.com,
yunlil@sunway.edu.my

Abstract. Throughout the years, numerous methods have been proposed for
FOREX trading analysis and forecasting. As analysts/traders prefer to work with
historical trading data, technical analysis based methods are often used. This
paper presents an in-depth examination of technical analysis methods with an
emphasis on charting/pattern-based analysis. Our ndings indicate how to
overcome the subjectivity often associated with identication and extraction of
patterns within FOREX historical data. Based on historical facts that FOREX
chart patterns repeat over time, the proposed method improves the approach
towards identication of chart patterns as well as prediction of their recurrence
regardless of the time warping effect affecting their formation.

Keywords: Pattern recognition  Forex forecasting  Linear regression line 


Piecewise Linear Regression  Dynamic Time Warping

1 Introduction

The continuous evolution of the nance market has contributed to its increasingly
complex nature with a myriad of nancial investment opportunities offered to the traders.
However, the FOREX market has proven to be traders preferred choice with an average
volume surpassing the trillion dollar mark [1, 2]. It is precisely due to the dynamic and
volatile nature of the market and the emphasis on protability that necessitates quick
analysis and forecasting of the price fluctuation. Therefore, extensive work has been
done to dissect the FOREX data with the expectation to unearth underlying relations that
could be used for forecasting market trends and making trading decisions. Numerous
methods of technical analysis, as well as econometrics and computational nance, have
been conceptualised and incorporated into the market over the years.
While the advancement in FOREX market research provides additional insight to
the traders, analysts are often faced with the element of subjectivity as heuristics and
trading rules remains an important part of analysis. Following the three fundamental
precepts introduced in technical analysis, the proposed method focuses on charting
based methods and attempts to reduce the subjectivity in identifying the repeating chart
pattern within the FOREX trading data. This can be achieved by simplifying the
predened chart patterns used for recognition. Subsequent sections will delve into more
details on the intricacies of the Forex market in conjunction with the analysis methods
used at present.

Springer International Publishing AG 2017


Y. Tan et al. (Eds.): ICSI 2017, Part II, LNCS 10386, pp. 395402, 2017.
DOI: 10.1007/978-3-319-61833-3_42
396 Y.L. Yong et al.

2 FOREX Analysis
2.1 Technical Analysis
Analysis of FOREX data is often an overwhelming task driven by various external
factors and constraints such as information availability, selection of currency exchange
pair and the frequency of the data (time interval) are often dependent on the traders
knowledge and prior experience. Although its effectiveness and predictive power are
often viewed with scepticism, technical analysis has always been an important trading
technique used by 90% of the market participants [3, 4] with researchers such as Hsu
et al. [5] obtaining positive results from the studies conducted. Based heavily upon the
notion that FOREX price move in trends and that history often repeats itself [3, 4, 6],
technical analysis encompasses two main approaches, namely charting and mechanical
rules. Technical analysis methods have also been used in conjunction with Articial
Intelligence (AI) methods such as Articial Neural Network (ANN) [7, 8] and Genetic
Algorithm [9] for forecasting.
Mechanical analysis revolves around the use of trading rules which are derived
from mathematical functions by using past and present exchange rate to provide a
mathematical justication and theoretical background. There are currently six
(6) well-known groups of indicators, viz: trend, momentum, volume, volatility, cycle
and Bill Williams indicator [10, 11]. On the other hand, charting based technical
analysis revolves around the interpretation of predened patterns, which develops over
time. Potential repeatability of FOREX trends and patterns contributes to the devel-
opment of a set of predened chart patterns, which are extensively documented in the
Encyclopedia of Chart Patterns [12] and are religiously followed by chartist to analyse
and forecast market fluctuations.

2.2 FOREX Chart Patterns


The underlying chart patterns identied within the Forex historical trading data are
important to chartist as it often provides invaluable information when thoroughly
scrutinised for market analysis and forecasting. Depending on the viewpoint adopted
(short or long term data analysis), the recurrence of a chart pattern derived from the past
often reflects the current market activity and volatility. The original investigation by Ito
et al. [13] considers the effects of seasonality using intraday trading information such as
the number of deals, price change, return volatility, and bid-ask spread for both the
USD/JPY and EUR/USD exchange pair. Findings from the study eventually reveal the
existence of trading patterns that occur not only daily but adapts itself across seasons.
On the other hand, the use of documented chart patterns allows for a different type of
analysis that emphasises on pattern matching. When developing patterns are detected
based on predened patterns, these patterns are not only useful as a forecasting mecha-
nism when correctly matched but they could signal one of the following trends: reversal,
continuation or bilateral movement of the trend. The FOREX trends investigated are often
formed using the peaks and troughs identied from FOREX charts and connecting two
major tops or bottoms together [12, 14, 15]. From the trends identied whether uptrend,
downtrend or sideway trend, it provides a global overview of the market direction.
Detection of Repetitive Forex Chart Patterns 397

3 Proposed Research
3.1 Detection of Underlying Trend
The emphasis of the proposed study is to identify and extract underlying FOREX
trends and chart patterns that are simple enough to provide adequate features for
classication. The proposed method was built on few technical analysis algorithms to
offer the benets of analysed data. Methods such as Linear Regression (LR) and
Piecewise Linear Regression (PLR) could potentially be used to identify the relation-
ship between fluctuating currency price over time. However, PLR implementation such
as proposed by [16, 17] offers a more flexible analysis whereby multiple breakpoints
are used for representing the dynamic nature of the nancial data as indicated in Fig. 1
(left) below. The PLR lines detected will determine how the data is segmented. As a
single pass using PLR on the dataset might not result in an optimal detection and
extraction of trends within the dataset, iterative detection is introduced whereby the
segments identied in the rst iteration is further processed by iterative PLR calculation
process such as shown in Fig. 1 (right) to ensure optimal trend identication.

Fig. 1. PLR implementation: (Left) full dataset; (Right) rst segment.

3.2 Extraction of Hidden Patterns


Once the underlying trends have been successfully detected and segmented, the sub-
sequent step is to detect possible repeating patterns within each segment. Herein the
proposed algorithm, the patterns extracted are not the common predened patterns as
documented by Bulkowski [12] but reduced to the basic trigonometric graph pattern as
shown in Fig. 2 whereby the left plot represents the downtrend chart pattern and the
corresponding right plot represents uptrend chart pattern. In an attempt to automate the
identication and extraction of patterns from the Forex historical data, the PLR lines act
as a baseline whereby the patterns are extracted based on the crossover above and
below the PLR lines. Here, the proposed approach attempts to compensate for the main
shortcoming of subjectivity that is often associated with charting method as it reduces
the need for human interpretation of the chart patterns.
398 Y.L. Yong et al.

Fig. 2. Archetypes of chart patterns: (Left) downtrend; (Right) uptrend.

3.3 Detection of Repeating Patterns


Agglomerative Hierarchical Clustering using Dynamic Time Warping (DTW) plays a
crucial role in establishing the repeatability of patterns as well as a method to represent
the similarities between the patterns extracted. Once the patterns have been extracted,
the hierarchical clustering performed gives an overview of how the trends compared
against each other. At this stage, only clusters containing a signicant amount of trend
patterns are taken into consideration as scattered trends do not contribute to the
assessment. As the patterns within each cluster consist of vectors with different length,
DTW algorithm provides the capability to calculate the distance measure between
patterns in each cluster.

4 Experimental Setup and Results


4.1 Dataset
Using the NZD/USD exchange rate from HistData [18] which offers a broad range of
currency pair exchange rate, the experimental results were obtained. The exchange rate
data was pre-processed to generate a day interval dataset instead of a minute interval
before subjecting it to the calculation of Moving Average Convergence Divergence
(MACD) technical indicator. A full description of the dataset used is summarised in
Table 1 below with the corresponding plot of the dataset shown previously in Fig. 1.

Table 1. Dataset information.


Currency dataset NZD/USD (date/time, open, high low and close)
Total time frame 2 Jan 2006 to 31 December 2015
Number of data points 3119
Time interval Daily interval
Technical indicator MACD (12, 26, 9)

4.2 Algorithm Implementation


The proposed algorithm works to simplify the analysis process as it bypasses the
requirement to have a pre-dened set of chart patterns for comparison. With the chart
Detection of Repetitive Forex Chart Patterns 399

FOREX Data FOREX Data PLR Breakpoint Detec-


Acquisition Pre-Processing tion and Segmentation

Pattern Detection
Clustering
and Extraction

Fig. 3. Proposed algorithm.

patterns as depicted in Fig. 2 successfully extracted, it is consequently subjected to


multiple iterations of hierarchical clustering process that enables the identication of
similar patterns. The clustering process ensures that similar patterns will eventually be
grouped together in the same cluster. Elimination of irrelevant trends is then performed
by only taking into consideration clusters that contain a signicant amount of trend
patterns than scattered trends. The overall algorithm is highlighted in Fig. 3.
Iterative trend detection processes are also introduced whereby PLR calculations
are used to identify uptrend and downtrend segments within the dataset. The prelim-
inary segments identied could be taken as is or further processed by iterative PLR

While (stopping condition is not true)


Perform PLR calculation and obtain breakpoints.
Calculate Mean Squared Error (MSE) value for each
segment.
End

Select PLR for the main iterations with the minimum


Mean Squared Error (MSE) value for segmentation.

For (each segment detected)


While (stopping condition is not true)
Perform PLR calculation and obtain breakpoints.
Calculate Mean Squared Error (MSE) value for each
segment for segmentation.
End
End

Select PLR for the secondary iteration with the min-


imum Mean Squared Error (MSE) value.

Fig. 4. Breakpoint detection and segmentation pseudocode.


400 Y.L. Yong et al.

Table 2. PLR breakpoint conditions.


Algorithm Looping conditions
A1 Single Iteration process
Main iteration K value: 5 - length of trend extracted
A2 Full length for both iterations
Main iteration K value: 5 - Length of trend extracted
Secondary iteration K value: 5 - Length of trend extracted
A3 Shorter K segmentation length for rst iteration; full length for second iteration
Main iteration K value: 5 - Length of trend extracted/120
Secondary iteration K value: 5 - Length of trend extracted
A4 Shorter K segmentation length for both rst and second iteration
Main iteration K value: 5 - Length of trend extracted/120
Secondary iteration K value: 5 - Length of trend extracted/15

calculation process to ensure that the best PLR adaptation to represent the trend pat-
terns are extracted depending on the algorithm selected from four different ones.
Subsequent implementation for the PLR breakpoint detection and segmentation module
as depicted by the pseudocode in Fig. 4 are performed using R statistics software with
the controlling variable being the number of quantiles chosen to represent the initial
breakpoints (denoted as K). The proposed implementation offers four different algo-
rithms implemented with the number of quantiles as listed in Table 2. The stopping
condition follows Table 2 unless the PLR algorithm encounters an error or failed to
converge for ve (5) consecutive K value.

4.3 Results
The Forex trend clustering results obtained from the algorithm previously discussed in
Sect. 4.2 clearly shows that hidden repetitive patterns do exist within the FOREX
historical dataset. Using the pre-processed data as input, clusters of similar patterns are

Fig. 5. An example of clustering result: (Left) A3 algorithm, (Right) A4 algorithm.


Detection of Repetitive Forex Chart Patterns 401

detected using the extracted trends. As there are four different variations of the algo-
rithm, Table 3 denotes the ndings using each of the variations and Fig. 5 illustrates an
example of the clusters detected.

Table 3. Dataset information.


Algorithm Total no. of trends Total no. of No. of rejected No. of clustered
detected clusters trends trends
A1 43 8 19 24
A2 334 31 241 93
A3 280 36 185 95
A4 136 22 84 52

From the results tabulated, it is clear that the FOREX historical data does not
fluctuate at random and that the assumptions held by technical analyst hold true.
FOREX price does indeed move in trend with the detected chart patterns repeating over
time albeit with slight difference caused by time warping effect. However, the issue can
be resolved easily with the use of DTW method which ensures comparison could be
carried out seamlessly.

5 Conclusion

In conclusion, the proposed method explored an alternative towards automated iden-


tication and extraction repeating patterns for analysis. This will eventually pave the
way towards removing the element of subjectivity from the patterns recognition pro-
cess as current analysis still relies upon the analysis by traders. The results obtained are
encouraging and solidies the theory that patterns could potentially be used for
FOREX forecasting. Further research options utilising the clustering results not only
involves process optimisation but the chart patterns extracted could be exploited for
forecasting purposes using the DTW mapping of the patterns.

References
1. King, M.R., Mallo, C.: A users guide to the Triennial Central Bank Survey of foreign
exchange market activity. BIS Q. Rev., 7183 (2010)
2. Bank of International Settlements: Triennial Central Bank Survey - Foreign Exchange
Turnover in April 2013: Preliminary Global Result (2013)
3. Schulmeister, S.: Components of the protability of technical currency trading. Appl.
Financ. Econ. 18(11), 917930 (2008)
4. Neely, C.J., Weller, P.A.: Technical analysis in the foreign exchange market. Federal
Reserve Bank of St. Louis Working Paper Series 2011-001B (2011)
5. Hsu, P.H., Taylor, M.P., Wang, Z.: Technical trading: is it still beating the foreign exchange
market? J. Int. Econ. 102, 188208 (2016)
402 Y.L. Yong et al.

6. Bagheri, A., Peyhani, H.M., Akbari, M.: Financial forecasting using ANFIS networks with
quantum-behaved particle swarm optimization. Expert Syst. Appl. 41(14), 62356250
(2014)
7. Gerlein, E.A., McGinnity, M., Belatreche, A., Coleman, S.: Evaluating machine learning
classication for nancial trading: an empirical approach. Expert Syst. Appl. 54, 193207
(2016)
8. Czekalski, P., Niezabitowski, M., Styblinski, R.: ANN for FOREX forecasting and trading.
In: 20th International Conference on Control Systems and Computer Science (CSCS 2015),
pp. 322328 (2015)
9. Ozturk, M., Toroslu, I.H., Fidan, G.: Heuristic based trading system on Forex data using
technical indicator rules. Appl. Soft Comput. 43, 170186 (2016)
10. Forex indicators: The best guide to indicators world. http://forex-indicators.net/list
11. Gallo, C.: The forex market in practice: a computing approach for automated trading
strategies. Int. J. Econ. Manag. Sci. 3(169), 19 (2014)
12. Bulkowski, T.N.: Encyclopedia of Chart Patterns, 2nd edn. Wiley, New York (2005)
13. Ito, T., Hashimoto, Y.: Intraday seasonality in activities of the foreign exchange markets:
evidence from the electronic broking system. J. Jpn. Int. Econ. 20(4), 637664 (2006)
14. Person, J.L.: A Complete Guide to Technical Trading Tactics: How to Prot Using Pivot
Points, Candlesticks & Other Indicators. Wiley, New York (2004)
15. Talebi, H., Hoang, W., Gavrilova, M.L.: Multi-scale foreign exchange rates ensemble for
classication of trends in forex market. Procedia Comput. Sci. 29, 20652075 (2014)
16. Muggeo, V.M.R.: Estimating regression models with unknown break-points. Stat. Med.
22(19), 30553071 (2003)
17. Wood, S.N.: Minimizing model tting objectives that contain spurious local minima by
bootstrap restarting. Biometrics 57(1), 240244 (2001)
18. HistData. http://www.histdata.com/download-free-forex-data

You might also like