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.
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.
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:
After selecting one of the tasks on the start page, the user must fine-tune the testing parameters:
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.
First of all, the context menu of the required Expert Advisor is selected and the «Test» command is executed.
As a result, the Expert Advisor will be selected in the strategy tester.
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.
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.
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:
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.
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:
The user has the opportunity to set his own trading account settings in the process of testing the following strategies:
Thanks to this opportunity, a trader simulates a variety of trading conditions with stock brokers.
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.
This field specifies how the current unrecorded profit/loss in the free margin will be taken into account:
This field indicates how the profit/loss fixed by the trader during the trading day will be taken into account in the free margin:
This section is intended to give the user control over the procedure for charging a commission on each of the trades:
When the «Use your own commission settings» option is enabled, commission settings for the current trading account become available.
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:
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.
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.
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.
View detailed results for each individual pass is available on the Optimization tab. Here it is possible to see the general results of testing:
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.
Indicators displayed for each individual optimization pass:
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:
For ease of visual analysis of passes, it is common to color the optimization results in the following colors:
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.
Here:
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:
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:
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.
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.
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.
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.
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.
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:
Control the 3D chart using the keyboard:
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:
In the «Use date» field, it is necessary to separate the selected part from the selected period:
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:
And they are tested on the forward period.
Lower limit set for number of forward test runs:
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.
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:
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.
What to watch out for:
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.
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.
To install from scratch, after downloading the MetaTrader 5 Strategy Tester Agent application, it is needed to follow a simple instruction:
When the installation process is complete, they can be used from any computer connected to the local network.
After opening the strategy tester, go to the «Agents» tab, where the «Local Network Farm» item is selected; and click the «Add» button.
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.
After clicking the «Done» button it will be possible to test all found agents.
There are a few more options to add agents:
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.
To change an agent's settings, the command «Edit» is activated in its context menu.
The settings window contains the following fields:
Local agents can only be enabled or disabled.
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:
Line breaks are used to separate the settings of different agents.
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.
When working with MQL5 Cloud Network, the following points should be taken into account:
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 cloud.mql5.com website. To display the value of the current balance of the MQL5.community account, a place has been allocated above the list of cloud agents.
Using the MQL5 Cloud Network is possible if your MQL5.community 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.
To enable network agents, go to the context menu and activate the «Enable» command. If there is no information about having an account on MQL5.community, the user will be prompted to enter it.
If haven't registered before, follow the link www.mql5.com to create a new account.
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.
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.
There are two optimization modes available in the strategy tester. To make a choice between them, go to the «Settings» tab.
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.
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:
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.
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:
Testing ends if there is no improvement for the agreed number of generations.
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.
An access to the following optimization criteria:
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:
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:
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.
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.
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.
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.
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:
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:
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.
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:
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:
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:
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:
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:
At the same time, there is a direct dependence on the number of ticks, and it looks like this:
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:
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:
Bearish candle:
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.
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
Bullish candle
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
Bullish candle
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:
When Prev is High, that is, the previous – this is High, then the following loop is applied:
Where:
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.
There are also certain rules for generating intermediate ticks between pivot points:
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:
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:
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:
However, the genetic algorithm allows completing the search for an extremum very quickly.
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:
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.
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.
After the Expert Advisor is selected, additional settings are made and input parameters are set. This is done by activating the «Expert Properties» button.
This action opens a new window with three tabs:
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:
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:
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.
To set the input parameters of the Expert Advisor for optimization, the following fields are used:
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.
Limiting parameters:
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.
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.
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.
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 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.
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.
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.
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 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:
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:
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:
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 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.