Walk-forward optimization library for MetaTrader 4: How Tos

15 August 2016, 19:43
Stanislav Korotky
0
89

This post is a part of documentation of WalkForwardOptimizer library for MetaTrader4 - here is the table of contents.

Before you start a new walk-forward optimization do always remove "WF_"-prefixed global variables which possibly remain from previous run. A simple way to do so start WalkForwardReporter script and set parameter ClearWFGlobalVariables to true. Alternatively you can automate this routine by calling wfo_setCleanUpTimeout in OnInit of your EA.

Before you start a new walk-forward optimization make sure that the name specified for output csv-file in wfo_outputFile does not match an existing file in tester/Files folder. Otherwize change the name or delete old file. Alternatively you can automate this deletion by calling wfo_setCleanUpTimeout in OnInit of your EA.

After every optimization run do not forget to move generated csv-file from tester/Files to MQL4/Files folder, where it will be accessible for WalkForwardReporter script.

After every optimization run make sure that total number of passes in the tester on the Optimization results tab is equal to WF_PASS global variable. If they do not match, open tester/Caches folder and clear it, then delete csv-file from tester/Files folder, clear WF global variables, and repeat optimization. This is a problem arisen from the fact that the tester may skip some passes if they are cached. Also the problem occurs if you forgot to disable the option Skip useless results in the context menu of the Optimization results tab.

Make sure you enable optimization for those meta-parameters which are explicitly mentioned so in this instructions, and clear flags for all the other meta-parameters. As for work parameters of your EA, you can include them into optimization as you wish.

 

Simple rolling walk-forward optimization with predefined periods or arbitrary periods in days

1. Choose optimization window size wfo_WindowSize from a list of predefined periods or choose custom period and specify number of days in wfo_customWindowSizeDays.

2. Choose forward step size wfo_stepSize from a list of predefined periods or choose custom period and specify percent in wfo_customStepSizePercent.

3. Enable optimization for wfo_stepOffset in range from 0 up to any number which will fit into available history and with step 1.

4. Run optimization.

5. Copy resulting csv-file into MQL4/Files.

6. Run WalkForwardReporter script.

7. Open generated HTML-file with report. 

Here is an example. Let us consider the period 2010-2016. Let optimization window be a year, and forward step size - a quarter. This is 6 full years and a half. 1 year is consumed by moving window (in-sample data) and the rest is covered by consecutive forward steps (out-of-sample tests). This is 5 years and a half, which gives 22 quarters of out-of-sample tests, so we should interate forward step wfo_stepOffset  from 0 to 21 (because 22-th step is 3-rd quarter of 2016 which we can't test yet at the time of writing).

 

Clustered walk-forward optimization

1. Choose optimization window size wfo_WindowSize as custom.

2. Enable optimization for wfo_customWindowSizeDays for any meaningful range and increment in days.

3. Choose forward step size wfo_stepSize as custom.

4. Enable optimization for wfo_customStepSizePercent for any meaningful range and increment in percents (the recommended range is 5-30%, the increment 5-10%). 

5. Enable optimization for wfo_stepOffset in range from 0 up to any number which will fit into available history and with step 1.

6. Run optimization.

7. Copy resulting csv-file into MQL4/Files.

8. Run WalkForwardReporter script.

9. Open generated HTML-file with report. 

If you have a preferred window size you can run cluster analysis where only step size is changing, and if you have a favorite step size it's possible to optimize window size only.

 

Drilldown analysis of a single case of walk-forward run from cluster

This is the same as the previous case, but when running WalkForwardReporter script specify WindowSize and StepSize that are available in columns and rows of the tables in the clustered report.

You can build different drilldown reports using the same output data of a single cluster optimization. 


Anchored walk-forward optimization

1. Choose optimization window size wfo_WindowSize as custom.

2. Enable optimization for wfo_customWindowSizeDays for any meaningful range. Make sure that increment in days is equal to a number of days of a predefined period which will be used on the next stage (for example, enter 30 days increment if you're about to choose monthly step).

3. Choose forward step size wfo_stepSize from a list of predefined periods, which equals to the increment for the window specified above.

4. Disable optimization for wfo_stepOffset and make sure it's 0.  

5. Run optimization.

6. Copy resulting csv-file into MQL4/Files.

7. Run WalkForwardReporter script.

8. Open generated HTML-file with report. 


 

 

Share it with friends: