The best test of a trading Expert Advisor is to launch in the conditions as close as possible to real ones. You can get the most qualitative results of testing a trading Expert Advisor by launching testing on training and demo accounts.
Testing is the running an Expert Advisor or indicator on historical data with a pre-installed set of settings. Testing is carried out in order to detect errors in the code of an Expert Advisor or indicator or errors in the trading strategy. The test can be launched in visualization mode, which allows you to see all trading actions and indicator signals right on the chart. Such testing is much slower than with disabled visualization. The visualization building process heavily loads the computing powers of the computer to render all the data. Therefore, you need to clearly understand what goal you are pursuing when testing.
Testing the Expert Advisor or indicator allows the trader to evaluate the program work on historical data. The main criteria for evaluating a trading Expert Advisor or indicator:
There are only two ways to check the program for compliance with the trading strategy, for the code errors and for real profitability. Any user of the MetaTrader 4 terminal can check the program trading strategy in the strategy tester or by running the program on a trading demo account.
Testing Expert Advisors in the MetaTrader 5 terminal differs from testing in the MetaTrader 4 terminal, we will consider both strategy testers in this instructions. A word of tip-recommendation if you are still choosing which terminal to work with or are already using MetaTrader 4, make a choice in favor of the MetaTrader 5 terminal. The support for the MetaTrader 4 terminal has officially ended, the development of the MetaTrader 4 terminal has been completely stopped.
Written and compiled scripts, so-called Expert Advisors, can be run on any MetaTrader 4 terminal. This factor has created a whole market of user programs distributed both free of charge and on various terms of a one-time payment or subscription. Today, you can find more than one hundred thousand such programs for all tastes on the Internet.
In theory, Expert Advisors should contain an open strategy repeatedly tested on demo trades and in real conditions, and the test results are usually attached to the program. It turns out that traders acquire fully automated, already tested algorithms.
In practice, this is not always the case, and since robots get access to a real deposit, it is very important to make a rapid assessment of the Expert Advisor purchased at the first stage of the choice, regardless of the attached and advertised results.
A custom Expert Advisor with a coded strategy for MetaTrader 4 is a mql4 or ex4 file. The trader should ensure the correct path when installing an Expert Advisor, so that it can be found and run on the MetaTrader 4 platform without problems.
The installation looks like an ordinary file copying, but there is one important feature – the folder for placing the Expert Advisor files is opened via the running trading terminal.
The first step for the trader – that the EA files are in fact intended for MetaTrader 4 by checking the extension (it should be mql4 or ex4). As an example, we consider the installation of the VR Smart Grid robot, which consists of a single file.
The second step is the MetaTrader 4 launch
The third step– is to open the Expert Advisor files installation folder via the terminal menu «File » and the option «Open Data Directory». After this operation, the folder window will open. as usual.
Indicators, Expert Advisors, scripts, auxiliary libraries, templates and many other things related to the custom configuration of the platform are located in the MQL4 folder. It is enough to open it to immediately find out where to copy the Expert Advisor files due to the authentic folder name.
Step four – – distribute the Expert Advisor files with the distribution and settings to the corresponding folders, following the recommendations attached to it or focusing on extensions:
In the example, we will copy the VR Smart Grid forex Expert Advisor file to the Experts folder.
If the Expert Advisor is installed correctly, its name will appear in the «Navigator», after MetaTrader 4 restart. The final stage before testing is to download ticks history. Define the instruments you want to work with and press F2.
Select the desired financial instrument in the quotation archive window and then click the «Download» button. The tick history will be downloaded, the process progress will be marked by the green bar at the bottom of the «Quotation Archive» window.
If the history is already loaded into the Metatrader 4 terminal and the broker servers do not contain new data, a message will appear with a suggestion to recalculate (reload) timeframes. Just in case, it is better to use the suggested update of tick data.
The downloaded quotation archive will provide the strategy tester with database for modeling (restoring) candles when recreating the trading history. The downloaded quotations in most cases do not have a complete set of data, very often there are data gaps, which leads to a low quality of Expert Advisor testing.
IMPORTANT! Part of the trading account properties are copied from the account to which the terminal is currently connected. Testing on different types of accounts will be very different. Properties that are copied (Leverage, minimum and maximum lot limits, number of decimal places, number of simultaneously allowed positions, total volume of open positions, etc.)
The strategy tester opens as the bottom window of the Metatrader 4 workspace, allowing the trader to test/optimize trading systems and «to be in the market» by tracking current positions at the same time.
The trader can launch the service at any time through the «View» platform menu or via combination of shortcuts specified in the «Strategy Tester» option.
The developers tried to make this application native, so a user, even barely familiar with the Metatrader 4 platform, has almost no questions about the interface, but some functions are quite specific.
The Expert Advisor properties are located in the right corner of the strategy tester field and control the direct setting of test modes divided into three tabs:
Never optimize during the initial run of the Expert Advisor! Performance test of any trading system should not be started with an attempt to «adjust» the parameters of the indicators and conditions included in it.
The optimization system uses a «genetic algorithm» that can effectively improve the test performance. The side result of his work is – to adjust parameters for a specific historical period and instrument loaded into the tester. In real trades, when faced with another form of fluctuations (volatility, gaps, etc.), the robot will make a lot of losses.
As already mentioned above, for Expert Advisor's correct operation during testing, you should follow the settings recommended or set by default by the developer of the trading system.
In some cases, changes are possible within «presets», special files attached to the robot with descriptions of cases or instruments for their use. If the Expert Advisor is popular, then the settings files can be found independently on the Internet.
The VR Smart Grid robot used as an example just has similar custom settings files. The settings files can be placed anywhere on your computer.
Then, in the strategy tester, the user will only have to click the “Upload” option and select the desired file in the window that pops up. Often, by default, the «Tester» folder is opened by default when you select a download, so use the Windows navigation to find the settings file yourself.
When you open the testing service, the «Expert Advisor» option is set by default to the left. It automatically displays the entire list of robots in the Experts folder and the «Navigator» window.
When you select the second option – the indicator, a list of files in the Indicators folder will be displayed.
To run the Expert Advisor test, double-click on its name in the drop-down list. Next, the instrument, according to the quotes of which a one-time test will be carried out, is selected in the same way; one click is enough to display it in the settings window.
The «Model» function determines the accuracy and duration of testing, the «every tick» method restores historical quotes using all the archive data, so it is the longest, the other two types do not provide an accurate estimate and are used by developers at the stage of testing «trading hypotheses» to save time while searching for ideas.
In some cases, when the logic of the robot is «tied» to a long-term strategy, where transactions are opened at the price of opening a candle (bar) at the beginning of the day, you can resort to a model with the appropriate name – this will allow the trader to «rush» the Expert Advisor through the maximum time period.
The duration and accuracy of the test is affected by the date or length of the historical segment. Some traders believe that the bigger it is the better, but empirical experience proves that:
As mentioned above, one of the testing tasks is to check the «logic» of opening and closing transactions, the work of money management – – automatic placement of pending orders, fixing losses and profits. Thanks to the visualization option, the trader can personally observe these processes in the «high-speed run» mode of trading sessions.
The «Visualization» option offers the user to choose the inclusion and duration period of the trading demonstration.
Setting the above settings allows you to press the «Start» button of the test, many do this, leaving out the «Spread» parameter, where the default value is «Current». This can lead to unreliable results for two reasons:
Sometimes traders input the spread cost manually, higher by one point of its real value, in order to somehow take into account the losses described above.
After choosing the method of modeling the trading history and the length of visualization segment, set a fixed lot size equal to 0.01 in the Expert Advisor input parameters. This will help to display the dimension of the test report indicators in points, which will make the analysis of test results convenient.
Testing starts by clicking the «Start» option and passes automatically, displaying only the segment selected on the visualization on the upper chart of the instrument. While monitoring transactions, you can pause (1), accelerate (2), reduce or expand by moving the slider (3).
If the «every tick» method is selected, then the candles are recreated in the tester and the price produced fluctuations, almost with reliable accuracy, which allows to display transactions not at the opening and closing price, but directly «inside» candle.
After the test is finished, new tabs are added to the service, which were not present at the tester launch stage: “Journal”, “Chart”, “Results” and “Report”.
Preliminary assessment of the effectiveness of the trading algorithm is carried out:
The stability of the Expert Advisor code is determined by the tester log.
At the final stage of testing in the Metatrader 4 strategy tester, the service performs a “trading breakout” i.e., forced closing of orders with an actual loss or profit. While testing medium-term, long-term strategies or Expert Advisors practicing order grids, as in the case of VR Smart Grid under consideration, the trader may see an overstated loss at the end of the test, which will be reflected in a sharp drop in the curve of profitability – equity.
The «Results» tab contains a detailed description of the completed or modified trade transaction, as well as pending (limit) orders and trading results.
All actions of the Expert Advisor's automatic strategy have a sequential numbering, which is contained in the first column for easy navigation when searching for work failures, as well as the time of operation, located in the second column.
Numbering of transactions is contained in the fourth column «Order». When modifying limit placed orders, it does not change, for example, the marker marks the placing of the second limit order for sale, so the column contains the number 2. It is repeated in the following line: due to the change of the previous Sell order, the robot added to it a related stop loss order to limit losses in case of unfavorable price movement.
The transaction type is determined by the second column, the operation of the money management unit of the strategy is displayed in S/L and T/P numbers, stop loss insuring against losses and take profit, fixing profit. The «Price» column shows the price level of pending or executed orders on the market, Profit» – closed transaction result, «Balance» – the dynamics of deposit changes.
In the above example of testing the VR Smart Grid Expert Advisor, the trader should pay attention to how the lot increase and the trailing stop is rearranged after the positive change in the direction of the open transaction and check on the chart whether these operations coincide with the logic of the robot algorithm.
The “Chart” tab is divided into two fields. The first one contains two lines: balance (blue) and current funds (green). The balance changes only when positions are closed, and current funds change depending on the current values of accumulated profit or loss, which explains the mismatch of these curves. The second window, located at the bottom, displays a histogram of position size, it will be constant for a strategy using a fixed lot opened by trading signal of the robot. In this example, VR Smart Grid Expert Advisor works according to a complex grid strategy using position increment, which is displayed with different heights of columns.
“Report” – is the most important tab, as it determines the testing results objectively, by the numbers. First of all, you should pay attention to the quality of trading history modeling (1), sometimes it is difficult to achieve 90 percent accuracy, so the Expert Advisor should be checked on a demo account.
Modeling errors will be displayed by:
The length of the tested period is indicated by the number of candles and «working timeframe, in this example it is Н1. The line (2) contains the data of the initial deposit and spread set by the user prior to testing.
The line (3) defines the strategy benefit in terms of profit, net and gross profit, even gross loss play a relative role, the following parameters are much more important:
The losses and profits in the strategy are posted in line (4):
Other parameters –, the absolute numbers of profitable and losing positions are not as important as:
The rest of the report is a kind of «collection of records» for the biggest test losses and profits, where you should pay attention to the maximum series of continuous transactions, closed in the negative.
The journal– is a statistical step by step report on the work of the Expert Advisor. Unlike terminal logs, it does not contain service messages (information about the robot start, shutdown, etc.), there is only a description of transactions.
The journal will definitely display code errors if any are found. If this happens, you need to contact the developer or download the Expert Advisor elsewhere.
By right-clicking on the “Report”, “Results” and “Chart” tabs, you can save them for further analysis. The drop-down menu provides a choice of options for copying or saving to a file, the path to which the trader chooses independently or agrees with the default option. Copies are needed to compare with other test options for which you will need to select other parameters or settings.
The main goal of testing– is express check of the Expert Advisor, so on the first “Chart” tab the trader should observe the growing equity line. At the same time, the stability of earnings is guaranteed by indirect indicators:
On the “Report” tab, first of all, we pay attention to the number and percentage of profitable transactions
A large number of positively closed orders can result in a loss if the trader “forgets” about such parameter as profitability:
This figure can be achieved by controlling the size of stop losses – orders limiting loss, relative to the automatically fixed profit, the size of which is determined by pending orders – take profits.
The table on the “Results” tab shows the totals for each positive and negative trade. Studying random sample will help to understand the systemacity of the stop loss and take profit size. If the algorithm contains too high losses, their series can “kill the deposit ”.
The parameter “consecutive losing transactions” will give an idea of the possible length of a series of negative transactions.
Analyzing the results above, the trader should understand that the task of the tester is the rapid analysis of the robot work. Testing proves only the absence of code errors in the Expert Advisor and the existence of a “workable” trading algorithm.
The MetaTrader 5 Terminal is an advanced platform for trading any financial instrument. The terminal allows you to trade any financial instrument, Forex, Crypto, CFD, Option, Futures. If you do not trade in the MetaTrader 5 terminal yet, we recommend that you do it as soon as possible. Also note that the MetaTrader 5 terminal works only in 64-bit operating systems. Terminals working in 32-bit systems are no longer supported or updated.
IMPORTANT! Expert Advisors, indicators, scripts made for terminals of version older than 2361 cannot work in terminals of version 2361 or lower. If you use MetaTrader 5 of version 2361, we strongly recommend to install the 64-bit version of the terminal, you may need to install the 64-bit operating system windows.
Launch the MetaTrader 5 terminal in which you plan to test the Expert Advisor. The installation of the Expert Advisor in the terminal is done in the same way as in the MetaTrader 4 terminal. After launching the terminal, you can call up the strategy tester in two ways.
The additional "Strategy Tester" window will open, these are preset test and optimization modes, selecting any of the modes in the subsequent settings, it remains possible to reconfigure everything to any of the presented modes.
Under the item (1) in the strategy tester window, there is the test mode with visualization. Despite the fact that the mode is called "Visualization" in the following settings, visualization can be disabled or enabled. The field (2) is intended for searching the results of previous tests. The list of previous tests and their results can be reviewed under item (3).
The strategy tester settings consist of 20 items.
(1) "Settings" tab – Is located in the tab bar and allows you to switch between other tabs.
(2) "Expert Advisor" Drop-down list – in this testing, you can select the Expert Advisor under test.
(3) "IDE" Button for calling the code editor – if the Expert Advisor under test has a source code file, you can open this source code by clicking on the IDE button
(4) Button for loading the settings file – by clicking on this button, you can load the previously saved settings file and test with the settings from the file.
(5) "Symbol" Drop-down list – in this setting, you can select the financial instrument on which testing will be carried out.
(6) "Period" Drop-down list – allows you to select the "Chart period" for testing.
(7) "$" Button for additional settings – allows you to make changes to the properties of a financial instrument, by default, the properties of the financial instrument are filled with values from the broker and these properties are used for real trade. If necessary, you can change the properties manually.
(8) "Interval" – Drop-down list – allows you to select a preset time interval for testing.
(11) "Forward" – Drop-down list – allows to set a period that is not involved in the optimization process, and the found set of settings is checked on it. Simply put - the terminal tester selects settings in one part of the history, and checks their work in another.
Forward - this setting allows you to check the test results, it will be useful for excluding situations of adjusting settings on history. The selected test period (9)-(10) is divided into parts (half, third, quarter). To specify your own start date for forward testing, you need to select the "Custom" item in the setting (11). And specify the start date for the Forward test in the field (12). The selection of settings is carried out in the first part of testing and called the back test, forward testing is carried out in the second part.
(13) " Delays" Drop-down list – allows the user to set delays for the process of opening positions, this delay is called "Requte" requote in real trading. Due to price changes, there is often a situation when a lot of time passes from the moment of the first attempt to open a position and the price has time to change. When trying to open a position at the old price, the broker server will return a "Requte" failure.
(14) Button – allows you to set additional parameters for changing the properties of the trading account, commission, margin, limits, etc.
(15) "Modeling" Drop-down list – allows you to select the mode for ticks modeling and price steps.
Best testing quality "Every tick based on real ticks" does not guarantee the same results as if it were on a training or real account.
"Every tick based on real ticks" is the maximum available quality, not a guarantee of 100% reproduction of price data movement.
(16) "Profit in pips"– if this option is enabled during testing, all profits will be calculated in pips, profit and loss calculations will not be made. This mode is not recommended for Expert Advisors with increased trading lots, since in such EAs, 5 pips of profit can cover 50 pips of losses.
(17) "Initial deposit" – allows you to set the deposit sum for testing.
(18) "Test currency" – allows you to set the deposit currency.
(19) "Leverage" – allows you to set the leverage size.
(20) "Optimization" – Drop-down list – allows you to enable the tester into the "Optimization" mode
(21) "Visual mode" – New window – if this option is enabled, the strategy tester will open an additional window in which you can visually see all trading operations made. Enabling this mode greatly slows down the testing process.
After you have set up the trading environment for the strategy tester, you can move to the settings of the EA itself. To do this, go to the "Parameters" tab.
The "Values" column is marked with a red rectangle, this is where you can set the desired settings for a single test. The list of settings, their values depend on the Expert Advisor and will change for each Expert Advisor. After you have set the settings for the Expert Advisor for testing and set up the test environment, you can press the green "Start" button.
After clicking the "Start" button, the strategy tester window will open with a quick run of the Expert Advisor on historical data. If you have installed Forward testing. Then, having reached the specified date, the strategy tester will launch the second tester window to visualize the Forward test. After testing, a chart with the test results will open in the main window of the MetaTrader 5 terminal, each transaction will be displayed on the chart. The launch of the first testing may be delayed, as the terminal may need to download the history of the financial instrument.
The testing window is a bit like the MetaTrader 5 terminal window, but it has fewer buttons. There are buttons to change the chart type, to zoom in and out of the chart, and to control the test speed at the top of the window. In the case when you need to skip a part of the visualization, you can specify the date until which you want to skip the visualization and press the "Scroll to" button.
The bottom of the window contains tabs:
"Trade" – the tab displays the current open orders and positions.
"History" – the tab displays the trading history of the Expert Advisor, you can view transactions, orders and transactions + orders via the context menu.
"Operations" – the tab displays trading operations made by the Expert Advisor, opening and closing positions of their modification.
"Journal" – Displays records and, with the test, writes everything that the trading Expert Advisor does, all trading conditions and errors of the Expert Advisor work are also written in this tab.
The chart of the balance and equity curve is plotted in the MetaTrader 5 terminal window.
The test report can be saved as a web page or table file.
The test report in MetaTrader 5 is much larger and more extensive than in MetaTrader 4. The trader can see the simple test reports and the forward test report.
If during testing/optimization there are withdrawals in the Expert Advisor, then the drawdown indicators are calculated taking them into account. The drawdown indicators calculated before the withdrawal is stored by the program. At the moment of withdrawal, their calculation will be restarted from the current value of the balance and funds. If the obtained drawdown values exceed the previously stored ones, they, in turn, will be stored by the program. Thus, the final test report will reflect the maximum drawdown values.
The grossest error of the trader is the attitude to the test results as the desired results of trading on a real account. Even testing and optimizing the EA on real ticks will not show the results that will be obtained when testing the EA on a demo account. Testing carried out in conditions as close as possible to real ones will be of the highest quality and honest. You can open a training account with our partners for quality testing.