Product Guide "MT5 Optimization Booster"

Product Guide "MT5 Optimization Booster"

3 September 2024, 16:50
Andrey Dik
0
28
Dear traders and investors! We present to you the MT5 Optimization Booster – an innovative product that will revolutionize your optimization experience on MetaTrader 5!

The MT5 Optimization Booster is designed to enhance the capabilities of the standard optimizer. The Booster allows you to use the highly accurate trading environment of the standard tester/optimizer while "turning off" all its limitations:

1.Unlimited number of parameters for optimization
2.Unlimited parameter step for optimization.
3.Unlimited number of runs.
4.Unmatched speed and accuracy of convergence.
5.Ease of use.
6.Full CPU core utilization.

To take advantage of optimizing your advisor with the MT5 Optimization Booster, you will need to make some small changes to the advisor's code.

Let's go through the steps of what needs to be done with the advisor's code. At the very top of the advisor's code, you need to insert (marked here and further in green) the call to the functions imported from the Booster. Your code will look something like this:

//+----------------------------------------------------------------------------+
//|                                                  Copyright 2024, Your Name |
//|                                       https://login.mql5.com/ru/users/user |
//+----------------------------------------------------------------------------+
#property copyright "Copyright 2024, Your Name"
#property link      "https://login.mql5.com/ru/users/user"

//------------------------------------------------------------------------------
#import "..\..\..\Market\MT5 Optimization Booster.ex5"
void AddRange     (double rangeMin, double rangeStep, double rangeMax);
bool AddRangeDone ();
bool GetInputs    (double &inputs []);
void SaveResult   (double ff);
#import
//------------------------------------------------------------------------------

The code above is intended to call the Booster functions (which by default are located in the \MQL5\Experts\Market\ folder) from the advisor. If you have moved the Booster to another folder, please adjust the path to it in the code above.

Next, insert a line in the code with a parameter counter that will iterate through the standard optimizer instead of your parameters:

//------------------------------------------------------------------------------
input int    CNT_P   = 0;
//------------------------------------------------------------------------------

Suppose the Expert Advisor has the following parameters that need to be optimized:

//------------------------------------------------------------------------------
enum Timeframe
{
  M1, M5, M15, H1, D1
};

input Timeframe ChartTimeframe  = H1;
input int       IndPeriod       = 10;
input double    IndAlpha        = 0.1;
input bool      UseTrailingStop = true;
//------------------------------------------------------------------------------

Make these parameters simple global variables by removing "input" before declaring them, after this operation the code will look like this:

//------------------------------------------------------------------------------
enum Timeframe
{
  M1, M5, M15, H1, D1
};
/*
input Timeframe ChartTimeframe  = H1;
input int       IndPeriod       = 10;
input double    IndAlpha        = 0.1;
input bool      UseTrailingStop = true;
*/
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
Timeframe ChartTimeframe  = H1;
int       IndPeriod       = 10;
double    IndAlpha        = 0.1;
bool      UseTrailingStop = true;
//------------------------------------------------------------------------------

Next, insert the following code into the OnInit() function at the very beginning:

//——————————————————————————————————————————————————————————————————————————————
int OnInit ()
{
  //For EA in the "Optimization" mode-------------------------------------------
  if (MQLInfoInteger (MQL_OPTIMIZATION))
  {
    AddRange (0, 1, 4);                //Timeframe ChartTimeframe  = H1;
    AddRange (6, 3, 30);               //int       IndPeriod       = 10;
    AddRange (0.0001, 0.0000001, 0.2); //double    IndAlpha        = 0.1;
    AddRange (0, 1, 1);                //bool      UseTrailingStop = true;

    if (!AddRangeDone ())
    {
      return INIT_FAILED;
    }
  }
  //----------------------------------------------------------------------------

In the AddRange() function, pass the optimization parameters corresponding to the parameters to be optimized (minimum range, step, maximum range). This code will instruct the Booster on the configuration of your optimization parameters. Set the range and step values within any limits, as there are no restrictions.

Next, insert the following lines of code immediately after the previous ones described above:

//——————————————————————————————————————————————————————————————————————————————
int OnInit ()
{
  //For EA in the "Optimization" mode-------------------------------------------
  if (MQLInfoInteger (MQL_OPTIMIZATION))
  {
    AddRange (0, 1, 4);                //Timeframe ChartTimeframe  = H1;
    AddRange (6, 3, 30);               //int       IndPeriod       = 10;
    AddRange (0.0001, 0.0000001, 0.2); //double    IndAlpha        = 0.1;
    AddRange (0, 1, 1);                //bool      UseTrailingStop = true;

    if (!AddRangeDone ())
    {
      return INIT_FAILED;
    }
  }
  //----------------------------------------------------------------------------

  //For EA in all modes---------------------------------------------------------
  double inputs [4];

  if (!GetInputs (inputs))
  {
    return INIT_FAILED;
  }
  else
  {
    ChartTimeframe  = (Timeframe)inputs [0];
    IndPeriod       = (int)inputs       [1];
    IndAlpha        = inputs            [2];
    UseTrailingStop = inputs            [3];
  }
  //----------------------------------------------------------------------------

The code above retrieves the optimization parameter settings from a file into the "inputs[4]" array (where 4 is the number of optimization parameters).

Assign each optimization parameter variable the value from the "inputs" array in the same order as when specifying their range and step, as shown above.

Check that the OnInit function code now looks like this:

//——————————————————————————————————————————————————————————————————————————————
int OnInit ()
{
  //For EA in the "Optimization" mode-------------------------------------------
  if (MQLInfoInteger (MQL_OPTIMIZATION))
  {
    AddRange (0, 1, 4);                //Timeframe ChartTimeframe  = H1;
    AddRange (6, 3, 30);               //int       IndPeriod       = 10;
    AddRange (0.0001, 0.0000001, 0.2); //double    IndAlpha        = 0.1;
    AddRange (0, 1, 1);                //bool      UseTrailingStop = true;

    if (!AddRangeDone ())
    {
      return INIT_FAILED;
    }
  }
  //----------------------------------------------------------------------------

  //For EA in all modes---------------------------------------------------------
  double inputs [4];

  if (!GetInputs (inputs))
  {
    return INIT_FAILED;
  }
  else
  {
    ChartTimeframe  = (Timeframe)inputs [0];
    IndPeriod       = (int)inputs       [1];
    IndAlpha        = inputs            [2];
    UseTrailingStop = inputs            [3];
  }
  //----------------------------------------------------------------------------

  /*
  Here is the rest of your advisor's code.
  ...
  ...
  ...
  */

  return (INIT_SUCCEEDED);
}
//——————————————————————————————————————————————————————————————————————————————

In the OnTester() function, write the code for your custom optimization criterion or use the built-in function to obtain the value of the complex optimization criterion. The OnTester() function code will look like this:

//——————————————————————————————————————————————————————————————————————————————
double OnTester ()
{
  double ret = TesterStatistics (STAT_COMPLEX_CRITERION);
  
  //-----------------------------------------------------------------------------
  SaveResult (ret);
  //-----------------------------------------------------------------------------
  return ret;
}
//——————————————————————————————————————————————————————————————————————————————

The code above calculates the optimization criterion and saves the result to a file so that the Booster can retrieve the result and improve it in search of the best value.

So, no more changes are needed in the advisor.

Working with the Booster follows this order:

1. Go to the MT5 optimizer (tester) and set the start and end dates for optimization on the historical data, as well as all other necessary parameters (symbol and others).

2. Set the optimization mode (slow, full parameter sweep), as the Booster will now manage the optimization.

3. Go to the advisor settings, check the box for the CNT_P parameter, and set the values and step to ensure the required number of runs.

4. Start the optimization by selecting all local agents. If there are 4 or fewer CPU cores, it is recommended to leave one agent disabled.

5. Launch the Booster on any chart of any symbol and any timeframe. The Booster will display a window asking you to select the advisor's folder. Choose the advisor's folder, and the Booster will start its work! After that, the Booster window will appear on the chart:

The Booster window shows its activity in red (a running counter), the best found result, the number of tasks sent, the number of tasks completed, and the number of tasks completed by each agent.

6. If the results are satisfactory, you can stop the optimization at any time: First, stop the MT5 optimizer, and then stop the Booster by clicking the button with the cross.

If you run the advisor prepared according to the above recommendations on a chart, the advisor will read the best settings prepared after optimization by the Booster and start working.

Wishing you success in optimization and achieving the best results in trading!