Home Forex Stroll-forward optimization library for MetaTrader: pause, resume, refine – Different – 1 November 2023

Stroll-forward optimization library for MetaTrader: pause, resume, refine – Different – 1 November 2023

0
Stroll-forward optimization library for MetaTrader: pause, resume, refine – Different – 1 November 2023

[ad_1]

Model 1.12 of WFO-library introduces an fascinating and highly effective characteristic – a chance to pause and resume an optimization. Till now WFO-library supported solely separate uninterrupted optimizations.

From the viewpoint of EA developer, new mode may be enabled by new flag WFO_FLAG_RESUME_OPTIMIZATION (32) handed to the perform wfo_setAdvancedOptions. However other than the coding, the characteristic requires some particular process for correct optimization setup. Right here I will present some directions. But earlier than we start, it is necessary to refresh your information on how optimization course of is organized in MetaTrader 5 technically.

Idea

The tester helps 2 varieties of optimization:

  • gradual optimization with full iteration via all mixtures of enter parameters, and
  • quick optimization primarily based on genetic algorithm;

Genetics pace up the method by way of choice of a small a part of potential mixtures – after all the choice isn’t random however backed up with a complicated logic (mendacity far past the scope of this quick publication), invented for locating quasi-optimal answer with finest ratio of “optimality” and time spent to search out it.

I remind you that even when you choose gradual optimization, the tester could routinely swap to genetics if the variety of mixtures is just too massive (for instance, over 100 mln in case of utilizing 64-bit terminal).

Each optimization produces a cache file – an opt-file situated within the subfolder /tester/cache/ of your MT5 folder. The title of the file begins with a prefix equal to EA title and in addition consists of work image, timeframe, date vary, and a hash quantity, uniquely figuring out present “EA construct” and settings. For instance,

WalkForwardDemo.EURUSD.H1.20230101.20231026.11.EF7BF3C92D7F53F512CC1E61A72B9448.decide

What’s the “EA construct” – I will describe a number of traces under.

Now it is necessary to notice, that the cache can be utilized not solely to evaluation outcomes of current optimizations simply within the tester UI, however to pause and resume a prolonged optimization. Certainly, as quickly as you begin an optimization, the tester gathers incoming leads to the opt-file, which is adequate to proceed the method with respect to already made efforts. You could cease optimization at any second, after which resume it by urgent Begin at any time later, provided that the opt-file nonetheless exists, and the hash matches “EA construct” and settings.

“EA construct” is a hash of binary ex5-file (and all binary libraries, if they’re used, akin to WalkForwardOptimizer.ex5). Each time you recompile EA (or change a library) the hash is modified, which invalidates the opt-file cache.

Please word, that MetaEditor generates a singular ex5-file because of any compilation, even when the supply code was not modified. This is part of safety towards decompilation.

Modifications within the tester settings or enter parameters may even make opt-file cache inconsistent.

Sadly, there isn’t a solution to uncover which ex5-file variant and settings are encoded within the hash (hash calculation is a one-way algorithm). So, it’s kind of tough for a person to differentiate one opt-cache from the opposite and work out if it nonetheless corresponds for the present surroundings, and therefore legitimate for optimization resumption. The one attribute a person can use for investigation is the timestamp of the opt-file (final time optimization knowledge was up to date). A person ought to make a remark someplace, which settings and inputs had been used for particular opt-cache (marked by particular date/time).

Really a person can choose caches one after the other within the tester UI from the dropdown record with all cached optimizations, learn their settings and inputs, however UI doesn’t present the opt-file names, so if there are numerous caches for a similar EA, image, timeframe and date ranges, the person want someway deduce, which hash corresponds to optimization run of his/her curiosity.

Optimization cache selection in MetaTrader 5 tester

If the cache turned invalid (because of modifications in no less than one of many components: ex5-file, or settings, or inputs), subsequent time you begin an optimization will probably be a brand new optimization, not a continuation of a earlier one. If ex5-file was modified, the tester removes opt-file (if exists for present settings/inputs) and outputs a message about this into the log.

For genetic optimizations there exists much more fascinating chance. After a genetic optimization is completed, you possibly can restart it and proceed the method, considering all cached outcomes, that isn’t from scratch.

