Walk-forward optimization library for MetaTrader: advanced options

1 November 2023, 19:45
Stanislav Korotky
0
198

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

The function wfo_setAdvancedOptions accepts an integer value which is a bitwise set of flags, that is a specific bit enables specific feature. All supported flags are listed in the header file with corresponding values.

// flags working in agent contex
#define WFO_FLAG_AUTO_CLOSE_SPLIT_TRADES 1
#define WFO_FLAG_MISMATCH_FIX_OFF        2
#define WFO_FLAG_STOP_ON_RANGE_VIOLATION 4
#define WFO_FLAG_CHECK_TICK_MODELLING    8
// flags working in terminal context
#define WFO_FLAG_STOP_ON_NONSTD_PARAMS  16
#define WFO_FLAG_RESUME_OPTIMIZATION    32

Multiple features can be enabled by bitwise OR-ing ('|') flags or by separate calls to the function, for example:

wfo_setAdvancedOptions(WFO_FLAG_MISMATCH_FIX_OFF | WFO_FLAG_STOP_ON_RANGE_VIOLATION);

Please note, that part of the flags affects code execution in the tester agents, and other part is intended for use in code executed in the terminal.

For agents you should call wfo_setAdvancedOptions in OnInit, for the terminal - call it in OnTesterInit. For generality you can call it in both places - this is safe, because excessive flags will simply not take effect.

The meaning of the flags and corresponding features are described below:

  • WFO_FLAG_AUTO_CLOSE_SPLIT_TRADES - enable automatic close of positions and pending orders on the boundary between walking window and forward test, the same as wfo_setCloseTradesOnSeparationLine (https://www.mql5.com/en/blogs/post/677266);
  • WFO_FLAG_MISMATCH_FIX_OFF - disable automatic correction of discrepancies, which may show up in WFO-reports under some circumstances; find more details in the FAQ (https://www.mql5.com/en/blogs/post/677450), Q.Why do I see discrepancies in some rows of walkforward tables?;
  • WFO_FLAG_STOP_ON_RANGE_VIOLATION - stop current tester pass if a trade(s) is detected before or after walking window and forward test; by default this feature is off, and EA developer is responsible for making sure in the source code, that trades are allowed strictly inside the window and forward;
  • WFO_FLAG_CHECK_TICK_MODELLING - enable tick modelling detection (empirical, not a part of MQL5 API), the result is shown in WFO-report;
  • WFO_FLAG_STOP_ON_NONSTD_PARAMS - enable strict check-up for proper optimization settings, that is at least one of wfo_windowSize, wfo_stepSize, wfo_stepOffset should be involved in optimization, otherwise, WFO will be disabled; not compatible with 3-rd party software wrappers of WFO-library, which setup these inputs programmatically;
  • WFO_FLAG_RESUME_OPTIMIZATION - keep WFO-specific data (csv and gvf files) and append new results into it, assuming continuation of optimization; find more details in other blog post;

All flags are optional.






Share it with friends: