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 on the Internet.
In theory, Expert Advisors should contain an open and repeatedly tested on demonstration trades and in real conditions strategy, and test results are usually attached to the program. It turns out that traders acquire fully automatic, 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 advisor purchased at the first stage of the choice, regardless of the delivered and advertised results.
There are only two ways to check the program for compliance with the trading strategy, for code errors and for real profitability. Any MetaTrader user can check the effectiveness of the program via the strategy tester or run the program on a demo account.
Let's consider both ways of testing in detail.
A custom script 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 of the trader is to make sure that the EA files are in fact intended for MetaTrader 4 by checking the extension (it should be mql4 or ex4). For the sake of providing an example, we will install 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 installation folder via the “File” -> “Open Data Folder”.
After this operation, the folder window will open as usual.
Indicators, Expert Advisors, auxiliary libraries, presets, templates and other files related to the custom configuration of the platform are located in the MQL4 folder. It is enough to open it to immediately find where to copy the Expert Advisor files due to corresponding folder names.
Step four - distribute the Expert Advisor files to the appropriate folders, following the recommendations attached to it or relying on extensions:
In the example, we will copy the VR Smart Grid 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 ticks history downloading. Define the instruments you want to work with and press F2.
Select the desired currency pair or CFD contract in the Quotation archive window, and then click the Download button. The tick history will be downloaded, the 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's servers do not contain new data, a message will appear with a suggestion to recalculate timeframes. Just in case it is better to make the suggested update of tick data.
The downloaded archive of quotations will provide the strategy tester with database for modeling (restoring) candles when recreating the trading history.
The first way to test Expert Advisors - using the Strategy Tester - is faster, but it does not provide accurate results. This is a great option for pre-testing the script.
The strategy tester opens as the bottom window of the Metatrader 4 workspace, allowing the trader to test and optimize trading systems and to keep track of current positions at the same time.
The trader can launch the service at any time through the “View” menu or via combination of shortcuts specified in the “Strategy Tester” option.
The developers tried to make this application intuitive, so a user, even barely familiar with the Metatrader 4 platform, has almost no questions, but some features are quite specific.
The EA 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 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 performance on the test. The side result of his work is parameters tailoring for a specific historical period and instrument loaded into the tester. In real trades, when faced with another form of fluctuations (volatility, laps, etc.), the robot will make a lot of losses.
As already mentioned above, for Expert Advisor's correct operation, 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. If the Expert Advisor is popular, the settings files can be found independently on the Internet.
The VR Smart Grid robot, considered for example, has similar files of custom settings, which after downloading should be placed in the Presets folder. To do this, you need to open the MQL folder in the terminal via the Data Catalog, so that you can place the file with the extension “set” in the Presets directory.
Then, in the strategy tester, you will only have to click the “Upload” option and select desired file in the window that pops up. Often, the Tester folder is opened by default when you select a download, so use Windows navigation to find the Presets folder yourself:
When you open the test service, the default option “Expert Advisor” is set to the left. It automatically displays the entire list of robots in the Experts folder and the Navigator window.
If 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 the effectiveness of the trading system will be checked, 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 data of the archive, 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 trades 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 — 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:
It is much more important to choose a section with the most symmetrical (even) distribution of upward trend, flat and various volatility levels
A segment from 2000 to 10,000 candles or bars of the timeframe — the interval selected in the “Period” menu — is enough
As mentioned above, one of the tasks of testing is to check the “logic” of opening and closing trades, the work of money management — automatic placement of pending orders fixing losses and profit. Thanks to the visualization option, the trader can personally observe these processes in the “high-speed run” mode of trading sessions.
The “Visual mode” option offers the user to choose the inclusion and duration period of the trading demonstration.
Setting the above settings allows you to simply press the start button of the test, 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.1 in the EA input tab. 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 the “Start” button and passes automatically, displaying only the segment selected on the chart above. You can pause (1), accelerate (2), reduce or expand trades by moving the slider (3).
If the “every tick” method is selected, the candles are recreated in the tester and the price produces fluctuations, almost with reliable accuracy, which allows to display trades not at the opening and closing price, but directly “inside” the candle.
After the test is finished, new tabs are added to the service, which were not present at the tester startup stage: Journal, Graph, Results and Report.
Preliminary evaluation of the effectiveness of the trading algorithm is carried out:
The stability of the EA 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 can see an inflated loss at the end of the test, which will be reflected in a sharp drop in the curve of profitability — equity (equity).
The Results tab contains a detailed description of the completed or modified trade transaction, as well as pending 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 trades is contained in the fourth column “Order”. When modifying limit placed orders, it does not change, for example, the yellow 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 a related stop loss order to limit losses in case of an unfavorable price movement.
The trade type is determined by the third column, the operation of the money management unit of the strategy is displayed in S/L and T/P (stop loss, and take profit) numbers. The “Price” column shows the price level of pending or executed orders on the market, “Balance” - the dynamics of the deposit changes.
In the above example of testing the VR Smart Grid Expert Advisor, the trader should pay attention to how the volume increase and the trailing stop is rearranged after the positive change in the in the direction of the open trade and check on the chart whether these operations coincide with the logic of the robot algorithm.
The Graph tab is divided into two fields. The first one contains two lines: balance (blue) and equity (green). The balance changes only when positions are closed, and the 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 on a complex grid strategy using position increment, which is displayed with different height of columns.
“Report” is the most important tab, objectively, by the numbers, determining the results of testing. First of all, you should pay attention to the quality of trading history modeling (1), sometimes it is difficult to achieve 90