Step-by-step instructions on how to properly optimize Expert Advisors for the MetaTrader 4 and MetaTrader 5 terminals. Full description of all optimizer fields and optimization results.

How to Optimize Forex and Crypto Expert Advisors
Complete Instructions for MetaTrader 4 and MetaTrader 5

Optimization of Expert Advisors in MetaTrader 5

The strategy tester allows the trader to test and optimize trading strategies (Expert Advisors) before using them in the real world. The process of testing the Expert Advisor consists in its one-time run using the initial parameters. And in order to optimize a trading strategy, it is needed to carry out repeated runs using different sets of parameters. As a result, it is possible to choose the most effective combination of these parameters to make a profit.

The multicurrency nature of the strategy tester makes it possible to test and optimize trading strategies that use several financial instruments. This eliminates the need to specify a list of symbols for optimization/testing, as the strategy tester automatically processes information on all symbols that have been defined for use in the EA.

Thanks to the multithreading of the strategy tester, it is possible to use all available PC resources. To carry out optimization and testing, special computing agents are used, which are loaded onto the user's computer as servers. Since the work of agents is independent, optimization passes can be calculated in parallel.

The functions of the strategy tester allow an almost infinite number of remote agents to be connected to it. In addition to this, the strategy tester makes it possible to use the huge MQL5 Cloud Network, which unites more than one thousand agents around the world. And all this computing power can be used by any client of the trading platform. 

The capabilities of the strategy tester are not limited to testing and optimization. For example, it can check the operation of custom indicators in visual mode. This function makes it easy to check demo indicators downloaded from the Market.

How to optimize

During optimization, the EA is usually run multiple times on historical data. A variety of parameter sets can be used to obtain the best option. Repeated runs allow possible combinations of the input parameters of an EA to be tried and tested in order to select the most workable combinations.

Selecting an optimization problem

The user running the tester, instead of many settings, is offered several typical tasks to choose from. This makes life much easier for beginners who do not have enough work experience.

Open the start page gives the user access to several basic optimization and strategy testing tasks, as well as the ability to restart one of the previous tasks quickly.

If there is not enough space in the list for running tasks, it is recommended to use the search bar, where the test can be found by the following parameters:

  • modeling type;
  • timeframe;
  • tool;
  • program name.

Optimization of Expert Advisors

After selecting one of the tasks on the start page, the user must fine-tune the testing parameters:

  • select an expert;
  • set period;
  • define tools;
  • other options. 

The work is made easier by showing only those parameters that are needed for the selected task. For example, if a trader chooses mathematical calculations, he will only need parameters for selecting a testing and optimization mode program. In this case, the settings for testing periods, delays, as well as tick generation will be hidden. 

Select a program to test

First of all, the context menu of the required Expert Advisor is selected and the  «Test» command is executed.

Optimization of Expert Advisors

As a result, the Expert Advisor will be selected in the strategy tester.

Set symbols in the Market Watch window for multicurrency Expert Advisors

Using the tester, it is possible to check the history of strategies trading on several instruments. Such experts are conditionally called multicurrency. The tester downloads the history of the instruments used, using the trading platform (and not the trading server) for this. This happens automatically when a specific tool is accessed for the first time. The trade server is used only in case of lack of history.

Before the optimization of the multicurrency Expert Advisor starts, it is necessary to enable the instruments necessary for testing in the «Market Watch». Next, the  ""Symbols" and the display of the necessary tools is turned on.

Optimization of Expert Advisors

Optimization settings

Before the start of optimization, it is necessary to select a financial instrument on which the robot will be tested. In addition, the period and mode are set.

Optimization of Expert Advisors

  1. Select Expert Advisor for testing or optimization.
  2. Select financial instrument.
  3. Time interval for testing and optimization.
  4. Enable forward testing.
  5. Enable order execution delays.
  6. Select the type of price simulation.
  7. Select initial deposit.
  8. Enable and select optimization type.
  9. Select the period testing or optimization.
  10. Date when testing or optimization started.
  11. End date testing or optimization.
  12. Start date of the forward test.
  13. Select the deposit currency.
  14. Select the leverage.
  15. Enable visual testing mode (significantly slows down the testing process, does not work for optimization).
  16. Security instrument settings.
  17. Opens the MetaEditor to access the source code of the program.
  18. Select Expert Advisor settings file.
  19. Additional «thin» optimization and testing settings.
  20. Select the type of profit calculation (for many trading systems it may work  incorrectly).
  21. An overview tab for predefined testing or optimization types.
  22. Settings testing or optimization tab.
  23. Advisor settings tab.
  24. Tab of agents-processor cores for optimization.
  25. Testing and optimization log tab (the terminal writes all errors and program results to this tab).
  • It must be remembered that if a symbol is specified, this does not mean that the tester uses only the indicated historical data. The tester automatically downloads information for all symbols used in Expert Advisor.
  • Also, all available price data based on the symbol of the main chart is automatically loaded into the platform. And this happens even before the start of testing/optimization. If the trader is using insufficient internet speed, this operation can take quite a long time.
  • All data is downloaded once. At the next launch, only the missing information is loaded.
  • In the Market Watch window, symbols are available that can be used for testing/optimization.
  • Another automatic – downloading data from the server by requested characters.
  • Start and end times for testing – 00h.00m.00 s. We must not forget that only the start date of testing/optimization is included in the testing period. End of testing – this is the last peak of the previous day. The end date cannot be greater than the current date: testing will still end on the current date, which is not included. 

To speed up optimization using a genetic algorithm, a trader can use the selection of optimization criteria, for which the field is allocated to the right. It contains information about the parameters to represent the most successful EA runs. The value of the result is directly proportional to the level of the selected indicator.  

After all settings are completed, the «Start» button is activated; and the testing or optimization process starts:

  • When testing/optimization is started, the settings of the strategy tester are saved.
  • If the optimization is stopped in the normal mode, that is, by pressing the «Stop» button, all previously calculated passes are saved. The next time the process is started, it will start where it left off.


The input parameters are used to control the behavior of the Expert Advisor, its adaptation to different market conditions, as well as to a specific financial instrument. For example, the work of an EA can be tested with different order placement distances (stop loss and take profit). It is possible to apply different moving average periods to  analyze the market before making a decision.

Optimization is essentially a process that tries different values and combinations of input parameters to get the best result.

Optimization of Expert Advisors

To enable optimization by parameter, select it by ticking the box. After that, the initial and final values are set, as well as the search step. It is possible to select one or more options. The total number of possible combinations can be seen below the list of parameters.

In order for the user to be able to return to the current settings of the MQL5 program, the set of parameters is saved. This can be done via the context menu:

  • To save the set on your computer as a set-file, it is needed to activate the «Save» button. These files are easily transferred between terminals on different PCs, as well as transferred to other users.
  • If it becomes necessary to save a set in order to use it in the future in the current platform, click on the «Save Set» button. To gain access to the parameters saved in this way, it is enough to go to the«Download Set» submenu. They are activated by elementary selection from the list.

Advanced test settings

The user has the opportunity to set his own trading account settings in the process of testing the following strategies:

  • commissions;
  • trading restrictions;
  • margin;
  • other.

Thanks to this opportunity, a trader simulates a variety of trading conditions with stock brokers.

Optimization of Expert Advisors

General settings

