Testing Expert Advisors: Properly Checking Your Systems Before Live Trading

When building automated trading systems most people focus on the trading strategy which the algorithm has to execute without giving the necessary importance to the reliability of their trading implementation. I for one – when I began building my own systems – traded a few systems live without proper and thorough testing of their implementations and although thankfully nothing bad happened it quickly became evident that it was just a matter of time before disaster knocked on my door. Since then I have given primordial importance to reliable trading implementations and have made my best effort to include adequate error handling, error prevention and safety mechanisms within the systems I have coded. Within the rest of this post I will talk a little bit about trading system reliability and the aspects you need to take into account whenever you are contemplating running a system live.

You have made it ! You have walked through the endless maze of strategies and trading knowledge and finally found a strategy which has what seems to be a robust statistical long term edge. Now it is only a matter of getting your strategy coded and your system running in order to test your idea. However after quickly coding your system and running it on your live account you notice a myriad of things which never showed in your backtests or your demo tests. You have some crashes, unreliable indicator calculations, trades that do not go through for no apparent reason, etc. Not this being enough, your system then interfered with another instance you were executing and you had some disastrous outcomes. Truth be told, you needed to understand better what is needed for reliable execution of a trading implementation.

When we run a trading system live we need to understand very well that the system will be exposed to a lot of things which generally do not show up in backtesting scenarios (and often not even in demo scenarios). Many of these problems – like requotes, server errors, etc – need to be handled adequately by your system, otherwise you will not know what happens when something goes wrong and you will most likely end up with a bad experience. The amount of code needed to make a system that can backtest adequately can only be a few lines of code (a simple system can be built with about 5 lines in MT4) but if you want to trade this live you will probably need to introduce a lot of additional code simply to handle all possible errors that could arise,

Error handling, which refers to the ability of your program to adequately log, report and deal with errors is the most important characteristic of a live trading production system. The system must be ready to log any error that might happen and it must also be ready to handle them in an appropriate fashion (avoiding crashes and such other fatal occurrences). Another important thing is to deal with all the possibilities which could lead to inaccurate trading that could breed disastrous results such as trades interfering between instances, needed variable values not being kept on platform restarts, etc. When you want to trade a system live you need to ensure that it can handle everything including platform restarts, duplicate magic numbers, etc.

As you can see errors are mainly divided between errors pertaining to order placement (platform-server interaction) and those pertaining to the calculations made by your system (internal). The first set of error cannot be prevented nor solved in most cases (as they are caused by the server which you do not control) but they need to be adequately handled so that the system knows what is going on. For example if a system is coded to set an SL after a trade is placed and no error handling is done the system may assume that all modifications are successful while on live trading the SL placement can fail and the trade can be “left hanging” without the EA ever retrying to setup the appropriate SL. Making the EA aware of all the outcomes of its trades and building the program such that adequate decisions are made when unfavorable outcomes happen is a vital part of handling server-client interactions.

The second part, which pertains errors related to internal calculations is also very important. There are many things which can go wrong within an EA which the system must be able to detect and correct. For example the system must be able to distinguish between its own positions and those of other systems (so that it does not interfere with them) and if the system uses some sort of  “permanent information” it must always be recalculated on startup or saved in a way in which it can be retrieved. Other things – such as appropriate indicator buffer initialization – are also critical and need to be appropriately taken into account in order to avoid possibly devastating problems.

Another very important thing is to stress test systems across all these scenarios before running them on live accounts. It is crucial to make the system go through reboots, restarts, crashes, etc and ensure that the account remains protected and trading remains nominal. Although many errors – as some mentioned above – can only be tested on proper live accounts it is wise to test them on very small cent accounts before committing to larger amounts of money where such errors would be absolutely critical. This is yet another reason why I do NOT believe in the use of commercial systems. How do you know that proper error handling has been coded if you have no access to the code ? How do you know that something disastrous cannot happen simply due to a programming neglect ?

Coding your own systems and being sure about their proper error handling capabilities is something most people who seriously consider automated trading should worry about. Having systems which you can fully trust is not only important but absolutely necessary for a successful long term venture in automated trading. If you would like to learn more about my work in automated trading and how you too can build systems with proper coding practices please consider joining Asirikuy.com, a website filled with educational videos, trading systems, development and a sound, honest and transparent approach towards automated trading in general . I hope you enjoyed this article ! :o)

Print Friendly, PDF & Email
You can leave a response, or trackback from your own site.

Leave a Reply

internal_server_error <![CDATA[WordPress &rsaquo; Error]]> 500