Inovance Machine Learning Histogram Background Algorithmic Automated Trading Home
Trading advice

5 Things You Need to Know Before Running Your Expert Advisor

By: | 11/15/2013

Comments

MetaTrader 4 has become the most popular trading platform when it comes to forex automated trading strategies, known as expert advisors.

The ability to quickly and easily build expert advisors, or EAs, attracts new traders and experienced coders alike. Within a couple hours, and with a little help from a good tutorial and a few other examples, you can code your strategy into a working EA, run a backtest, and view the results. While MetaTrader 4 is a great way to get started, when you are building an EA for a live trading account there are some serious issues you need to be aware of.

1. Reliability of Backtesting Results

Great backtesting results can may give you the impression that your system is ready to go live, but it is not quite that easy. These results are completely dependent on the quality of the data used in the backtest, meaning poor data can easily lead to unreliable results. The default data in MetaTrader 4, supplied from MetaQuotes, can only achieve a modeling quality up to 90%. This may seem good enough, but this can cause huge differences in backtesting and live testing results, especially on smaller time frames . Luckily there are sources of free historical data and instructions on how to prepare the data for MetaTrader 4. Obtaining high-quality, reliable data for your backtests should be the first step in preparing an EA to trade a live account.

2. Accurately Reflecting the Spread in Backtests

Once you have reliable data loaded into MetaTrader4, the next important consideration is how to incorporate trading costs, or the spread, into your backtests. The spread can easily turn a profitable EA into a disaster. MetaTrader 4, by default, applies the current spread at the time of the backtest to all the simulated trades. However, spreads vary greatly and depend on your broker. A fixed spread is simply not realistic and backtesting on weekends, when the markets are closed, can lead to some interesting results. (You can view the spread used in the backtest by selecting "Symbol Properties" in the "Strategy Tester" menu.) Currently, there is no quick solution to manually set the spread that I have been able to find but please comment if you have a good workaround.

3. Understanding your Execution Speed

While this mainly is an issue for scalping strategies and at times of high volatility, understanding the execution speed of your trades can be crucial to building a reliable EA. MetaTrader 4 requires trading activity every 30 seconds, known as a "session". If there is no trading activity for more than 30 seconds, your session will automatically time out. This requires the IP address to be automatically be re-authenticated with login and password credentials. This takes time, ranging from 200 ms to up to 2 seconds with some brokers. Even this slight delay in times of high volatility can have a significant impact on the results of your trades. It is possible toload a script that slightly modifies, but does not actually effect your order, every 29 seconds to stop your session from timing out, which cuts out this delay. This is a great way to decrease slippage with any EA.

4. Debugging your EA

If you have spent any time writing a fairly complex EA in MetaTrader 4 you know the hassle of debugging the code. Most other software comes with debugging tools that allow you to easily use a break position to find problems in your code. However, MetaQuotes, the company behind the Metatrader software, caters more to the needs of brokers than traders. This leads to some features, like a debugger, not being included. Fortunately, there are a few ways to simplify your life. One option is to input print() functions into your code (the output of this print function is written to the experts/logs file). Although this can become very cumbersome, especially if you have thousands of lines of code or are not sure where your problem lies. Another option is to follow this guide and download Microsoft’s DebugView to view a neatly formatted log. There is also the option of posting your EA to the mql4 forums and hoping for a good samaritan in the forex community to help you out, but you do have to release the inner workings of your EA.

5. Testing your Metatrader 4 Connection

MT4 must be on and connected to your broker in order for your EA to run. There is nothing more frustrating than thinking you have an EA up and running only to see it has been disconnected and is unable to reconnect. While Metatrader 4 is programmed to automatically reconnect to the server, this does not always work as expected. If you have multiple Metatrader accounts, sometimes the wrong credentials are used during the reconnection process. Or for whatever reason there may be a connection problem with your broker or their server and you are unable to automatically reconnect. The best solution is to delete your unused accounts from the Navigator window in Metatrader 4 or include a IsConnected()command in your code to alert you if you have been disconnected. This may not be a huge problem, but can become very frustrating if you are getting disconnected and your isn't EA continuously up and running.

Metatrader 4 may be the most popular forex automated trading software, but before running your EA on a live account there are some areas that need to be addressed. This is by no means a complete list and I strongly recommend running your EA on a demo account before setting it loose on a live account. However, if you understand these issues and the limitations of MetaTrader 4 then you are well on your way to developing a profitable and fully automated trading strategy. I would love to hear your thoughts on these or other problematic areas of MetaTrader 4. Until then, good luck and happy trading!