This section can be used to set the maximum possible number of positions and open orders that are present on the account simultaneously. In addition, session settings are available here in case of a ban on trading for the tested program.


Here it is possible to control the margin reservation process and which position accounting system is intended to use for testing.

Optimization of Expert Advisors

  1. Risk management model: OTC and exchange, netting and hedging.
  2. The level of funds on the account, upon reaching which it switches to the Margin call state.
  3. This field specifies how the current unrecorded profit/loss in the free margin will be taken into account:

    • Do not use unrealized profit/loss — do not take into account open positions when calculating.
    • Use unrealized profit/loss — use when calculating the loss and profit on open positions.
    • Use unrealized profits — use profit only.
    • Use unrealized loss — use only loss.
    • .
  4. This field indicates how the profit/loss fixed by the trader during the trading day will be taken into account in the free margin:

    • Use Daily Fixed Profit/Loss — take into account the profit and loss recorded during the trading day in the free margin.
    • Use Daily Fixed Loss — take into account only the loss fixed during the trading day in the free margin. During the day, the accumulated profit is fixed in a separate field of the account ("Blocked"). At the end of the trading day, the accumulated profit is released (reset to zero) and reflected on the account balance (taken into account in the free margin).
    • .
  5. Release accumulated profit at the end of the day — this option is available only if the "Use daily fixed loss" option is enabled. If it is enabled, then at the end of the trading day, the profit accumulated during the day will be released and written to the balance (and, accordingly, taken into account in the free margin). Otherwise — won't.
  6. The level of equity, upon reaching which orders are forcibly removed from the account and trading positions are closed. Both levels can be specified in money and as a percentage. In the first case, the levels are defined as the value of the indicator "Funds" on the account. If the "Percentage" option is selected, the levels are defined as the value of the "Margin Level" indicator on the account (Equity/Margin*100).


This section is intended to give the user control over the procedure for charging a commission on each of the trades:

  • Commissions are divided into single-level and multi-level. In the first case, the size of the commission charged does not change with a change in the volume of the transaction or turnover, while in the second case this dependence exists.
  • The time of commission collection is set either immediately after the closing of the transaction, or at the end of a certain trading period – day or month.
  • There is a division of commissions depending on the direction of the transaction: for exiting, for entering, for both.
  • The commission is set either for each trade or for each lot.
  • Commission types may vary (in pips, percentages, money).

When the «Use your own commission settings» option is enabled, commission settings for the current trading account become available.

Optimization of Expert Advisors

Custom test symbol settings

The main trading instrument used for testing or optimization can be reconfigured by the user. It has access to almost all of the specificity options:

  • execution mode;
  • volumes;
  • margin requirements;
  • trade modes;
  • more.

As a result, there is no need to create a custom symbol and load history into it in order to test the EA in other trading conditions. It is enough just to change the settings of the standard tool.

Optimization of Expert Advisors

When the symbol specification is changed, an asterisk appears on the settings icon (as well as on the custom symbol icon) in the list. Thanks to this, the user always understands that custom settings are applied for testing.

Optimization of Expert Advisors

Run optimization

To do this, just click on the «Start» button, which is located in the «Settings» tab. On the left, the user will see how the optimization is launched.

How and where to see optimization results

View detailed results for each individual pass is available on the Optimization tab. Here it is possible to see the general results of testing:

  • information on the number of trading operations;
  • profit margin;
  • Various statistics to help evaluate the quality of the robot.

For detailed information, just go to the «Test Report» section.

It is possible to sort the optimization report by any parameter. To do this, just hover over the column heading and click. If desired, the user can not only find the most profitable combination of parameters, but also run it in single test mode to get a more detailed report.

Optimization of Expert Advisors

Indicators displayed for each individual optimization pass:

  • Aisle – pass number.
  • Result – the final indicator of the parameter, which is the optimization criterion by which the best passes are selected.
  • Profit – profit or loss resulting from the pass.
  • Total Trades – the number of trades (trades that led to profit or loss) carried out in the current pass.
  • Profitability – the ratio of total profit to total loss in percent. One means that profit and loss are the same. 
  • Expected payoff – a statistically calculated indicator that reflects the average profit or loss of one trade.
  • Drawdown – relative drawdown of funds, the highest loss (as a percentage) of the maximum value of funds. Withdrawal by the EA during optimization is taken into account when calculating the drawdown.
  • Recovery Factor – this parameter reflects the riskiness of the strategy (how much the EA risks to make a profit). The indicator is calculated as the ratio of the received profit to the maximum drawdown.

Sharpe Ratio — this indicator characterizes the effectiveness and stability of the strategy. It displays the ratio of the arithmetic mean profit during the position holding to the standard deviation from it. In addition: it takes into account the value of the risk-free rate, which is the profit on the deposit of the corresponding amount on a bank deposit.

Parameter(s) to be optimized — in addition to general statistics, it displays the values of the input variables set for this pass.

The context menu commands allow hiding or show some of the columns listed in the table. To make it more convenient to work, the «Auto-switch to results» option is enabled. As a result, as soon as the optimization is completed, the strategy tester will automatically switch to the results tab. There is a similar command in the context menu that opens after activating the «Log» tab.

Thanks to the filters, the user can quickly hide the unsuccessful passes in the list, in which:

  • no deals;
  • the robot shows losses;
  • drawdown exceeds 50%;
  • recovery factor below one;
  • Sharpe ratio level does not reach 0.5.

For ease of visual analysis of passes, it is common to color the optimization results in the following colors:

  • Balance: blue – values exceed the initial deposit; red – values below the initial deposit.
  • Profit: blue – values above zero; red – values below zero.
  • Expected win: blue – above zero; red – below zero.
  • Drawdown: green – from 0 to 5%; red – above 30%.
  • Sharpe Ratio: Green – exceeds 2; red – below zero.
  • Recovery factor: green – more than two; red – does not reach one.
  • If forward testing was used during optimization, then the appropriate parameters of the optimization criterion (optimization parameter) for the forward test and back test will be displayed in the indicated tab. To switch between viewing modes of forward testing and back testing results, use the context menu.
  • With double-click the left mouse button while hovering over one of the optimization results, the testing of the Expert Advisor will start. If the optimization is completed, the parameters of this run will be applied.
  • Sometimes there is a situation where the input parameters of the next pass (member of the population) are identical to the shown pass tested earlier. For this reason, this pass will not be reflected in the results tab. But it will be reflected in the optimization chart, where the display of all passes allows showing how the search for the best result went.
  • The red background of the optimization pass line indicates an error in the EA operation. A similar entry will be made in the tester's log. 

Optimization cache

The cache contains information about optimization passes that have been calculated previously. The strategy tester needs it so that optimization resumes after a pause without recalculating already calculated testing passes.

Optimization caches, which are rendered as binary files, are stored in the\Tester\cache folder. The files are named according to the following rule: ExpertName.Symbol.Period.StartDate.EndDate.GenerationModeOptimizationMode.Hash.opt.


  • ExpertName – the name of the Expert Advisor being optimized;
  • Symbol – symbol;
  • Period – timeframes;
  • StartDate – optimization start date;
  • EndDate – optimization end date;
  • GenerationMode (tick generation mode): 0 – «All tics», 1– «Each tick based on real ticks», 2 – «OHLC on M1», 3 – «Only opening prices», 4 – «Mathematical calculations».
  • OptimizationMode (optimization type): 0 – «Slow (full enumeration of parameters)», 1 – «Fast (genetic algorithm)», 2– «All symbols selected in the window«Market Watch»».
  • Hash.opt – hash derivative of all other parameters (used to find cache files).

The presence of cache files always allows getting acquainted with the optimization results that were obtained earlier. To do this, open the «Optimization results» tab, select an expert, and a file containing the optimization cache:

Optimization of Expert Advisors

The list contains the complete set of optimization cache files available on the disk of the expert that was selected. Here the user will see the following data:

  • date of optimization;
  • information about input parameters;
  • testing settings (dates, timeframe, symbol).

Additionally, the function of filtering the optimization results based on the trading server from which they were received is provided.

It is also possible to change the optimization criterion that was set before launch. It is displayed in the «Result» column and determines the quality of the tested set of input parameters. There is a direct connection between the value of the optimization criterion and the evaluation of the test result with a particular set of parameters: the greater the value of the first, the higher the second indicator. In order for the tester to automatically recalculate all available in the «Result» column values, it is required to select the appropriate criterion in the list from the top of the tab.

When using third-party programs (such as Office Excel), it is possible to save the optimization report as a file. To do this, go to the context menu and select the command   «Export to XML». It also contains commands for both exporting and importing cache files. They are best used in cases where it is necessary to transfer optimization results from one platform to another. 

  • To optimize disk space, cache files are automatically deleted after thirty days of inactivity.
  • When genetic optimization is performed, intermediate results are cached after each generation is calculated (file platform_data_folder/tester/cache/*.gen). Thus, interruption of the genetic optimization process can be done at any time. Even if this happens for some external reason, the process will automatically continue from the place where it was interrupted, as soon as the interruption cause is eliminated. The storage of the genetic optimization cache is terminated if the optimization settings are changed or the optimization process ends.
  • If optimization is interrupted with the «Stop» button,  saving of all previously calculated passes is guaranteed. The resumption of optimization serves as a signal to continue the process from the point where it stopped.

How optimization results are visually represented

The strategy tester in the trading platform has a powerful system that allows visualizing optimization results. To do this, go to the «Optimization Chart» tab, which has access to several types of charts – to switch between them, use the context menu.

Zero line (plane)
Display of the zero line is available on each of the existing types of charts. The only exception is 2D, which displays a plane if the chart is 3D. When the balance value is an optimization criterion, this line indicates the size of the initial deposit. Due to this, profitable passages are visually separated from unprofitable ones. All other cases imply using the zero value of the optimization criterion to draw this line.

Result Plot and Line Plot (1D)

It is not necessary to take any action to open a chart showing optimization results, as this happens by default.

A point is used to display each pass of an Expert Advisor that has certain input parameters.

The horizontal axis of the chart is used to mark the pass number, and the vertical – for the values of the parameter, which is the optimization criterion.

Depending on the value of the optimization criterion, color gradients from green to red are applied to color the chart.

Optimization of Expert Advisors

Line chart (1D) is used to display the parameter. The optimization criterion is selected along the vertical axis, and along the horizontal axis – one of the optimization parameters selected to be displayed on this axis. Using the «X Axis» command from the context menu, the user selects which parameter will be displayed on the horizontal axis.

Flat (2D) and 3D (3D) plots

If 2D display is selected, then changes that have occurred in the parameters selected before optimization are postponed on each axis. Color gradients are used to show changes in the optimization criterion. Higher values of the optimization criterion correspond to a more saturated color.

Optimization of Expert Advisors

When the 3D view mode is selected, the X and Y axes are used to mark the changes that have taken place in the selected parameters, and optimization criteria are displayed on the vertical Z axis. Through the command «Axis X» and «Axis Y» the user can select options for displaying on the vertical and horizontal axes.

The 3D chart can be controlled with the mouse:

  • The central part captured by the left mouse button can be moved by moving the cursor.
  • Rotation of the mouse wheel while holding down the Ctrl key allows rotating the chart around the horizontal axis.
  • To zoom in or out of the chart, press the Ctrl key and hold down the left mouse button to move the cursor vertically along the central part of the chart.
  • The pressed left mouse button and the Ctrl button allow moving the zero plane if moving the cursor vertically, removing it from the central part of the chart.
  • In order for the chart to return to its original position, it is enough to double-click with the left mouse button while the cursor is hovering over the central part.

Control the 3D chart using the keyboard:

  • Enable/disable coordinate grid – G.
  • Switch between solid and line fills – space.
  • Camera move up (chart moves down) – up arrow.
  • Camera move down (chart moves up) – down arrow.
  • Camera move to the right (chart moves to the left) – right arrow.
  • Camera move to the left (chart moves to the right) – left arrow.
  • Camera zoom (zoom in) – plus.
  • Camera zoom (zoom out) – minus.
  • Rotate the chart on forward around the horizontal axis – Home.
  • Rotate the chart away backward around the horizontal axis – Page Up.
  • Rotation of the chart around the vertical axis counterclockwise – End.
  • Rotate the chart around the vertical axis clockwise – Page Down.
  • Move the ground plane up by one – Ctrl+Up Arrow.
  • Move the ground plane down by one – Ctrl+Down Arrow.
  • Move the ground plane up by 10 units – Ctrl+Page Up.
  • Move the ground plane down by 10 units – Ctrl+Page Down.
  • Move the ground plane to the maximum value of the chart – Ctrl+Home.
  • Move the ground plane to the minimum value of the chart – Ctrl+End.
  • Increase the transparency of the ground plane – Ctrl+Plus.
  • Reduce the transparency of the ground plane – Ctrl+Minus.
  • Set ground plane transparency to maximum (disappears) – Ctrl+Right Arrow.
  • Set ground plane transparency to minimum (becomes opaque) – Ctrl+Left Arrow.
  • Revert to default chart settings – key "5" on the numeric keypad.

Check the robot by forward testing on a non-optimized area

When they talk about forward testing, they mean a re-run of the best optimization results for a different time period. Forward testing makes it impossible to adjust the parameters of Expert Advisors on specific sections of historical data.

Algorithm for enabling forward testing – Settings tab => field «Forward period» => specifying that part of the total period for which the check should be applied:

  • no – no forward testing required;
  • 1/2 – only half of the selected period is used for forward testing;
  • 1/3 – one third of the selected period is used for forward testing;
  • 1/4 – one fourth of the selected period is used for forward testing;
  • custom – when selecting this field, it is required to specify the date of the start of forward testing on the right side.

Optimization of Expert Advisors

  • Forward testing is always subject to the last (second) part of the total period.
  • Vertical line on optimization chart – this is the start date of the forward period.

In the «Use date» field, it is necessary to separate the selected part from the selected period:

  • the first of these is called back testing;
  • second – forward testing.

The back-testing period is used to perform full optimization of the EA (slow or fast). After that, the selection of the best runs is performed:

  • if there is a full search, then 10% is selected;
  • during genetic analysis, 25% is selected.

And they are tested on the forward period.

Lower limit set for number of forward test runs:

  • When the number of best runs is less than 256,  to  additional best runs are added to it until the required number is reached.
  • If the total number of runs is less than two hundred and fifty six, then all available runs are used in forward testing.

When using genetic optimization for forward passes, it is recommended to use all unique results.

To view the optimization results for the forward period, the user just needs to go to the «Forward optimization» tab; or «Optimization». In the latter case, the «Forward testing results» item is selected in the context menu. How often the results will coincide directly depends on whether the Expert Adviser can show a good result in real trading.

To be able to visually present the results of optimization on the forward period, just go to the «Forward optimization chart» tab. A comparison with a back test is also available, for which it is possible to switch between them using the context menu.

Optimization of Expert Advisors

Using agents for multi-threaded testing

In order to use all available computer resources, it is recommended to use a multi-threaded tester. For this purpose, it is necessary to install special computing agents that work independently on the PC in the form of servers. This allows parallel computation of optimization passes.

Agents come in three types:

  • Locals – installed by default along with the installation of the trading platform.
  • Deleted – using the power of other computers.
  • Cloud – working similarly to the previous ones.

Their number directly depends on the processor power on the computer. To select the agent that will be used in the optimization process, go to the «Agents» section; in the strategy tester.

Optimization of Expert Advisors

What to watch out for:

  • To reduce laptop battery consumption, it is better to stop using local agents and switch to cloud or remote ones.
  • For five minutes, the processes of used local agents are not unloaded from the computer's memory if testing was not stopped using the «Stop» button; or it was not due to the closure of the trading platform. This eliminates delays due to preparing historical data and starting agent processes. But this statement is true only when the EA, symbol, period, or time interval do not change when testing or optimization is restarted.  
  • The default installation at the same time as the trading platform only applies to local agents. Their use is possible only in testing the strategies of a specific local platform. Install remote agents is only possible in manual mode.   

Local agent farm to speed up optimization

Sometimes even installing a multi-core processor on a computer does not contribute to a multiple increase in the number of parallel tasks. With the help of the strategy tester, it is possible to create your own computing farm of agents in the local network.

Algorithm for creating an agent farm

Agents are installed on all computers connected to the local network. If this was done earlier, then to open the test agent manager, go to the «Tools» menu.

Optimization of Expert Advisors

To install from scratch, after downloading the MetaTrader 5 Strategy Tester Agent application, it is needed to follow a simple instruction:

  1. Go to the «Services» tab in the manager.
  2. Select the required number of agents to be installed, which depends on how many cores the processor has.
  3. Specify the password that agents will use to connect.
  4. Select a range of ports.
  5. Enable button «Add».

When the installation process is complete, they can be used from any computer connected to the local network.

Only 64-bit operating systems are suitable for using remote agents.
To save disk space and traffic, as well as to improve security, it is not recommended on remote agents:
  • show EA messages and information related to trading operations in the log;
  • call the DLL.

Order of connecting agents

After opening the strategy tester, go to the «Agents» tab, where the «Local Network Farm» item is selected; and click the «Add» button.

Optimization of Expert Advisors

Easier and faster addition is done through automatic port and LAN scanning over a range of IP addresses. They are specified along with a password that allows connecting to agents.

Optimization of Expert Advisors

After clicking the «Done» button it will be possible to test all found agents.

There are a few more options to add agents:

  • Use the server's IP address or domain name. To do this, the listed data is specified, as well as the range of ports in combination with the password set for connecting agents.
  • Import from *.mt5 file. After clicking the «Next» button specify the *.mt5 file from which agents are planned to be imported.

If MetaTester 5 Agents Manager was used to install agents on a computer, they can be connected as remote on the same PC. If there is some power reserve, it becomes possible to increase the load and use the entire computing potential.

Changing agent settings

To change an agent's settings, the command «Edit» is activated in its context menu.

Optimization of Expert Advisors

The settings window contains the following fields:

  • Name – the name of the agent is specified here.
  • Address – here specify the IP address and port of connection to the agent.
  • Password – the password for connection is specified here.
  • Enable – here check the box so that this agent takes part in testing, otherwise the process will be carried out without it.  

Local agents can only be enabled or disabled.

Import and export parameters of external agents

The platform has the ability to import and export settings of external agents into test files in order to facilitate this process. Agent settings files have *.mt5 extension. Location of import and export commands – Agents tab.

Format of agent settings file: Name;Address:port;Password;Description;Enable.

It has the following designations:

  • Name – agent name.
  • Address:port – specifying the IP address and port for connecting to the agent.
  • Password – connection password.
  • Description – a brief description of the technical equipment on which the agent is running.
  • Enable – number 1 (agent enabled) or 0 (agent disabled).

Line breaks are used to separate the settings of different agents.

MQL5 Cloud Network to accelerate optimization

When using the MQL5 Cloud Network (cloud computing network), it becomes possible to speed up the optimization of the Expert Advisor. This is achieved by using the power of a large number of computers.

With the help of the network, remote agents are combined, as well as the distribution of optimization tasks between them. To connect the strategy tester to the cloud network, several access points are used, the placement of which takes into account the territorial principle.  

Nuances related to the operation of the MQL5 Cloud Network

When working with MQL5 Cloud Network, the following points should be taken into account:

  • The capacity of the MQL5 Cloud Network is used when there is a complete enumeration of parameters.
  • A feature of the genetic algorithm is such that genetic optimization requires the use of only one access point.
  • When the total number of optimization steps exceeds 100,000,000, the genetic optimization mode is switched on automatically.
  • To use the MQL5 Cloud Network, a 64-bit system must be used on the computer.
  • A user can be not only a consumer of the MQL5 Cloud Network, but also a supplier of his own computing power to the network. To install remote agents and connect them to the network, it is recommended to use the special MetaTester utility.
  • For complete information about the MQL5 Cloud Network, go to the official website

Expenses for using MQL5 Cloud Network

The MQL5 Cloud Network agents cannot be used for free. To get acquainted with the cost calculation formula, go to a separate section of the website. To display the value of the current balance of the account, a place has been allocated above the list of cloud agents.

Using the MQL5 Cloud Network is possible if your account balance is at least $1. The user must be willing to pay for the services of batch distribution of jobs to a certain number of access points.

It is important to consider that the network does not have the ability to calculate in advance the required amount of time and resources that will be required to calculate these tasks.   

Launch MQL5 Cloud Network

To enable network agents, go to the context menu and activate the  «Enable» command. If there is no information about having an account on,  the user will be prompted to enter it.

Optimization of Expert Advisors

If haven't registered before, follow the link to create a new account.

Algorithm for starting calculations using MQL5 Cloud Network

As in the case of regular optimization, after specifying the required testing settings, as well as the input parameters of the Expert Advisor, activate the «Start» button. Further in the tab «Agents» it is possible to control the process of distributing tasks from the strategy tester to available agents. It displays the number of not only available agents, but also those that are currently involved.

Optimization of Expert Advisors

Sometimes traders need to optimize for several tens or hundreds of thousands of passes at a certain time. The use of the multi-threaded strategy tester and the MQL5 Cloud Network makes it possible to perform calculations within one hour that can be performed independently in just a few days. Access to the processing power of several thousand cores is available in the trading platform.

Optimization types

There are two optimization modes available in the strategy tester. To make a choice between them, go to the «Settings» tab.

Optimization of Expert Advisors

Slow mode (full enumeration of parameters)

Choosing this mode allows complete enumeration of all possible combinations of input variable values selected for optimization. To do this, go to the appropriate tab.

It is believed that the results obtained by this method are more accurate. But in order to run the Expert Advisor for each combination of parameters, it may take quite a long time.

Fast Mode (Genetic Algorithm)

The peculiarity of this method is that a genetic algorithm is used to select the most optimal values of the input parameters. It is not inferior to the previous  qualitatively, but its use allows speeding up the execution of a complete enumeration of parameters.

The genetic algorithm allows performing in a short period of time the amount of work that would take days (and sometimes weeks) to complete by exhaustive enumeration.

Each individual has a specific set of genes corresponding to its parameters. The cornerstone of genetic optimization is the principle of continuous selection of the most «adapted» parameters – values that allow getting the best result in the end.

The general view of the algorithm can be described as follows:

  1. From the total number of combinations of parameters, two populations (sets) are randomly selected.
  2. After testing the selected sets, the one that showed the best results is kept.
  3. The members of the selected set are crossed, the purpose of which is random mutations due to the exchange of fragments of genetic information.
  4. The best results are selected from the obtained results, and the crossing is carried out again.

The best result among the offspring is the one that is better than the best result of the parents. All the above operations do not stop until the optimal result is achieved.

Number of test passes

Due to the reduction in the total number of passes during genetic optimization, the overall speed of the process increases. When genetic optimization is already running, go to the «Settings» tab, where the estimated number of planned test passes is indicated. To calculate it, a formula is used in which:

  • Population size – can have a value between 64 and 256. The basis for its calculation is the number of possible combinations of parameters to be optimized.
  • Unconditional number of generations – can range from fifteen to thirty-one. In this case, 15 passes are mandatory. If there is no improvement in the optimization criterion on one of the generations between 15 and 31, then additional testing of all generations is started to evaluate the convergence.
  • Number of generations to evaluate convergence – the calculated number is one third of the stipulated number of generations. For example, if the best result is recorded on the seventeenth generation, and it is absent on the eighteenth, then additional testing of five generations is performed – because improvements were already missing on the eighteenth generation, and to check the convergence, the absence of positive dynamics on six generations (18/3) is required.

Testing ends if there is no improvement for the agreed number of generations.

  • Fast optimization turns on automatically when the total number of optimization steps reaches the mark  1,000,000 (32-bit system) or 100,000,000 (64-bit system).
  • To save intermediate results during genetic optimization, after each generation is calculated, a cache is used (platform_data_folder/tester/cache/*.gen file). Therefore, interruption of the genetic optimization process is possible at any stage. Even when genetic optimization is interrupted by external factors (no light), the point of automatic continuation of optimization will be the last calculated generation.
  • Cache persistence is ensured either until the optimization settings are changed or until the optimization is complete.
  • If the «Stop» button was used to stop the optimization, the previously calculated passes are saved and the resumed optimization will start from where it stopped.

Optimization criterion

This is the name of the indicator, the value of which is determined by the quality of the tested set of input parameters. The larger it is, the higher the assessment of test results with a certain set of parameters. To select this indicator, go to the «Settings» tab, where it is located to the right of the «Optimization» field.

The need for an optimization criterion arises only when using a genetic algorithm.

Optimization of Expert Advisors

An access to the following optimization criteria:

  • Max balance – the indicator of optimization is the maximum balance value.
  • Maximum profitability – the indicator is the maximum value of profitability.
  • Max win expectation – the indicator is the expectation of winning.
  • Minimum drawdown – in this case, the drawdown level is taken into account: Balance/Equity drawdown.
  • Maximum Recovery Factor – the indicator is the recovery factor.
  • Maximum Sharpe Ratio – the indicator is the Sharpe ratio.
  • Custom optimization criteria – when this parameter is selected as an optimization criterion, the value of the OnTester() function in the Expert Advisor will be taken into account. This parameter allows applying any custom indicator for optimization.

In addition, there is «Maximum of the complex criterion», which is a complex, integral indicator of the quality of the test pass.

It simultaneously takes into account the following parameters:

  • number of deals,
  • drawdown level,
  • Sharpe ratio,
  • mathematical expectation of winnings,
  • recovery factor.

Thanks to this criterion, based on a comprehensive analysis, there is an understanding that one overestimated parameter – not always the best option. Its use makes it possible to select the best passes:

  • first of all, the number of deals is evaluated;
  • then – mathematical expectation of profit;
  • next – recovery factor;
  • and so on.

The result of optimization is getting the best passes for each parameter, from which it is possible to choose the most attractive one at the moment.

Market Watch Window and characters selected in it

A distinctive feature of this optimization mode is the ability to test the EA when using the same input parameters but different symbols. During any optimization pass, the changes concern only the main symbol of the Expert Advisor testing. Simply put, we are talking about the symbol on the chart to which the Expert Advisor was attached.

Optimization is carried out on the symbols selected at a particular moment in the «Market Watch» section. Therefore, it is possible to control the optimization by adjusting the set of selected characters.

  • The time it takes to download the required price information from the server can be quite long. However, this happens only in the case of the first launch on a symbol, then only the missing data is resumed.
  • Character-specific optimization means using the current values of the input parameters, which are given in the «Value» column.

Real and generated ticks

In order to correctly set up and test Expert Advisors, use ticks. It is their data that is used by the automatic program. Setting and verification is carried out both on real indicators from the exchange, and on data randomly generated by the strategy analyst based on minute results.

Real ticks

In order to work as efficiently as possible, real-life data (ticks) are used. Because all the conditions are close to real auctions.

Data generated randomly at short intervals, or so-called minute ticks, is considered less effective for optimizing performance, as it is extremely scarce.

Real work on the trading floors shows that everything can change within one minute, following a bearish or bullish trend. Whereas random generation on a minute tick fixes the situation on the trading floor in the corresponding bar.

Moreover, the price is fixed based on exchange indicators, while there is no real purchase. When working with real data, the calculation is based solely on the last completed purchase – last. Although the OnTick event itself is fixed in any case, even if the deal (Last) has not been made.

It must be remembered that the construction of the chart always does not proceed from the Bid and Ask prices (although they are used to make purchases on the trading floor) – the chart is based on the Last price. And as a result, if there is a command at the price (Last), the EA will open a position depending on the bullish or bearish trend, at Bid or Ask prices. Of course, the sale and purchase will be carried out at these prices.

When using the generation mode «All ticks» bars are built at Bid prices, and transactions are made at Bid and Ask. The purchase price is calculated, the best offer for the asset's purchase by other users is taken, and the difference between the bid and ask price, or Spread, is added to this price. As a result, the formula looks like this:

Ask = Bid + Spread (minute bar).

When there is no one-minute bar in the history of transactions, but there is its symbol, the settings will automatically form the price based on the history of the symbol (when the «All ticks» mode is running).

This configuration will help to check the EA even when the broker has incomplete tick data. On the contrary, even the presence of minute bar data without a symbol leads to complete disregard of all tick data, and priority is given to minute data.

Information on ticks – size and so-called weight – much more serious and more minute data. It is for this reason that data analytics (especially when first launched) takes a very long time. Because TCS stores information for several months of trading operations in the directory \bases\[trade server name]\ticks\[symbol name]\.

In order to correctly check the setup of Expert Advisors, the tick data used by the particular Expert Advisor is required. Setup and verification is carried out both on real data from the exchange, and on randomly generated data based on minute data.

Generate ticks

The Strategy Analytical EA generates tick readings based on the home directory of minute records in integer format. Simply put, the program takes readings from the history of transactions on the exchange and, converting to integer format, speeds up its own calculations.

The Strategy Tester contains several different tick generation modes. And the option «All ticks» the most accurate of them.

Different ticks are created depending on the difference in tick volume readings:

Tick volume = 1

When tick readings are equal to one, no ticks are created. And a tick is fixed, equal to the price readings at the close of the transaction:

Optimization of Expert Advisors

Tick Volume = 2

When the situation on the exchange is similar and the bar has readings of only two ticks, the tester operates in a similar mode and does not create new ticks. The program simply fixes the indicators of opening a transaction on the exchange at the starting price Open, and then fixes the completed transaction, marking the price at completion or Close on the exchange.

It looks like this:

Optimization of Expert Advisors

Tick Volume >= 3

The situation changes dramatically for bars with three or more ticks. In these cases, various tick charts are created – depending on their number.

Schemes of bar development

Of course, when there are three or more ticks in a bar, different patterns are created. In particular, the tester generates 4 charts.

In the first case, the initial value on the exchange changed in the direction of a bearish or bullish trend, but recovered at the opening value. As a result, the so-called bar has both the highest price (High) and the lowest price (Low).

This is displayed on the chart as follows:

Optimization of Expert Advisors

In the second case, the opening price of trading on the stock exchange changed upwards (or downwards) and at the end of the day went significantly higher (or lower) than the opening price. Then either   highest or lowest price (on stock exchange slang – High/Low) – depending on the market situation. It must be remembered that the opening and closing prices of trading are not equal.

The following picture will appear on the chart:

Optimization of Expert Advisors

The third scenario: the value on the exchange at the start of trading changed, but at the end of trading has not returned to its original position.

The following situation will appear on the chart:

Optimization of Expert Advisors

The fourth value – the value only grew or, conversely, fell. There were no backward spikes, only a bullish or bearish trend. Then at the end of trading the bar does not have the highest or lowest value (High/Low).

This is shown on the chart like this:

Optimization of Expert Advisors

Generate ticks for bars with three or more ticks

Of course, creating ticks depends on anchor points. Their maximum number – eleven. The Open price is not included in calculating the number of pivot points, since the movement starts from it.

Anchor points are always divided into three main groups:

  • creating an opening shadow;
  • the size of the so-called «candle»;
  • result of closing shadow.

Optimization of Expert Advisors

At the same time, there is a direct dependence on the number of ticks, and it looks like this:

Optimization of Expert Advisors

If a candle does not have any of the shadows, then the anchor points of the corresponding shadow are given to the range of the candle.

When a candle does not have one of the shadows, the size of the candle increases due to the transfer of anchor points. The dimensions of the «candle» are always determined only by an odd number of control points.

Of course, there are cases when an even number of points is involved in the size. This is extremely easy to solve:

  • or point is simply ignored and only the odd one is taken into account:
  • or passed to one of the shadows, but provided that it already has two points.

Ideal Distribution (3-5-3)

There is a so-called ideal distribution of reference points, which depends on the price of the beginning of trading on the exchange. Certain formulas are used to calculate the distribution of points 3-5-3.

Bullish candle:

Optimization of Expert Advisors

Bearish candle:

Optimization of Expert Advisors

Doji Candles

When a «Doji» (Close = Open),  check the previous candle. If it was descending, then the current one should be considered ascending, and vice versa.

Optimization of Expert Advisors

Three-point shadows

There are cases when the shadow is formed on three anchor points, and the values and size of the shadow are equal. This can happen if open and low or open and high differ by no more than 2 points. That is, the price steps forward and backward correspond to each other.

Then the shadow is formed like this:

Bearish candle

Optimization of Expert Advisors

Bullish candle

Optimization of Expert Advisors

The final shadow is formed in the same way.

Two-point shadows

In cases where the shadow is formed from two anchor points, the corresponding generation also occurs.

Bearish candle

Optimization of Expert Advisors

Bullish candle

Optimization of Expert Advisors

The final shadow is formed in the same way.

Candle range

Candle swing is created on cyclical waves.

For example, when Prev is Low, the previous – this is Low, then the following loop is applied:

Optimization of Expert Advisors

When Prev is High, that is, the previous – this is High, then the following loop is applied:

Optimization of Expert Advisors


N1, N2 – these are anchor points in the loop;

Prev – previous course;

Step– step size.

The step is calculated according to the following algorithm: (H — L — 1)/(Number of cycles) + 1.

In this case, the number of cycles is calculated using the following formula: (Number of reference points in the span + 1)/2.

Optimization of Expert Advisors

Intermediate ticks

There are also certain rules for generating intermediate ticks between pivot points:

  • When the number of ticks exceeds the number of pips between pivots, a «saw» is created; (initial score +/-1).
  • When there are a large number of points between pivot points, a linear chain of ticks is created. 

Tick generation methods

The tester's interface has settings that allow selecting the tick generation mode method.

The following options are available here:

«All ticks»

As the name implies, not only OHLCs work, but also «intermediates». The generation method for this case is discussed above.

OHLC on M1

From the title and description of the principles of operation above, it is obvious that  works only with minute OHLC ticks.

The choice of this mode does not mean that testing or optimization will be carried out with a period of M1. Quotes will be formed on each minute bar for Open, High, Low and Close values.

In this case, the OnTick event also needs to be fired four times per minute:

  • on opening;
  • on closing;
  • at the minimum;
  • at the maximum.

In fact, OHLC rates are in historical quotes. That is, during testing, only the arrival time of Open, High, Low and Close ticks is created. And exchange rates are taken from history.

Only opening prices

This mode of operation implies the possibility to check the work of the Expert Advisor without time delays. However, some orders may be triggered not at the declared value.

And there are a number of restrictions here:

  • It is not possible to use the «arbitrary delay» function in this mode.
  • Cannot get data from lower bars.
  • Timeframe limits in this mode of operation also apply to other symbols.

Therefore, the optimal solution would be to use the «All ticks» mode, but this will slow down the EA.

Math calculations

In this mode of operation, all fields become inactive, except for the following:

  • «Optimization Mode»;
  • «Expert's Choice».

However, the genetic algorithm allows completing the search for an extremum very quickly.

Optimization of Expert Advisors in MetaTrader 4

The essence of optimization lies in successive runs of the specific Expert Advisor with different input parameters on the same  data. It is possible to select such parameters that raise the efficiency of the adviser to the highest possible level. The terminal has regular tools, which makes this process automatic.

Before starting the optimization of the characteristics of the Expert Advisor, tuning is performed. It occurs according to the following algorithm:

  • an adviser is selected and its input parameters are set;
  • selecting not only the financial instrument, but also its period;
  • out of three methods used to model bars, one is selected;
  • optionally sets time limits for optimization.

In order to test and optimize Expert Advisors, the terminal has a window designed specifically for this purpose. That's what it's called – «Tester». In it, go to the tab «Settings» to make all the above settings.

EA characteristics

The Expert Advisor whose indicators need to be optimized is located in the field of the «– Tester– Advisors". But not any adviser file can be selected, only the one that is available in the client terminal. To get them there, they must be compiled and saved in the /EXPERTS folder.

Optimization of Expert Advisors

  1. Select the type of program under test;
  2. Select a program for testing - optimization;
  3. Select financial instrument;
  4. Select the type of price emulation;
  5. Enable the use of testing and optimization dates;
  6. Enable visualization mode (Significantly slows down the testing process, does not work for optimization);
  7. Testing speed slider (Does not work for optimization);
  8. Select the start date of testing;
  9. Buttons to pause testing and skip visual mode;
  10. Select the end date of the test;
  11. Choose a date for skipping testing in visual mode;
  12. Select the period;
  13. Select the spread size;
  14. Enable optimization function;
  15. Open the Expert Advisor or indicator settings window;
  16. Open the financial instrument properties window;
  17. Open a chart of a financial instrument;
  18. Open the MetaEditor to access the source code of the program;
  19. Tester settings tab;
  20. Testing and optimization log tab (The terminal writes all errors and program results to this tab);
  21. Indicator testing processes;
  22. Start/Stop the testing process;

After the Expert Advisor is selected, additional settings are made and input parameters are set. This is done by activating the «Expert Properties» button.

Optimization of Expert Advisors

This action opens a new window with three tabs:

  • «Testing».
  • «Input Parameters».
  • «Optimization».

Test Process

This tab is used to set such general optimization characteristics as the volume and currency of the initial deposit. For their placement there are fields with similar names. In addition, this tab is needed to select the type of positions to be opened:

  • Only Long – to open exceptionally long ones.
  • Only Short – only short ones open.
  • Long and Short – positions can be opened in either direction.

Regardless of the EA's algorithm, it will open positions only in the directions that have been selected.

The parameter to be optimized is the metric whose value is used to determine the quality of the input feature set under test. The higher the level of the optimization criterion, the better the test result gets.

List of parameters available for optimization:

  • Balance – the highest balance value.
  • Profit Factor – the highest value of the profit factor.
  • Expected Payoff – the largest value of the mathematical expectation of winning.
  • Maximum Drawdown – the largest drawdown value.
  • Drawdown Percent (%) – the smallest relative drawdown value.
  • Custom – the criterion for choosing this optimization characteristic will be the value inherent in the OnTester() function in the Expert Advisor.

Input Features

A table is also used here to accommodate all input features. Under the term «input characteristics» variables that affect the functionality of the Expert Advisor are implied. In order to change them, it is enough to have a client terminal. However, there is no need to change the expert's code. Variations in the number of input variables from one expert to another are possible.

Optimization of Expert Advisors

To set the input parameters of the Expert Advisor for optimization, the following fields are used:

  • «Start» (starting values).
  • «Step» (change step).
  • «Stop» (finish values).

A tick is placed to the left of the line with the name of the variables, after which the parameter is included in the optimization.

The optimization does not change the value, so the parameter entered in the «Value» field is applied. In direct proportion to these characteristics is the number of runs. There is no dependence of the Expert Advisor optimization on the data entered in the «Values» field, since the need for them arises only when it is tested.

It is possible to load a set of input characteristics that have already been saved («Start», «Step», «Stop » are no exception). To do this, click the «Download» button. and the parameter set that has been previously saved is selected. To save an existing set of external variables, just activate the button with the appropriate name.


Using this tab, it is possible to manage constraints during the optimization process. When any of the set conditions is reached during a particular run, the EA run is interrupted. Optimization continues from the next run.

The inclusion of a limiting condition is performed by the corresponding checkbox to the left of it. Double click with the left mouse button on the field «Value» allows changes to an existing property. To do this, press the «Enter» key. after entering a new value.

Optimization of Expert Advisors

Limiting parameters:

  • Minimum balance – the minimum value of the balance in the deposit currency.
  • Maximum profit – maximum profit in deposit currency.
  • Minimum margin level % – minimum margin level in percent.
  • Maximum drawdown % – maximum drawdown in percent.
  • Continuous loss – maximum total loss in one series. A losing series is a series of consecutive losing trades.
  • Continuous number of losing trades – the maximum number of losing trades in one series.
  • Continuous win – maximum total profit in one series. A series of consecutive profitable trades is called a profitable series.
  • Continuous number of profitable trades – the maximum number of profitable trades in one series.

Financial instrument – what is it

Choosing an Expert Advisor and setting it up properly is not enough to start testing. It is also required to decide on the financial instrument and the timeframe (period) during which testing will be carried out. These data are also used in the testing process, for which it is possible to select one of the tools available in the terminal. It is possible to use external data files.

Optimization of Expert Advisors

The /TESTER directory is used for writing *.FXT historical data files used in testing.  The creation of these files during testing occurs automatically when the tool available in the terminal is selected.

To set a financial instrument, the field «Symbol» is used, and to set timeframes – field «Period». When the fact of the absence of a data file for a specific instrument, modeling technique and period is detected, it is automatically created. If there is no historical data related to the symbol and period, then the tester automatically downloads the 512 final bars of the history.

The presence of any information beyond 512 bars will automatically download historical data up to the last available bar. As a result, there is a high probability of a significant increase in traffic consumption.

Modeling Methods

Historical data in the terminal is saved only as bars, which are records in the form of OHLC. Such data is used if price dynamics is simulated when the Expert Advisor is being optimized. Sometimes the available data is not enough for testing or optimization.

So, for example, daily data on price fluctuations within a bar can act as a reason that provoked the Expert Advisor to work. And this is despite the fact that triggering may not occur during the optimization process. Simply put, if the EA is optimizing based solely on bars alone, then the target may not be accurate. As a result, a false impression is created about how effective an Expert Advisor is with a certain set of parameters.

Using the terminal, it is possible to optimize the Expert Advisor using various methods that allow simulating historical data. In this case, it becomes possible to obtain a more accurate emulation of the dynamics of price changes. When using not very large time periods of historical data, it is possible to get an idea of price fluctuations within bars.

For example, when the Expert Advisor is optimized on hourly data, minute data can become the basis for modeling the dynamics of price changes within a bar. The result of this is an increase in the reliability of the Expert Advisor optimization, which is explained by a significant approximation of historical data to real-life price fluctuations.

During the optimization setup, choose one of the following methods to model historical data.

Including opening prices

It is common for some mechanical trading systems to be independent of intra-bar simulation, as they use mature bars to trade. The full formation of the current price bar is signaled by the appearance of the next one. This simulation mode is designed specifically for them.

Here, first, the simulation of the bar opening occurs (Open = High = Low = Close, Volume=1). Thanks to this, the Expert Advisor is able to accurately identify the end of the formation of the previous price bar. The nascent bar starts testing the Expert Advisor.

A fully formed current bar is displayed in the next step, but it is not used for testing.


Apply breakpoints using fractal interpolation and nearest timeframe. When there is a need for an approximate assessment of experts using the inside of a bar for trading, they resort to a method that allows modeling control points.

For this, the historical data of the nearest smallest period (timeframe) must be available. The available information is often not enough to cover the time range of the tested timeframe. 

In such a situation, to generate the development of a bar, the closing prices of the twelve previous bars are taken. This is the essence of fractal interpolation. With the advent of historical data of a smaller timeframe, fractal interpolation is applied to the indicated data. However, there is no need to use twelve bars, and only six are used.

The real-life prices Open, High, Low, Close are reproduced, as well as two more generated prices. Their location and value depend on how prices move on the six previous bars.

All ticks

All the smallest available periods are used as the basis, with fractal interpolation of each tick.

Using this mode makes it possible to simulate price movements within a bar. Unlike the previous method, in this case, the generation is carried out using not only the data of the nearest smaller timeframe, but also all other available ones.

When any time range has more than one timeframe data, only the smallest timeframe data is run into the generation process. Just like in the previous method, control points are fractally generated.

With the help of fractal interpolation, the price movement between the points selected for control is also generated.

The situation when several ticks are generated in a row is not excluded. Then duplicate quotes are filtered with the subsequent fixing of the volume of the last of them.

The generated tick data can be very large. This may affect the OS resources consumed and the speed of testing.

In any case, there are two additional factors to consider:
  • If there are no smaller timeframes that can completely cover the period under study, it is not recommended to start tick testing, as it may contain inaccuracies.
  • During thorough testing, simulation of all ticks is used, while when optimizing – control point modeling.

Bid prices are stored in the history of price data (client terminal). When modeling Ask prices, the strategy tester by default uses the current spread of the instrument at the time of optimization start. But the  user has the opportunity to set his own spread value for optimization. To do this, he just needs to go to the «Spread» field.

Time Range

The date range makes it possible to test the Expert Advisor not on all available data, but only on the time period that was selected. This creates convenience when a particular piece of historical data needs to be explored. The use of a limited range is possible not only when the Expert Advisor is being tested, but also when the current sequence of bars is being generated.

It is often not necessary to generate the entire history data. To a large extent, this applies to tick-by-tick modeling, in which there are extremely large amounts of unused data. For this reason, the generation of bars outside of the specified range is not performed, if the option of using the date range is enabled when initially generating the test sequence.

They are simply rewritten into the output sequence, with no exclusion of data from the sequence, as this would interfere with the correct calculation of the indicators on the whole received history. However, the first hundred bars are not generated – regardless of the specified date range.

The «Use dates» checkbox is checked to trigger the date restriction. and enter the required values in the fields «From» and «Before». After completing all the settings, the «Start» button is activated, which starts testing.

To determine how long the process will end, just look at the bottom of the window.

It's important to consider:
  • If there is no checkbox next to «Optimization» and the pressed button «Start» not optimization will start, but the testing of the EA.
  • It is possible to use own history files for both optimization and testing.

Optimization of expert advisors presults

After the optimization process is completed, go to the «Optimization Chart» tabs; and «Optimization results» to view the results.

Optimization of Expert Advisors

Optimization differs from testing in that it involves multiple MTS (mechanical trading system) runs. In this case, various input characteristics can be used. The purpose of this action is to determine the characteristics of the adviser, which will allow it to achieve the maximum level of profitability.

To perform optimization, check the box with the same name in the tab for setting up testing and activate the «Start» button. The result of these actions will be the appearance of two new tabs in the window:

  • «Optimization Chart».
  • «Optimization Results».

The second contains reports for each of the runs carried out, while in the «Test Results» a list of all operations is published.

For the convenience of users, all information is displayed in the form of a table, which contains fields with the following names:

  • Pass – number of the current run.
  • Profit – gross profit minus gross losses (net profit).
  • Total transactions – the total number of trading positions that were opened.
  • Profitability – percentage of total profit to total loss. The unit means equality between the amounts of profit and loss.
  • Expected payoff – a statistically calculated indicator that reflects the ratio of the average value of profitability to the unprofitability of a particular transaction. It is believed that this indicator also shows the ratio of the expected profitability to the unprofitability of the subsequent transaction.
  • $ drawdown – the maximum drawdown rate (comparable to the initial deposit in its currency).
  • Draw % – the maximum fixed drawdown (comparable to the initial deposit).
  • Input parameters – reflect how  the characteristics of the input variables were subjected to changes with each run performed.

By clicking with the left mouse button and hovering the cursor over the header of the desired column, the user can sort the data in the table both in ascending and descending order. When a command from the context menu is executed, the data of the selected run is written as the base input variables of the expert. In this case, after going to the «Settings» tab; the optimization mode is disabled.

After activating the «Start» button, EA testing becomes available, using the selected input variables. It is possible to access it by hovering the cursor over the run line (available in the optimization results tab) and double-clicking with the left mouse button. Using the keyboard shortcut Ctrl+C (or the «Copy» command) in the context menu allows copying them to the clipboard (after selecting the result rows). In the future, they can be used in other applications.

The absence of selected rows serves as a command to copy the entire table to the clipboard. This action can also be performed by selecting the «Copy All» command.

In order to save the report to the hard drive, the optimization results must be in HTML format. This is done by using the command from the context menu «Save as report».

List of other commands for customizing the display of results from the context menu:

  • Skip useless results – show or hide the results of the runs that caused the loss.
  • Show input parameters – show or hide the column called «Inputs».
  • Autosize columns – setting the size of the columns automatically when the window is resized. This action is also performed by pressing the A key.
  • Grid – show or hide the grid by which columns are separated. A similar result is obtained after pressing the G key.

Optimization of Expert Advisors

Automatic display of the chart of the profit of each of the runs performed is carried out in the «Optimization chart» tab. With its help, the user can evaluate the profitability of using various combinations of input characteristics.

The lower part is reserved for the chart, which displays the number of trades during each run:

  • if trades are profitable, green color is used;
  • If trades are unprofitable, red color is used.

If double-click with the left mouse button at the selected point on the chart, you will switch to the «Results» tab; and the  corresponding run is selected.

To copy a chart image to the clipboard, use the Ctrl+C key combination (or the «Copy» context menu command), after which it can be used in other applications. In addition, using the keyboard shortcut Ctrl+S (or the «Save as Picture» context menu command), the chart is saved as a GIF file on your hard drive.

Reviews and discussions

To write a comment, log in Enter

Articles of your choice

How to install – update the application in MetaTrader. Simple instruction.
How to install – update Forex and Crypto Expert Advisors.
Detailed instructions for MetaTrader 4 and MetaTrader 5
Step-by-step instruction on how to correctly and error-free install or update a Forex – Crypto Expert Advisor, indicator or script in the MetaTrader terminal. The instruction is described for MetaTrader 4 and MetaTrader 5
17.01.2022 Comments Read Beginner, Lessons, Help, MetaTrader
How to buy an Expert Advisor, indicator or script for MetaTrader
How to buy Forex and Crypto Expert Advisors
Detailed instructions for MetaTrader 4 and MetaTrader 5
Step-by-step instructions on how to buy or rent an application for MetaTrader.
The instructions describe two ways to purchase the application in the MetaTrader terminal and on the website
13.01.2022 Comments Read Beginner, Lessons, Help, MetaTrader
How to test Forex and Crypto Expert Advisors in MetaTrader
How to test Forex and Crypto Expert Advisors
Detailed Instructions for MetaTrader 4 and MetaTrader 5
How to qualitatively test Expert Advisors in MetaTrader for the Forex and Crypto markets, the most detailed instructions with recommendations. The instruction is written for the MetaTrader 4 and MetaTrader 5 terminals, it is step by step with pictures.
06.01.2022 Comments Read Beginner, Lessons, Help, MetaTrader


Password recovery Registration

Password recovery Registration
Password request

If you forgot your password, enter your e-mail. The control line for changing the password will be sent to you by e-mail.

A link has been sent to your email address to confirm the E-mail address. To complete the registration, follow this link.

If you have not received an email to your email, check the Spam folder. If there is no letter there either, then contact us.

Registration completed successfully!

You have successfully logged in to the site!

Feedback Top icon
We use both our own cookies and third-party cookies for the purpose of analysis, as well as to display ads based on your preferences, in accordance with your browsing habits and your profile. For more information, please see our Privacy Policy.