One of the main advantages of MetaTrader 4, the leader among similar platforms used by traders for trading on the Forex market, is the ability to program strategies. Any user who has learned the basics of the mql language can code the system by creating an algorithm for signals issuing or for fully automatic trading (algotrading).
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% accuracy, so the EA should be checked on a demo account.
Simulation errors will be displayed by:
The length of the tested period is indicated by the number of candles and timeframe, in this example it is Н1. The line below (2) contains the initial deposit and spread set by the user prior to testing.
Line (3) defines the strategy results in terms of total net profit, gross profit and gross loss, but the following parameters are by far the most important:
The losses and profits in the strategy are posted in line (4):
Other parameters 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 trades 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 robot start, shutdown, etc.), there is only a description of trades.
The log 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 Graph tabs, you can save them for further analysis.
In the drop-down menu one can choose from options of 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 options or settings.
The main goal of testing is express assessment of the Expert Advisor, so on the first tab “Chart” 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 trades
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 automatically fixed profit, the size of which is determined by pending orders — take profit.
The table on the Results tab shows the totals for each positive and negative trade. Studying random sampling will help to understand the logic behind stop loss and take profit size. If the algorithm contains too high losses, their series can “kill the deposit”.
The parameter “continuous loss trades” will give an idea of the possible length of a series of negative trades.
Analyzing the results above, the trader should understand that the task of the tester is the rapid analysis of the robot. Testing proves only the absence of code errors in the Expert Advisor and the existence of a “workable” trading algorithm.
The fluctuation of exchange rates or other instruments of the Forex market is ensured by a continuous flow of customers trades, so-called ticks. This information is stored on the broker servers, to which the Metatrader trading platform is “tied” to. Despite the versatility of the program, each broker independently engages in filling, i.e. collects its own version of quotations.
When you start the tester, each candle (or bar) is emulated — filled with ticks according to the server, it is millions of trades that cannot always be accurately repeated in full. The program will remind it on its own, if the trader chooses this option of testing.
Based on the above, it becomes clear that despite advertising the tester as an ideal tool for determining the profitability of the strategy, the result of real trading will be very different from the received figures. Use the received profit data to set test parameters on a demo account as close as possible to real trading. Only it can accurately determine the real profitability of the Expert Advisor.
Running the EA on a demo account provides the greatest reliability of the test results, but this method requires considerable amount of time. In addition, it is advisable to use a VPS server when testing.
VPS server is a service that has appeared in hosting providers with the development of automated trading. The company provides traders with remote access to the Metatrader platform installed on its own powerful data center servers.
The operation of the Expert Advisor algorithm depends on a continuous Internet connection, by which the robot manages the placed pending and triggered orders, according to the the logic of the trading strategy.
Disconnection or shutdown of the Metatrader 4 terminal leads to a failure, the user will have to close open and cancel pending trades, after its restart. If at this moment the trader is not near the computer, the trades will remain “hanging” on the broker's server and can cause unlimited loss.
VPS server is used to allow trading to take place automatically without the risk of any failures. Stability of operation is guaranteed by:
The latter fact gives an additional advantage to the user of VPS server, increasing the speed of execution of orders due to smaller ping size and faster changes in quotations.
The hosting provides full technical and consulting support as well as assistance in setting up VPS server, so the service can be used with any level of knowledge.
Forex brokers provide traders with a choice of different types of accounts designed to optimize fees. These conditions are fully duplicated in the demo accounts.
Testing the Expert Advisor on a demo account should not differ from real trades, so the deposit type and amount must match the real Forex trading account which you plan to use advisor on. This question should be solved by the trader independently before the first start of the robot, based on the algorithm of the trading strategy, or it can be taken into account in the instructions/recommendations attached to the Expert Advisor.
Sometimes they pursue advertising purposes for affiliate earnings - developers recommend a specific broker even, so we will give a brief overview of the main types of accounts.
In the Forex market brokers offer 4 different options for payment of fees:
Swap is a daily charge/withdrawals of a leverage fee. It is calculated as the difference in the rates of the central banks of the countries that own both currencies in the pair. Broker, like any bank, withdraws interest for the loan on the sold currency, at the same time paying interest on the purchased currency.
For example, selling EUR/USD looks like buying dollars for euros sold. The European Central Bank holds almost zero rate, so interest for the use of the euro will be zero, and on the amount of purchased US dollars fee will be charged for each day at the rate of 2.5% annual. This is rather low income or loss, so “Islamic or “swap-free” accounts do not play a significant role in choosing the demo mode of the Expert Advisor testing.
A cent account is opened by traders trading for an investment amount not exceeding $100, which Metatrader 4 will present as 10000 cents. This “cent transformation” of the deposit is necessary when trading vis Expert Advisors by a grid strategy (placing multiple orders against the trend) or Martingale (increasing the order size after every loss-making transaction). To run it on any standard account you will need a deposit of $1000, in the “cent version” $100 will suffice.
Fixed spread accounts are selected by traders who launch robots once, twice a day or rarer. The average profit from the transaction makes the fee negligible, and the calculation of expenses is simple, it is enough to multiply the spread by the number of trades
Intraday, short-term or scalper strategies with a large number of trades per session use floating spread accounts. They are presented under many abbreviations: ECN, NDD, STP or DMA. The name determines the method of execution of the trade and the mechanism of spread formation, the subtleties of which are described in the accompanying specifications of the account.
If a trader does not understand dealing desks, glasses, rules of market execution of orders, he should not use a scalper robot, which in the absence of knowledge of intricacies of intraday trading will kill the deposit in one day.
The amount is determined by the results of testing in the strategy tester. The first part of the description defines the tactics of launching the Expert Advisor with a fixed trade size of 0.1 lots. This selection allows you to equate the maximum drawdown parameter from the “Report” tab with the currency pair exchange rate points.
In the example of VR Smart Grid testing the result was 155.38, which means that the robot must “withstand” the loss:
The trader can read how to correctly account for losses from a mathematically justified point of view in Ralph Vince books, but the easier way to determine the size of the deposit is to multiply the number of maximum drawdown on the maximum series of loss-making trades and then apply the coefficient of 3.
In our example you will get the following deposit amount:
15,4 x for maximum consecutive loss series (4) x 3 = 186,45
This means that when testing the VR Smart Grid Expert Advisor, the amount of deposit on the demo account should be:
The coefficient is chosen empirically and means the triple maximum margin, so the higher it is, the more stable is the strategy.
Often trading algorithms are written for specific Forex instruments, this fact is highlighted in the settings or recommendations to the Expert Advisor. If the strategy is universal, the robot testing on the demo account should be based on:
The Metatrader 4 platform allows you to run as many copies of the Expert Advisor as many instruments the broker offers. A large number of instruments in theory diversifies the strategy, compensating the loss on one pair with profit from the other.
In practice, all movements in the Forex market are subject to the laws of correlation — falling and growth of currency pairs coincide, especially in moments of global macroeconomic events. Therefore, choosing a large number of instruments only multiplies the load on the deposit instead of the diversification expected.
Before increasing the number of currency pairs, the trader will have to return to the strategy tester again and determine the maximum loss for each pair in order to take it into account when testing the Expert Advisor on the demo account. The trader will have to increase the amount of investments or decrease the volume by allocating a trading deposit separately for each currency pair, calculating the reserve according to the formula described above.
Tthe situation of running the Expert Advisor on medium- and long-term strategies, provided that different classes of instruments are selected, can be an exception: currency pairs, indices, commodities and raw materials. If the run on the strategy tester shows the frequency mismatch of trades on the selected instruments on the “Visualizations” or “Results” tab, the trader can calculate one deposit for all instruments. by selecting the average drawdown size and using the coefficient of 5 (instead of 3) to calculate the deposit size.
If the user is faced with the task of finding the most profitable currency pair for the Expert Advisor during testing on a demo account, then he can run many instruments using larger size of the deposit than is planned for real trading. However, this process will lengthen the tests on the demo account - a second stage will be required, where only the selected pair will be tested separately, with the planned deposit.
The timeframe size — the time period represented on the chart by a candlestick or bar determines the “accuracy” of the EA trades, so this parameter is initially set up by default or is reflected in the recommendations.
Some strategies implemented in robots have scalability, i.e., the trading algorithm can work on different time periods. Before testing the Expert Advisor in Metatrader 4, the user must determine what period he will use in real trades and choose the same in the demo account settings.
The size of timeframes is standard: 1,5, 15, 30 minutes; 1 or 4 hours; higher intervals: day, week, month.
The choice of lower, minute, periods assumes a higher frequency of trades, often used to “overclock” the deposit. If the trader does not have large funds and sets the goal of “fast earnings” in the market, he will choose minute intervals. This will mean intraday trading, where the following restrictions must be used:
The choice of an hour timeframe is a medium-term strategy, the daily one is considered long-term, candles per week or month are seldom selected by traders.
The fluctuations in the Forex market have a fractal structure, which means the similarity of cyclicity and pattern shape within one hour and within day or week. This knowledge allows the trader to deliberately choose a shorter period to speed up the Expert Advisor test on a demo account. Profitability on small timeframes means that the strategy will definitely “pass” on higher periods.
When changing timeframes, the trader should take into account the interconnectedness of their size with the EA settings. Inside the robot, a trading system can be programmed, whose periods are synchronized with calendar data, the dimensions of automatically constructed levels are “tied” to certain percentage changes in exchange rate, etc.
In order for the strategy to work effectively on custom timeframe settings other than those set by the developer, the trader should understand the mechanism of placing trades, understand the composition of indicators or other principles used for the formation of trading signals by the robot. This will help you to select and synchronize the Expert Advisor parameters when any changes are made to one or more settings blocks.
First of all, the developer's variants are tested on the demo account.
The ability to change parameters independently is limited by the Input Parameters tab. Coders - the creators of the robot - bring in this window only those settings that a trader can change without the risk of “destroying” the algorithm efficiency.
If a trader is not familiar with the implemented trading strategy, he can find its analogues in specialized forums. If there is convincing evidence about the operability of certain parameters included in the Indicator Expert Advisor, they can be changed in the robot settings.
The EA is added to the chart of the instrument by simple dragging from the Navigator window.
Attachment will automatically open the EA settings. Most of them are accepted by trader by default or modified according to the instructions attached to the robot. Adjustment of the strategy should be carried out using only ideas of the trading system proven in the tester, as well as on demonstration and real trading in Metatrader 4.
After installing the Expert Advisor on the chart, the trader should pay attention to the emoji appearance in the upper right corner - a smile means successful start the robot. Sad emoji indicates problems with settings.
Metatrader 4 platform for working with Expert Advisors requires the inclusion of additional options. They are located in the Tools -> Settings menu and are installed once, then are apllied for any new robot.
In the window that opens, find the “Expert Advisors” tab and select (enable) all items by clicking on them with the left mouse button.
Click the “OK” key and go to the “Properties” setting of the robot, they are available by right-clicking the indicator on the chart, in the drop-down menu of the “Expert Advisors” option.
Allow the EA to trade by initializing the option with the appropriate name and pressing “OK”.
The rest of this settings window is used “by default” unless otherwise provided by the instructions that come with the robot. In this case, the trader can connect libraries, limit trade in one way, etc.
Testing process on the demo account should give the trader understanding of what performance the robot will show in any “state” of the Forex market, especially in “vulnerable” areas for any trading system. These include:
Test data, which includes only continuous growth or decline, for trend strategies are unrepresentative, as robots incur losses on flat. In this case, the trader must initially visually determine the average length of this type of oscillations using historical quotes and wait for the same period on demo account.
Trading in the range is mainly conducted at the Asian session, which involves the least number of Forex traders, which guarantees no trends. The situation changes drastically with the release of important unpredictable news in China or Japan, fluctuations caused by other publications can be avoided by predicting them in advance thanks to information from the economic calendar.
In this case, the number of news cannot be predicted accurately, so the trader should rely on the empirically calculated average result. Evaluate losses from unpredictable movements will help the results of trading during the release of important economic indicators, which the trader avoids at real trades. The time of their publication is known beforehand, and the number of sessions to test the Expert Advisor should be equal to the average result of the appearance of “unexpected” news.
Impulse trading is placing pending orders at important price levels in anticipation of strong exchange rate changes in a short period. They can be “provoked” by news or predicted by technical analysis methods. During testing of an Expert Advisor for impulse trading, the trader needs to wait for a symmetrical number of buy and sell trades (breakthrough of the “down and up” level).
Forex demo account is a 99.9% guarantee of creating conditions similar to real trading, which allows you to rely on the result shown by the Expert Advisor. The trader chooses the account type, deposit size, timeframe and can predict the profit and loss of future investments in the selected robot.
The only downside of this type of testing is the duration, the EA must pass multiple stages of trading, and the trader wait for the trend, the volatility jump on the news and other Forex market states on which the size of the greatest possible loss depends, as well as to trade a "calm" period equal to these periods afterwards. This helps to understand the rate of recovery of the deposit after a series of negative trades and correctly determine the size of the trading lot and the reserve of the investment.
Testing is an obligatory part of the adoption process of any new trading system, especially important when you intend to automate trading. During the analysis, the trader will get a visual idea of the mechanism of opening and closing positions, the theoretical scale of loss, the share of profitable trades.
At the same time, the strategy tester is not a reliable indicator of the Expert Advisor's performance for a number of reasons mentioned above. Reliable data will give real trades, which at the first stage need to be replaced by the period of operation of the robot on the demo account, in order to prevent loss of deposit.
The tested strategy should be put in the market using Metatrader installed on a VPS service for reliable round-the-clock Internet provision and protection against technical failures in power networks or on broker servers.
The indicator visually on the chart, for the current period, predicts the levels of growth and decline in prices based...
The VR System strategy has proven itself to be simple, reliable and efficient...
Adviser for linking (Linker) open charts in MetaTrader terminal. The program has its own Market Watch which changes the...