Initial Commit.
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
# Working with Optimization Results
|
||||
|
||||
Functions for organizing custom processing of the optimization results in the strategy tester. They can be called during optimization in testing agents, as well as locally in Expert Advisors and scripts.
|
||||
|
||||
When you run an Expert Advisor in the strategy tester, you can create your own data array based on the simple types or [simple structures](/en/docs/basis/types/classes#simple_structure) (they do not contain strings, class objects or objects of dynamic arrays). This data set can be saved using the [FrameAdd()](/en/docs/optimization_frames/frameadd) function in a special structure called a frame. During the optimization of an Expert Advisor, each agent can send a series of frames to the terminal. All the received frames are written in the *.MQD file named as the Expert Advisor in the terminal_directory\MQL5\Files\Tester folder. They are written in the order they are received from the agents. Receipt of a frame in the client terminal from a testing agent generates the [TesterPass](/en/docs/runtime/event_fire#testerpass) event.
|
||||
|
||||
Frames can be stored in the computer memory and in a file with the specified name. The MQL5 language sets no limitations on the number of frames.
|
||||
|
||||
### Memory and disk space limits in MQL5 Cloud Network
|
||||
|
||||
The following limitation applies to optimizations run in the [MQL5 Cloud Network](https://www.metatrader5.com/en/terminal/help/algotrading/strategy_optimization#cloud_start): the Expert Advisor must not write to disk more than 4GB of information or use more than 4GB of RAM. If the limit is exceeded, the network agent will not be able to complete the calculation correctly, and you will not receive the result. However, you will be charged for all the time spent on the calculations.
|
||||
|
||||
If you need to get information from each optimization pass, [send frames](/en/docs/optimization_frames) without writing to disk. To avoid using [file operations](/en/docs/files) in Expert Advisors during calculations in the MQL5 Cloud Network, you can use the following check:
|
||||
|
||||
```
|
||||
int handle=INVALID_HANDLE;
|
||||
bool file_operations_allowed=true;
|
||||
if(MQLInfoInteger(MQL_OPTIMIZATION) || MQLInfoInteger(MQL_FORWARD))
|
||||
file_operations_allowed=false;
|
||||
|
||||
if(file_operations_allowed)
|
||||
{
|
||||
...
|
||||
handle=FileOpen(...);
|
||||
...
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
| Function | Action |
|
||||
| --- | --- |
|
||||
| FrameFirst | Moves a pointer of frame reading to the beginning and resets the previously set filter |
|
||||
| FrameFilter | Sets the frame reading filter and moves the pointer to the beginning |
|
||||
| FrameNext | Reads a frame and moves the pointer to the next one |
|
||||
| FrameInputs | Receives input parameters , on which the frame is formed |
|
||||
| FrameAdd | Adds a frame with data |
|
||||
| ParameterGetRange | Receives data on the values range and the change step for an input variable when optimizing an Expert Advisor in the Strategy Tester |
|
||||
| ParameterSetRange | Specifies the use of input variable when optimizing an Expert Advisor in the Strategy Tester: value, change step, initial and final values |
|
||||
|
||||
See also
|
||||
|
||||
[Testing Statistics](/en/docs/constants/environment_state/statistics), [Properties of a Running MQL5 Program](/en/docs/constants/environment_state/mql5_programm_info)
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
# FrameFirst
|
||||
|
||||
Moves a pointer of frame reading to the beginning and resets a set filter.
|
||||
|
||||
```
|
||||
bool FrameFirst();
|
||||
|
||||
```
|
||||
|
||||
Return Value
|
||||
|
||||
Returns true if successful, otherwise false. To get information about the error, call the [GetLastError()](/en/docs/check/getlasterror) function.
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
# FrameFilter
|
||||
|
||||
Sets the frame reading filter and moves the pointer to the beginning.
|
||||
|
||||
```
|
||||
bool FrameFilter(
|
||||
const string name, // Public name/label
|
||||
long id // Public ID
|
||||
);
|
||||
|
||||
```
|
||||
|
||||
Return Value
|
||||
|
||||
Returns true if successful, otherwise false. To get information about the error, call the [GetLastError()](/en/docs/check/getlasterror) function.
|
||||
|
||||
Note
|
||||
|
||||
If an empty string is passed as the first parameter, the filter will work only with a numeric parameter, i.e. only frames with the specified id will be viewed. If the value of the second parameter is [ULONG_MAX](/en/docs/constants/namedconstants/typeconstants), only a text filter works.
|
||||
|
||||
Call of FrameFilter("", ULONG_MAX) is equivalent to calling [FrameFirst()](/en/docs/optimization_frames/framefirst), i.e. equal to not using any filter.
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
# FrameNext
|
||||
|
||||
Reads a frame and moves the pointer to the next one. There are two variants of the function.
|
||||
|
||||
1. Calling to receive one numeric value
|
||||
|
||||
```
|
||||
bool FrameNext(
|
||||
ulong& pass, // The number of a pass in the optimization, during which the frame has been added
|
||||
string& name, // Public name/label
|
||||
long& id, // Public ID
|
||||
double& value // Value
|
||||
);
|
||||
|
||||
```
|
||||
|
||||
2. Calling to receive all the data of a frame
|
||||
|
||||
```
|
||||
bool FrameNext(
|
||||
ulong& pass, // The number of a pass in the optimization, during which the frame has been added
|
||||
string& name, // Public name/label
|
||||
long& id, // Public ID
|
||||
double& value, // Value
|
||||
void& data[] // Array of any type
|
||||
);
|
||||
|
||||
```
|
||||
|
||||
Parameters
|
||||
|
||||
pass
|
||||
|
||||
[out] The number of a pass during optimization in the strategy tester.
|
||||
|
||||
name
|
||||
|
||||
[out] The name of the identifier.
|
||||
|
||||
id
|
||||
|
||||
[out] The value of the identifier.
|
||||
|
||||
value
|
||||
|
||||
[out] A single numeric value.
|
||||
|
||||
data
|
||||
|
||||
[out] An array of any type.
|
||||
|
||||
Return Value
|
||||
|
||||
Returns true if successful, otherwise false. To get information about the error, call the [GetLastError()](/en/docs/check/getlasterror) function.
|
||||
|
||||
Note
|
||||
|
||||
In the second version of the call, you must correctly handle the received data in the data[] array.
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
# FrameInputs
|
||||
|
||||
Receives [input parameters](/en/docs/basis/variables/inputvariables), on which the frame with the specified pass number is formed.
|
||||
|
||||
```
|
||||
bool FrameInputs(
|
||||
ulong pass, // The number of a pass in the optimization
|
||||
string& parameters[], // An array of strings of form "parameterN=valueN"
|
||||
uint& parameters_count // The total number of parameters
|
||||
);
|
||||
|
||||
```
|
||||
|
||||
Parameters
|
||||
|
||||
pass
|
||||
|
||||
[in] The number of a pass during optimization in the strategy tester.
|
||||
|
||||
parameters
|
||||
|
||||
[out] A string array with the description of names and parameter values
|
||||
|
||||
parameters_count
|
||||
|
||||
[out] The number of elements in the array parameters[].
|
||||
|
||||
Return Value
|
||||
|
||||
Returns true if successful, otherwise false. To get information about the error, call the [GetLastError()](/en/docs/check/getlasterror) function.
|
||||
|
||||
Note
|
||||
|
||||
Having obtained the number of strings parameters_count in the parameters[] array, you can organize a loop to go through all records. This will help you find the values of input parameters of an Expert Advisor for the specified pass number.
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
# FrameAdd
|
||||
|
||||
Adds a frame with data. There are two variants of the function.
|
||||
|
||||
1. Adding data from a file
|
||||
|
||||
```
|
||||
bool FrameAdd(
|
||||
const string name, // Public name/label
|
||||
long id, // Public ID
|
||||
double value, // Value
|
||||
const string filename // Name of a data file
|
||||
);
|
||||
|
||||
```
|
||||
|
||||
2. Adding data from an array of any type
|
||||
|
||||
```
|
||||
bool FrameAdd(
|
||||
const string name, // Public name/label
|
||||
long id, // Public ID
|
||||
double value, // Value
|
||||
const void& data[] // Array of any type
|
||||
);
|
||||
|
||||
```
|
||||
|
||||
Parameters
|
||||
|
||||
name
|
||||
|
||||
[in] Public frame label. It can be used for a filter in the [FrameFilter()](/en/docs/optimization_frames/framefilter) function.
|
||||
|
||||
id
|
||||
|
||||
[in] A public identifier of the frame. It can be used for a filter in the [FrameFilter()](/en/docs/optimization_frames/framefilter) function.
|
||||
|
||||
value
|
||||
|
||||
[in] A numeric value to write into the frame. It is used to transmit a single pass result like in the [OnTester()](/en/docs/event_handlers/ontester) function.
|
||||
|
||||
filename
|
||||
|
||||
[in] The name of the file that contains data to add to the frame. The file must be locate in the folder MQL5/Files.
|
||||
|
||||
data
|
||||
|
||||
[in] An array of any type to write into the frame. Passed by reference.
|
||||
|
||||
Return Value
|
||||
|
||||
Returns true if successful, otherwise false. To get information about the error, call the [GetLastError()](/en/docs/check/getlasterror) function.
|
||||
+143
@@ -0,0 +1,143 @@
|
||||
# ParameterGetRange
|
||||
|
||||
Receives data on the values range and the change step for an [input variable](/en/docs/basis/variables/inputvariables) when optimizing an Expert Advisor in the Strategy Tester. There are 2 variants of the function.
|
||||
|
||||
1. Receiving data for the integer type input parameter
|
||||
|
||||
```
|
||||
bool ParameterGetRange(
|
||||
const string name, // parameter (input variable) name
|
||||
bool& enable, // parameter optimization enabled
|
||||
long& value, // parameter value
|
||||
long& start, // initial value
|
||||
long& step, // change step
|
||||
long& stop // final value
|
||||
);
|
||||
|
||||
```
|
||||
|
||||
2. Receiving data for the real type input parameter
|
||||
|
||||
```
|
||||
bool ParameterGetRange(
|
||||
const string name, // parameter (input variable) name
|
||||
bool& enable, // parameter optimization enabled
|
||||
double& value, // parameter value
|
||||
double& start, // initial value
|
||||
double& step, // change step
|
||||
double& stop // final value
|
||||
);
|
||||
|
||||
```
|
||||
|
||||
Parameters
|
||||
|
||||
name
|
||||
|
||||
[in] [input variable](/en/docs/basis/variables/inputvariables) ID. These variables are external parameters of an application. Their values can be specified when launching on a chart or during a single test.
|
||||
|
||||
enable
|
||||
|
||||
[out] Flag that this parameter can be used to enumerate the values during the optimization in the Strategy Tester.
|
||||
|
||||
value
|
||||
|
||||
[out] Parameter value.
|
||||
|
||||
start
|
||||
|
||||
[out] Initial parameter value during the optimization.
|
||||
|
||||
step
|
||||
|
||||
[out] Parameter change step when enumerating its values.
|
||||
|
||||
stop
|
||||
|
||||
[out] Final parameter value during the optimization.
|
||||
|
||||
Return Value
|
||||
|
||||
Returns true if successful, otherwise false. For information about the error, use the [GetLastError()](/en/docs/check/getlasterror) function.
|
||||
|
||||
Note
|
||||
|
||||
The function can be called only from [OnTesterInit()](/en/docs/event_handlers/ontesterinit), [OnTesterPass()](/en/docs/event_handlers/ontesterpass) and [OnTesterDeinit()](/en/docs/event_handlers/ontesterdeinit) handlers. It has been introduced to receive Expert Advisor input parameters' values and variation ranges during the optimization in the Strategy Tester.
|
||||
|
||||
When called in OnTesterInit(), the obtained data can be used to redefine the rules for enumeration of any [input variable](/en/docs/basis/variables/inputvariables) using [ParameterSetRange()](/en/docs/optimization_frames/parametersetrange) function. Therefore, new Start, Stop and Step values can be set and the input parameter can even be completely excluded from optimization regardless of the Strategy Tester settings. This allows you to manage the area of the input parameters during the optimization by excluding some parameters from the optimization depending on the Expert Advisor's key parameters' values.
|
||||
|
||||
Example:
|
||||
|
||||
```
|
||||
#property description "Expert Advisor for ParameterGetRange() function demonstration."
|
||||
#property description "Should be launched in the optimization mode of the Strategy Tester"
|
||||
//--- input parameters
|
||||
input int Input1=1;
|
||||
input double Input2=2.0;
|
||||
input bool Input3=false;
|
||||
input ENUM_DAY_OF_WEEK Input4=SUNDAY;
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Expert initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
//--- Expert Advisor is designed for operation only in the Strategy Tester
|
||||
if(!MQL5InfoInteger(MQL5_OPTIMIZATION))
|
||||
{
|
||||
MessageBox("Should be launched in the optimization mode of the Strategy Tester!");
|
||||
//--- finish the Expert Advisor operation in advance and remove from the chart
|
||||
return(INIT_FAILED);
|
||||
}
|
||||
//--- successful completion of initialization
|
||||
return(INIT_SUCCEEDED);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| TesterInit function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnTesterInit()
|
||||
{
|
||||
//--- example for long type input parameter
|
||||
string name="Input1";
|
||||
bool enable;
|
||||
long par1,par1_start,par1_step,par1_stop;
|
||||
ParameterGetRange(name,enable,par1,par1_start,par1_step,par1_stop);
|
||||
Print("First parameter");
|
||||
PrintFormat("%s=%d enable=%s from %d to %d with step=%d",
|
||||
name,par1,(string)enable,par1_start,par1_stop,par1_step);
|
||||
//--- example for double type input parameter
|
||||
name="Input2";
|
||||
double par2,par2_start,par2_step,par2_stop;
|
||||
ParameterGetRange(name,enable,par2,par2_start,par2_step,par2_stop);
|
||||
Print("Second parameter");
|
||||
PrintFormat("%s=%G enable=%s from %G to %G with step=%G",
|
||||
name,par2,(string)enable,par2_start,par2_stop,par2_step);
|
||||
|
||||
//--- example for bool type input parameter
|
||||
name="Input3";
|
||||
long par3,par3_start,par3_step,par3_stop;
|
||||
ParameterGetRange(name,enable,par3,par3_start,par3_step,par3_stop);
|
||||
Print("Third parameter");
|
||||
PrintFormat("%s=%s enable=%s from %s to %s",
|
||||
name,(string)par3,(string)enable,
|
||||
(string)par3_start,(string)par3_stop);
|
||||
//--- example for enumeration type input parameter
|
||||
name="Input4";
|
||||
long par4,par4_start,par4_step,par4_stop;
|
||||
ParameterGetRange(name,enable,par4,par4_start,par4_step,par4_stop);
|
||||
Print("Fourth parameter");
|
||||
PrintFormat("%s=%s enable=%s from %s to %s",
|
||||
name,EnumToString((ENUM_DAY_OF_WEEK)par4),(string)enable,
|
||||
EnumToString((ENUM_DAY_OF_WEEK)par4_start),
|
||||
EnumToString((ENUM_DAY_OF_WEEK)par4_stop));
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| TesterDeinit function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnTesterDeinit()
|
||||
{
|
||||
//--- this message will be shown after optimization is complete
|
||||
Print(__FUNCTION__," Optimization completed");
|
||||
}
|
||||
|
||||
```
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
# ParameterSetRange
|
||||
|
||||
Specifies the use of [input variable](/en/docs/basis/variables/inputvariables) when optimizing an Expert Advisor in the Strategy Tester: value, change step, initial and final values. There are 2 variants of the function.
|
||||
|
||||
1. Specifying the values for the integer type input parameter
|
||||
|
||||
```
|
||||
bool ParameterSetRange(
|
||||
const string name, // parameter (input variable) name
|
||||
bool enable, // parameter optimization enabled
|
||||
long value, // parameter value
|
||||
long start, // initial value
|
||||
long step, // change step
|
||||
long stop // final value
|
||||
);
|
||||
|
||||
```
|
||||
|
||||
2. Specifying the values for the real type input parameter
|
||||
|
||||
```
|
||||
bool ParameterSetRange(
|
||||
const string name, // parameter (input variable) name
|
||||
bool enable, // parameter optimization enabled
|
||||
double value, // parameter value
|
||||
double start, // initial value
|
||||
double step, // change step
|
||||
double stop // final value
|
||||
);
|
||||
|
||||
```
|
||||
|
||||
Parameters
|
||||
|
||||
name
|
||||
|
||||
[in] [input or sinput](/en/docs/basis/variables/inputvariables) variable ID. These variables are external parameters of an application. Their values can be specified when launching the program.
|
||||
|
||||
enable
|
||||
|
||||
[in] Enable this parameter to enumerate the values during the optimization in the Strategy Tester.
|
||||
|
||||
value
|
||||
|
||||
[in] Parameter value.
|
||||
|
||||
start
|
||||
|
||||
[in] Initial parameter value during the optimization.
|
||||
|
||||
step
|
||||
|
||||
[in] Parameter change step when enumerating its values.
|
||||
|
||||
stop
|
||||
|
||||
[in] Final parameter value during the optimization.
|
||||
|
||||
Return Value
|
||||
|
||||
Returns true if successful, otherwise false. For information about the error, use the [GetLastError()](/en/docs/check/getlasterror) function.
|
||||
|
||||
Note
|
||||
|
||||
The function can be called only from [OnTesterInit()](/en/docs/event_handlers/ontesterinit) handler when launching optimization from the Strategy Tester. It is designed for specifying the parameter's range and change step. The parameter can be completely excluded from optimization regardless of the Strategy Tester settings. It also allows using the variables declared with sinput modifier in the optimization process.
|
||||
|
||||
ParameterSetRange() function allows you to manage an Expert Advisor optimization in the Strategy Tester depending on its key parameters' values by including or excluding required input parameters from the optimization and setting the required range and the change step.
|
||||
Reference in New Issue
Block a user