The Wonderful Things About Alternative Testing Solutions: A FreePascal Tester Vs MT4

For experienced quantitative analysts there is absolutely no way in which they would ever consider testing strategies on MT4. The first and probably most important is related to the coding flexibility and the inherent limitations on the ideas you can try on this proprietary platform but time – another crucial point – is also a tremendous reason why testing on MT4 is – in the long run – not a very good idea. I wanted to get a little bit more serious with testing and code a simple tester using FreePascal to compare it to the MT4 and MT5 testing solutions. Within the following few paragraphs I will talk to you a little bit about my experiment and how an independent FreePascal strategy tester compares with the current Metatrader implementations.

Metatrader 4 is – by definition – a bloated platform which has an inefficient language that has very slow processing speeds when compared with languages like pascal and C++. Metatrader 4 could be thought about as an interpreted language – not that much unlike python – which is tremendously inefficient due to the nature of its implementation. The Metatrader 4 strategy tester is very slow and a test of 10 years on one minute data takes around 15-20 minutes on a very fast computer without the possibility to use multiple cores to evaluate a given strategy. Metatrader 5 on the other hand is based on the much more powerful MQL5 language which achieves much more rapid testing in the order of one backtest every 3-5 minutes over 10 years of data.

Now there are several important limitations to both of the above mentioned testers. The first one is that they do not allow you to escalate testing in a parallel fashion (MT5 allows you to to use multiple cores but not multiple computers) and they do not allow you to change the way in which the optimization algorithm works at its core level (therefore making the improvement of optimization much harder). Another important point is that they both do not allow the simultaneous testing of different strategies nor do they allow you to use separate Bid/Ask data feeds to evaluate systems.

The problem now is to know how difficult it is to develop a tester which performs better and how better such a tester may perform. In order to be fair in my test I coded and entire FreePascal testing platform which does globally the same things as MT4/MT5 regarding system evaluation. The strategy is not “hard coded” but called from a DLL (something which hits performance slightly) and indicator calls are also done through a separate indicator containing DLL (another slight performance hit). The program also draws charts and makes a chart of the equity curve as the test progresses, in line with what MT4 and MT5 do also calculating all relevant statistical information as MT4 and MT5 do.

My first test came down to control point daily simulations which are the fastest simulations one can carry in MT4. Sadly I cannot compare the one minute or daily simulation speeds exactly on MT5 as I cannot do a “fair comparison” since I do not know the nature (and exact coding) of their one minute tick interpolation algorithm. A daily control point simulation on MT4 takes about 5 seconds in average to carry out while my FreePascal implementation took about 0.02 seconds in average for each simulation. The FreePascal implementation can run a 50K optimization in about 16 minutes while Mt4 takes almost 10 days in order to do the same thing. My FreePascal implementation achieved similar performance differences on 1 minute data with an improvement in speed in the order of 100-500 times on all the tests I carried out.

This definitely shows that performance enhancements are not only clear but spectacular when running independent testing platforms. Another very important advantage is that you KNOW exactly what you’re running and you clearly understand all the limitations and possible problems within your testing implementation. Using the above code I was able to fully optimize a daily system I created across 15 different currency pairs, knowing for sure how the optimization algorithm worked and what its limitations were exactly. I was also able to optimize for variables such as the average AMR to maximum draw down ratio, something which isn’t achievable in MT4. Compared to MT5 (although the comparison might not be extremely fair) the FreePascal code achieves an improvement in speed from 10-50 times, still much faster than this new MT implementation and with ALL the freedom one could wish for (as it is a custom solution).

Building this FreePascal tester was a very good exercise and definitely it has proved to be a useful tool to evaluate certain ideas but it is still much slower than a C++ testing scheme we are currently developing in Asirikuy which does testing almost an additional order of magnitude faster. So if with FreePascal you can get a test result in 0.02 seconds with C++ this time is reduced to 0.001 or even less.  Probably the final solution I will be releasing to the community – hopefully later this year – will include a FreePascal UI (it is much easier to develop this here) coupled with a C++ testing framework built for the speed of its calculations.

If you would like to learn more about my work in automated trading and how you too can create your own trading systems with sound profit and risk targets 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.

3 Responses to “The Wonderful Things About Alternative Testing Solutions: A FreePascal Tester Vs MT4”

  1. Winter says:

    Hi Daniel,

    Another great breakthrough in the strategy testing tool.

    Winter

  2. Alex says:

    Hi,
    I have just read a book called Quantitative Trading by EP Chan. He extensively uses Matlab (which has a vector based programming language) and Alphacet Discovery, amongst other tools, to do his backtesting and search for stategies, identify ME and edge.
    Did you already checked these tools to perform your backtests ? Would they be much slower than redevelop a complete backtesting solution ? (except the fact that you could lose control or knowledge of your backtesting engine internals)

    • admin says:

      Hello Alex,

      Thank you for your comment :o) Matlab is a tremendous tool for quantitative trading research. The main problem I have with this is that for most people the license is very expensive (more than 1500 USD) and therefore it is much better for us – as a community – to develop our own testers in either C++ or FreePascal (C++ is way faster but I absolutely love the simplicity of modern object Pascal). So long story short Matlab is very useful and very expensive (particularly if you’re looking to use it with an entire community) while developing your own solution takes more time and effort but in the end it is YOURS and you have much more control over the internal aspects of the implementation. A C++ native implementation can also be potentially much faster than Matlab although – as I said before – it will take longer to implement. I hope this answers your questions :o)

      Best Regards,

      Daniel

Leave a Reply

WordPress › Error

There has been a critical error on this website.

Learn more about troubleshooting WordPress.