Walk-forward optimization library for MetaTrader 4: Functions

15 August 2016, 19:42
Stanislav Korotky
0
56

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

Functions

void wfo_setEstimationMethod(WFO_ESTIMATION_METHOD estimation, string formula)

selects a method to estimate EA performance; available options: wfo_built_in_loose (default) and wfo_built_in_strict - composite indicators comprising sharpe, profit factor, profit amount and number of trades, wfo_profit - net profit amount, wfo_sharpe - sharpe ratio, wfo_pf - profit factor, wfo_drawdown - inversed drawdown (100 - DD) calculated on balance curve, wfo_profit_by_drawdown - profit amount divided by drawdown, wfo_profit_trades_by_drawdown - profit amount multiplied by number of trades and divided by drawdown, wfo_average - average profit of a single trade, wfo_expression - custom formula for performance estimator, specified in formula; the function is optional, should be called in OnInit;

void wfo_setHeader(string s)

assigns a string, which will be outputted to resulting CSV file as ending part of header with work parameters of EA; by default - "Payload"; the function is optional, should be called in OnInit;

void wfo_setPFmax(double max)

assigns a maximal value for profit factor for cases when losses are missing; by default - DBL_MAX; the function is optional, should be called in OnInit;

void wfo_setGVAutomaticCleanup(bool b)

sets a flag for automatic deletion of existing global variables with "WF_" prefix at start-up of new optimization; by default - false; can be set to true, only if you do not use genetic algorithm; the function is optional, should be called in OnInit;

int wfo_OnInit(WFO_TIME_PERIOD optimizeOn, WFO_TIME_PERIOD optimizeStep, int optimizeStepOffset, int optimizeCustomW, int optimizeCustomS, string optimizeLog)

passes all required data into the library: window size, forward step, rolling forward step number, custom window size in days, custom step size in percent of window, name of csv-file for results; must be called in OnInit; returns 0 on success, or error code on error, for example, INIT_PARAMETERS_INCORRECT if passed parameters are incorrect;

int wfo_OnTick()

manages EA optimization inside window and testing on forward step; must be called in OnTick; returns 0 if current tick is inside moving optimization window and EA is allowed to trade; returns -1 or +1 if current tick is outside the window and trading should be skipped; -1 means that trading window is not yet started, +1 means that the trading window is already ended;

double wfo_OnTester(string payload = "")

manages EA optimization by selected custom estimator; must be called in OnTester; the optional parameter can send arbitrary stringified parameters of EA to the library, so that they will be saved into resulting csv-file in the colums corresponding to the headers sent via wfo_setHeader function; returns the estimator value to be passed back to the tester;

void wfo_setCloseTradesOnSeparationLine(bool b)

sets a flag to close all market and pending orders at the moment of crossing the boundary between optimization window and forward test; by default - false; the function is optional, should be called in OnInit;

void wfo_setCleanUpTimeout(int seconds); (ver.1.2+)

assigns a timeout in seconds; when new optimization starts and requested csv-file does already exist with modification time older for more than given 'seconds', the file is deleted; if WF_-global variables are marked by a timestamp which more than given 'seconds' in past, the variables are also deleted; by default (if function is not called), timeout is 0, and the feature is disabled; consider setting the timeout to a value, which is deliberately larger than an average time of a single tester pass for your EA in selected mode (such as open prices, ticks, etc). Usually 60 seconds is ok, but then the feature will work only if you have 1 or more minutes between successive optimizations. The function should be called from OnInit handler.

Share it with friends: