You are on page 1of 6

JOURNAL

Leading Research in Risk Control for Sustainable Returns Finamatrix.com


_______________________________________________________________________________________________

Automated Gold Trading with MT4

Manyat Wong
manyatwong@outlook.com

Lanz Chan, Ph.D.


lanzchan@qq.com

Wing-Keung Wong, Ph.D.


awong@hkbu.edu.hk

Jun, 2014

Abstract

This paper reports the performances of expert advisor (EA) strategies that are tested on the popular metatrader4 (MT4)
platform. The results show the profitability and stability of the strategy; for the test period of July 2013 to March 2014 on
per minute (M1) data, the net profit return is nearly four times based on an approximate 45% winning rate, providing
evidence that the trading strategies have room for improvements but can also run efficiently in micro-accounts. Further
development work is to be performed for reduction of the average loss trade and maximal drawdown.

Keywords: gold trading, expert advisor, automated algorithms, metatrader, quantitative trading, black box.

Introduction

From the perspective of the trader or fund manager, if one is to maximize profits or returns (Bai et al, 2009), a logical
inference on the average number of transactions per trading day is dependent on the number of opportunities that
present themselves. It is a frequent activity for traders to observe patterns of price movements and of selected technical
indicators, such as moving average (Wong et al, 2003), bollinger bands, average directional index (ADX), moving
average convergence divergence (MACD), momentum (Lam et al., 2007, 2010, 2012; Fabozzi et al., 2013) and others,
so as to visually capture repeating trends. With the use of algorithms, these repeating trends can be captured and tested
with precision. While the reliance of fundamental analysis is critical for traders, it is a task that works in tandem with
trading algorithms or the black box. It is also implied that the focus on technical analysis (Wong et al, 2001; Chan et al,
2014) to predict movements due to fundamentals is the objective of automated algorithmic trading (Chan and Wong,
2012, 2013).

Over the past decade, the development of automated trading strategies have increasingly become mainstream in the
trading community on the MT4 platform. This study develops an expert advisor, which is the term for an automated
trading algorithm on the metatrader platform, based on hundreds of trials and errors that utilize a suite of some 30 plus
technical indicators that are both common and customized. The ultimate choice of the input variables (indicators and
specifications) used in developing the expert advisor is proprietary and will not be revealed in this study. For more
information, please contact the authors.

Data Analysis

XAUUSD (gold) data is obtained from the FXPro server and the back-test is performed using the strategy tester module
in metatrader. Long/Short positions are both allowed and there is the option of genetic optimization (Bai, et al., 2009) with
the following settings:

Optimized Parameters: Balance, Profit Factor, Expected Payoff, Maximal Drawdown, Drawdown Percent.

Optimization Limitation: Balance minimum, Profit maximum, Minimal margin level, Maximal drawdown, Consecutive loss,
Consecutive loss trades, Consecutive win, Consecutive win trades.

Copyright 2014 1

Electronic copy
Electronic copy available
available at:
at:https://ssrn.com/abstract=2457098
http://ssrn.com/abstract=2457098
JOURNAL
Leading Research in Risk Control for Sustainable Returns Finamatrix.com
_______________________________________________________________________________________________

The algorithm settings include the following but not limited to: risk per trade, maximum total risk, maximum account risk,
stop loss pips, take profit pips, start hour, end hour, etc. Every tick data is used for analysis which is the most precise
method based on all available least timeframes to generate each tick. Spread levels are set at current which is the most
realistic method of approximation. A low spread level of less than 10 pips will improve test results while a spread level of
more than 30 pips can reduce test results. Spreads widen during high price volatility and as such, the success of trades
should reduce during higher spreads or higher price volatility. An important implication is that a successful expert advisor
with short-term intraday trades should be able to be successful during periods of lower spreads and price volatility as a
more efficient strategy.

Based on popular dealers for XAUUSD quotations, spread levels were set at 30 pips for the tests, while each position is
executed only when price satisfies the set indicators, resulting in overnight trading.

Figure 1.1 – XAUUSD Price Chart, July 2013 - March 2014

Note: ADX(14), MACD(12,26,9), StdDev(20) technical indicators are displayed above.

Over the nine months under analysis, the estimated maximum price is approximately 1433.50 while the minimum price is
1182.24, offering 25,126 pips or 21.25% return. It is observed from the above price chart that potentially higher returns
are possible with an actively managed trading strategy or portfolio of strategies.

Test Results

The test result shows the profitability of this strategy, nearly 4 times profits in 9 months with 479 trades. The result also
displays a limited winning percentage of 45% in total trades. This strategy provides evidence that capitalizing on profits
on large fluctuations are able to cover losses for wrong trades and the lack of price volatility.

The total of 479 trades implies that for the approximately 180 trading days, the average number of trades per day is less
than 3 to generate the returns at a maximal drawdown of about 45%.

The statistics shows that 47.28% of short trades and 43.33% of long trades derived 3.7 times return from a capital base
of USD1,000 (ending capital of $3713.3). It is noted that short transactions are more successful than long transactions,
which highlight a potential improvement focus for next efforts. It is also well noted that the average profit trade is 1.5
times more than the average loss trade, while the largest profit trade is about 43.68% more than the largest loss trade.

Copyright 2014 2

Electronic copy
Electronic copy available
available at:
at:https://ssrn.com/abstract=2457098
http://ssrn.com/abstract=2457098
JOURNAL
Leading Research in Risk Control for Sustainable Returns Finamatrix.com
_______________________________________________________________________________________________

Figure 1.2 – XAUUSD Strategy Test (M1) for USD1,000 Account, July 2013 – March 2014

Stress Test

In order to prove the stability of the strategy, stress tests are necessary. Two stress tests were set up, one to raise the
spread to 50 pips, the other to set conditions for stop loss. These tests are both important to provide evidence that this
strategy is able to be successful in real-time.

In the first stress test, the results show that as compared to the former test, the profit reduced by about 20%, but they
display the same varying trend. The profit trades also decreased by 6, about 1.25% of total trades. These imply that the
strategy has stability when the spread increases by two-thirds to 50 pips. Hence, there is evidence that this strategy is
able to deal with large gold price fluctuations at higher spreads.

The second stress test is added onto the first stress test. More stringent stop-loss rule is setup in the algorithm. The test
results show that the trading pattern has been totally destroyed, with an increase in transaction frequency and the drastic
reduction of profitable trades. Under our stop-loss rule, the strategy had become unstable. More losses were generated
with the stop loss with 50 pips spread, but the strategy was still able to finally gain over 2 times return, providing
evidence that the strategy is fundamentally robust.

Copyright 2014 3

Electronic copy available at: https://ssrn.com/abstract=2457098


JOURNAL
Leading Research in Risk Control for Sustainable Returns Finamatrix.com
_______________________________________________________________________________________________

Figure 1.3 – XAUUSD Stress Test One with 50 pips Spread (M1) for USD1,000 Account, July 2013 - March 2014

Figure 1.4 – XAUUSD Stress Test Two (M1) for USD1,000 Account, July 2013 - March 2014

Copyright 2014 4

Electronic copy available at: https://ssrn.com/abstract=2457098


JOURNAL
Leading Research in Risk Control for Sustainable Returns Finamatrix.com
_______________________________________________________________________________________________

Conclusion

The above tests have provided evidence that investors are able to use micro-accounts to create high returns on gold
trading with similar EAs. The low percentage of profit trades does not translate to low returns. Nearly or less than 50% of
profit trades is enough, provided that the average profit trade is greater than the average loss trade, as well as most of
the profit trades achieve more absolute profit than most of the loss trades.

Expert advisor development is at the forefront of quantitative trading for achieving precise risk control for the creation of
sustainable returns in the financial markets. The use of long/short transactions on any investment instrument with
sufficient trading volume or market depth which allows long/short trades such as stock index or commodity futures are
good examples for EA development. The success of EA depends on a myriad of factors that may be suitable for certain
market conditions. This study has shown that EA success is possible for micro-trading accounts which can benefit not
only institutional investors, but also retail investors.

References

Bai Z, Liu HX and Wong WK (2009) Enhancement of the Applicability of Markowitz's Portfolio Optimization by Utilizing
Random Matrix Theory, Mathematical Finance 19(4) 639-667.

Chan, LCWJ and Wong WK (2012) Automated Trading with Genetic-Algorithm Neural-Network Risk Cybernetics: An
Application on FX Markets. Finamatrix Journal, Feb 2012.

Chan, LCWJ and Wong WK (2013) Expert Advisor Development on MT4/MT5 for Automated Algorithmic Trading on
EURUSD M1 Data. Finamatrix Journal, Sep 2013.

Chan, RHF, Lee, STH, and Wong WK (2014) Technical Analysis and Financial Asset Forecasting: From Simple Tools to
Advanced Techniques, World Scientific Publishing Company.

Fabozzi FJ, Fung CY, Lam K, Wong WK (2013) Market Overreaction and Underreaction: Tests of the Directional and
Magnitude Effects, Applied Financial Economics 23(18), 1469-1482.

Lam K, Liu T and Wong WK (2010), A pseudo-Bayesian model in financial decision making with implications to market
volatility, under- and overreaction, European Journal of Operational Research 203(1),166-175.

Lam K, Liu T and Wong WK (2012) A New Pseudo Bayesian Model with Implications to Financial Anomalies and
Investors’ Behaviors, Journal of Behavioral Finance 13(2) 93–107.

Copyright 2014 5

Electronic copy available at: https://ssrn.com/abstract=2457098


JOURNAL
Leading Research in Risk Control for Sustainable Returns Finamatrix.com
_______________________________________________________________________________________________

Lam VWS, Chong TTL and Wong WK (2007) Profitability of Intraday and Interday Momentum Strategies, Applied
Economic Letters, 14, 1103–1108.

Lam VWS, Chong TTL and Wong WK (2007) Profitability of Intraday and Interday Momentum Strategies, Applied
Economic Letters, 14, 1103–1108.Wong WK, Chew BK and Sikorski D (2001) Can P/E ratio and bond yield be used to
beat stock markets? Multinational Finance Journal, 5(1), 59-86.

Wong WK, Manzur, M, Chew BK and Sikorski D (2003) How Rewarding is Technical Analysis? Evidence from Singapore
Stock Market, Applied Financial Economics, 13(7), 543-551.

Copyright 2014 6

Electronic copy available at: https://ssrn.com/abstract=2457098

You might also like