You possibly can restart genetic optimization many times. Each restart will most certainly discover an increasing number of higher outcomes, all summed up within the opt-file.

This works easily till you do not customise optimization in any peculiar approach, akin to WFO. The issue arises from a number of elements.

MQL5 API doesn’t present any means to let MQL-program know, if present optimization is a brand new one or a continuation primarily based on pre-existing opt-cache. In different phrases, neither your EA nor WFO library can routinely detect whether or not to collect their particular knowledge (complementing normal optimization knowledge) to a brand new file or append to an previous one (if it exists). Furthermore, it is inconceivable to determine, if a legitimate opt-cache exists for present “EA construct” and settings. And furthermore, it is inconceivable to detect a state of optimization based on an present opt-file: it might belong to a completed gradual optimization (it may’t be resumed), to a paused optimization (regardless of gradual or quick, each may be resumed), or to a completed genetic – the latter may be restarted/refined. Strictly talking there are some “hacks”, which aren’t components of MQL5 API, and permitting to learn opt-files – they’re inadequate and unreliable to be used in a product for MQL5 market.

Because of this WFO library didn’t permit optimization suspension/continuation till model 1.12. The library begins gathering its particular knowledge from very starting upon every optimization begin. It implies that if a legitimate opt-file exists, it ought to have been eliminated manually by a person earlier than new optimization.

Follow

Ranging from model 1.12 you could set the flag WFO_FLAG_RESUME_OPTIMIZATION in your code. In consequence WFO library will maintain present WFO knowledge throughout optimization begin and append new passes into it, that’s in sync with filling opt-file by the tester.

To allow/disable the flag one can use the next strategy:

#embody <WalkForwardOptimizer.mqh>
sinput ulong wfo_advancedOptions = 0; 

int OnInit()
{
  ...
  wfo_setAdvancedOptions(wfo_advancedOptions);
}

void OnTesterInit()
{
  ...
  wfo_setAdvancedOptions(wfo_advancedOptions);
}

The perform wfo_setAdvancedOptions is named twice in OnInit and OnTesterInit for generality right here, as a result of totally different flags are utilized in totally different contexts: a part of the flags are relevant on the brokers, and a part of the flags – within the terminal (see https://www.mql5.com/en/blogs/publish/754712).

Particularly the flag WFO_FLAG_RESUME_OPTIMIZATION (32) is sensible in OnTesterInit solely.

Do not forget that altering wfo_advancedOptions enter itself modifications the hash and invalidates opt-cache (if it exists). Watch out:

  • once you change 0 to 32 in wfo_advancedOptions, be certain there isn’t a WFO-related information, as a result of the tester ought to usually create a brand new opt-file;
  • but in the event you did already use 32 some day in the past, an opt-file corresponding to those inputs should exist – then you could be certain (test your facet notes, for instance) that correct WFO-related information do additionally exist;
  • once you change 32 to 0 in wfo_advancedOptions, be certain there isn’t a an opt-file appropriate for continuation, as a result of WFO-files can be deleted;

If you’re completely positive that you just all the time need to proceed optimization (that’s WFO-related information, akin to csv and gvf, in the event that they exist, correspond to an opt-file eligible for continuation), then you possibly can hardcode the brand new mode within the following approach:

#embody <WalkForwardOptimizer.mqh>

void OnTesterInit()
{
  ...
  wfo_setAdvancedOptions(WFO_FLAG_RESUME_OPTIMIZATION);
}

It is also protected strategy, if there isn’t a caches in any respect (neither an acceptable opt-file, nor WFO-related information) – it’s best to test this (or clear up) manually earlier than new optimization.

The brand new mode is specifically helpful for a number of successive runs of genetic optimizations. As a result of genetic optimization selects very restricted variety of passes from total optimization house, it produces WFO-reports with quite a lot of holes in ahead steps (keep in mind – steps are organized by increments of wfo_stepOffset, and genetics could contemplate to probe solely a small a part of the steps).

By restarting genetic optimization an increasing number of occasions, you may more and more fill within the gaps in WFO-report.

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here