Walk-forward optimization in MetaTrader 4

14 August 2016, 15:14
Stanislav Korotky

Many experienced traders use walk-forward optimization for their algorithmic trading systems. Unfortunately MetaTrader 4 does not provide any means for performing walk-forward optimization of expert advisers (EA). This is why I decided to implement Walk-Forward Optimizer (WFO) library and I am ready to announce it here in the blogs - this is the only place on mql5.com (excluding the Market itself), where existing and future Market products can be presented and discussed without a user being banned.

I can't tell you when the library will become publicly available because it depends from many external factors such as waiting in queue for pre-release check-up, the check-up itself and so on. I'm not even sure that the library will be distributed via the Market, because it's not clear if it violates the Market's rules or not (I'm trying to clarify the matter with MQ support, but to no avail so far). But if you're interested in the library, drop me a line, and I'll notify you upon its availability.

As it's a library, the WF feature will be suitable only for those who have source codes of their experts and can afford small temporary changes in the source.

If you can't deal with programming there are 2 other ways to perform walk-forward optimization in MetaTrader 4. The first one uses an external UI automation program which would fill dates and switch all necessary options in the tester as if it's a user, initiate optimization runs and forward test runs (one by one), saving results into files, and then another program should parse the results and build a report. This approach requires a user to be familiar with these external programs and setup them appropriately. The second one utilizes MetaTrader's command line (which requires a user to prepare a bunch of configuration files (.ini, .set) and shell files (.bat or .cmd)), as well as an external program or script for parsing resulting html-reports and combining them into a single aggregated report. Both ways are not much simplier than tweaking EA with the library.
The library supports rolling walk-forward, anchored walk-forward, and cluster analysis. But do not expect its WF implemenation be as full-featured as it's in well-known standalone programs for trading and backtesting.

The library relies on the built-in tester. Basically it manages and shifts the range of dates allowed for EA trading during every optimization run. The results of all optimization passes are saved in an intermediate csv-file and special global variables, which then should be processed by a helper script - WF reporter. As a result, it generates an HTML-page with comprehensible report of one of the supported types.

Here is how a rolling forward test report looks like.

Rolling Walk-Forward Report built by WFO library for MetaTrader 4

These results are for standard EA "Moving Average" (from MetaTrader distribution) genetically optimized and tested on EURUSD D1 starting from 2010 with minimal constant lot.

Full documentation and examples will be provided as soon as the products are published.

The library is supposed to be paid, and the script is free. Or vice versa.

Share it with friends: