What is forex optimization. How to teach an advisor to trade profitably in the Forex market? Step-by-step algorithm for optimizing a trading expert
We do optimizations several times a month - as needed. You can also perform additional optimization of the settings yourself much more often if you are not satisfied with the recommended settings or if you want to achieve a more comfortable Forex advisor (trading robot) for you, or if you want to try it with another built-in indicator, on a new time interval or on a new trading instrument.
Trading systems "Robots Forex" are a professional tool for working in the Forex market and commodity exchanges... Our robots have many parameters and settings, several indicators and additional opportunities, all of which we do not even use, because it is simply physically impossible to cover the entire range of implementations of these opportunities by several optimizer traders.
However, each robot owner can personally make any number of optimizations in order to achieve optimal trading parameters in a given time period, or for a small quick additional optimization of parameters for this situation on the market.
Preparation for optimization
Firstly, all optimizations need to be done on a fairly powerful computer, and an ordinary simple VPS server will not work for Forex, since the optimization uses a large amount of memory and the processor is loaded quite heavily, which can lead to your VPS server freezing. Therefore, we recommend using a home computer with a good processor and sufficient memory. The weaker the computer, the longer the optimizations will take.
Secondly, for optimizations, you need exactly the same trading terminal from the same broker on which your trading robot is running. You need to connect to the same trading account and open the chart of that currency pair(or a commodity instrument - gold, oil) that you want to optimize. If there are no restrictions on accounts and instruments, then you can use different trading accounts and different trading instruments. For example, we did not deal with the tools "Bitcoin" or "dollar / ruble" or "corn", but you can easily optimize for these tools and, if you find it worthwhile to run a robot on them, you can do this for the Double Trader Extreme robot. , which has no restrictions on instruments and accounts. If the robot has limitations, then you can change indicators, time intervals, trading schedule and any other parameters from the robot's control panel within one trading instrument / currency pair.
So let's get started:
1. Install the MetaTrader 4 trading terminal on your computer.
You can download it from your broker's website,
2. Connect to your trading account in the terminal.
On the menu File select Connect to a trading account:
Enter your login (account number) and password, also select the correct broker's trading server.
3. Open the chart of the symbol to be optimized
Open a new chart of the required instrument by right-clicking on it and selecting Chart window.
If this tool is not among the active symbols, right-click on any symbol in Market overview and select symbols, then turn on the character you want.
4. Download manually the history of quotes from the chart
Before downloading the history of the broker's real quotes, you need to disable the auto-scrolling of the chart and set the maximum possible story quotes.
On the menu Service select item Settings:
In the settings in the tab Charts install maximum number of bars in history and charts 2 000 000 000 .
Click on OK.
Load the correct quotes for the desired time frame
Then, on the symbol chart, exactly on the time interval (time frame) that you plan to optimize, you need to click the mouse and press the key Home on keyboard. Or you can turn the mouse wheel down until it stops, after which the previous chart data should be loaded. Thus, pressing several times Home or by scrolling the mouse to the beginning of the chart and then repeating these actions again, you can load the maximum possible history of quotes of this broker, on which you can normally optimize the robot. Downloading the quotes archive by other means (for example, from the MetaQuotes server) will only harm, since they will not be correct for this broker.
When the maximum number of quotes has been loaded, you can start testing and optimizing.
5. Open the "strategy tester"
On the menu View select item Strategy Tester:
Or click on the tester button on the top panel of the terminal (if it is there):
A strategy tester window will open at the bottom of the terminal.
6. Select the robot to be optimized and the desired trading parameters
First select the robot, then the desired symbol, time period (time frame). Model you need to choose At opening prices. The spread needs to be set according to the broker- it is different for everyone and you can check its value with the broker, or by looking at the difference between buying and selling an instrument in the terminal (during business hours). If the symbol has no spread, bet current.
Set the desired optimization time - start and end dates.
7. Setting the parameters for the optimization of the robot
After setting the main parameters, you can click on the button Expert properties.
The robot optimization control panel will open. In the first tab Testing you need to set the size of the deposit and the optimized parameter (usually we optimize by Maximal Drawdown - maximum drawdown), it is also desirable to include Genetic algorithm... You can try to optimize for other parameters, if you understand them:
Then open the third tab immediately Optimization, where you can select the maximum value of the optimized parameter, which must also be included here. In addition, here you can speed up the optimization by setting additional restrictions (although it is usually better to start with as many results as possible in the end):
Next, tear off the tab Input parameters where the main parameters are located. In this tab, you need to select the desired indicator and set the corresponding parameters for optimization. Also here you need to choose which parameters will be optimized, and which, on the contrary, will be constant. In fact, you can optimize any parameters, but some just obviously remain the same and do not need optimization. Also, for example, it is pointless to waste time on parameter optimization MA filter period, if this MA filter is disabled. In addition, you need to understand that when choosing different indicators, they use different parameters to work and they must be selected accordingly. Which parameters are responsible for what you can find in
Don't forget to click OK to apply the set parameters before starting the optimization.
8. Optimization process
After setting all the desired parameters, you need to enable the mode Optimization and press Start.
If the optimization process has not started, then an error is possible due to too many parameters being optimized. To check this, you need to open the tab Magazine at the bottom of the strategy tester:
If such an error occurs, a warning is displayed. As a way out, you can reduce the step in the optimization parameters and the maximum / minimum value of some especially large parameters. Then press again Start... When the optimization starts, the Start button will turn into Stop and the expected end time of the process will appear:
9. Selection of optimization results
And the final stage of optimizing trading systems is viewing the results and choosing the best parameters for using them in the future in automated trading.
Open the tab Optimization results... It will display many options for parameters and the results of their use. Sort by the parameter you need (for example, Profit or vice versa, Drawdown):
Then you need to apply the parameters you like, based on the preferences of the optimizer and the tasks set earlier - right-click on the desired result and select from the pop-up menu Set input parameters:
The tab will open automatically Settings strategy tester, where you can click Start and run the selected optimization parameters on any selected time interval (for example, over a longer period or including an earlier or later interval) to find the optimal trading result). If the result of the run does not suit you, select and set other input parameters from the tab Optimization results. For a test run on history, you need to make sure that the checkbox next to the parameter Optimization removed.
After running the selected parameters in the tester, you can examine the result graphically in the tab Schedule either digitally in the tab Report:
Then come up with a name for the SET file and press the button again Save:
After that, this file with settings can be installed in a working trading robot and new parameters can be used.
Outcome
This detailed instructions on optimizing trading robots (Forex advisors) or trading systems, is designed to help those who want to professionally engage in robotic control and achieve outstanding results in trading, even though we undertake all this work - for each of our robots - for each currency pair and for each time interval.
If you have any questions, you can leave comments - the instructions will be supplemented and improved as necessary.
Today we will consider the issues of testing and optimizing Expert Advisors in the MT4 trading terminal.
The strategy tester will open in which we will test our Ilan16c_PipStepExponent_MFI_lock.
In the upper-left tab of the strategy tester, select “Expert Advisor”.
In the tab next to it, in the drop-down list, look for our advisor and double-click on its name.
In the tab below, select a symbol - a currency pair for which we want to test the advisor. Let's have USDJPY.
Choosing a testing model - choosing the most accurate "Every tick" method. “Control Points” and “At Open Prices” are models that are more suitable only for a cursory analysis of the EA's work.
We put a tick on "Use date" - set the interval. Let us have an interval from the beginning of 2015 to 2015.11.23.
The next item is "Visualization".
You can check the box for visualizations, or you can leave it unchecked. A check mark on the visualization means that you will see the entire process of testing the Expert Advisor on the selected history interval right on the chart.
Set the testing speed to maximum - move the slider all the way to the right.
Pause / Play and Skip to buttons are also available.
We move our gaze to the right in the tester.
We make a choice of a time period - on which we will test the robot. Let's have an M5.
Now let's open the Expert Advisor settings - click "Expert Properties".
Here we see the standard settings of the Ilan16c_PipStepExponent_MFI_lock advisor - we will test with them. You can change the settings of the expert as you want and only then test it. Any Expert Advisor can be tested an unlimited number of times and.
On the "Testing" tab, you can select the size of the deposit for testing and its currency, as well as specify which positions to open: buy and sell, buy only or sell only.
Let the initial deposit be 10,000 USD, and the positions: buy and sell (Long & Short) - this should always be the standard in MT4.
Attention: in order to test the Expert Advisor on a decent history with high quality modeling, we need to load quotes for the symbol used in the tests. In our case, we need to download quotes for USDJPY.
This process is also useful for optimizing a trading Expert Advisor. You need to download the archive of quotes for any instrument only once.
How to upload an archive of quotes to MT4?
In the uppermost menu of the terminal, click "Service" and then "Quotes Archive". Or just press F2.
A window with archives of quotes for available instruments will open.
We are looking for our symbol (our currency pair) USDJPY in the list and double-click on its name, and then double-click on "1 Minute".
Press the button "Download". The process of downloading all quotes for USDJPY will begin - for all timeframes.
That's it - all quotes for USDJPY have been downloaded - now you can qualitatively test and optimize EAs at all ticks.
We close this window and try to test our advisor Ilan16c_PipStepExponent_MFI_lock - press the “Start” button.
Quotes are loaded from the quotes archive.
What's the bottom line? Draining the entire deposit.
As you can see, the standard settings are clearly not suitable for us - we will have to optimize this EA.
Note: you can save any report to your computer - go to the "Report" sub-tab of the strategy tester, where we display all the data about the passed test, and right-click in this window, and then "Save as report" - the report will be saved in HTML format ...
Click "Expert properties" and put a checkmark in front of those parameters that will take part in the optimization - put a checkmark on the parameters that are more significant for us.
Also, we put down in front of the parameters with checkmarks their "Starts", "Steps" and "Stops" - in simple words, limit of values from and to with a step.
On the "Testing" tab, you can select the size and currency of the deposit, as well as specify the types of positions to open: purchases and sales, only purchases or only sales.
An optimized parameter is a certain indicator, the value of which determines the quality of the tested set of input parameters. The higher the value of the optimization criterion, the better the test result is estimated with a given set of parameters. The following optimization options are available:
- Balance: the indicator of optimality is the maximum value of the balance;
- Profit Factor: the indicator is the maximum value of the profit factor;
- Expected Payoff: the indicator is the maximum value of the mathematical expectation of a payoff;
- Maximal Drawdown: the indicator is the minimum drawdown value;
- Drawdown Percent: the indicator is the minimum value of the relative drawdown (in percent);
- Custom: when this parameter is selected, the value of the OnTester () function in the Expert Advisor will be taken into account as an optimization criterion. This parameter allows the user to use any custom metric for optimization.
A checkmark opposite the genetic algorithm - it is recommended to leave it with a checkmark. If there is no check mark, then be sure to check it. If you leave this box unchecked, you will wait forever for the Expert Advisor to be optimized, since absolutely all combinations of the Expert's input parameters will be sorted out.
Optimization tab. It allows you to manage constraints during optimization. If any of the conditions is met during a separate run, this run of the advisor will stop. Optimization will continue from the next run.
To enable a limiting condition, you must select the corresponding checkbox to the left of it. By double-clicking the left mouse button in the "Value" field, you can change the existing parameter, after entering the new value, press the "Enter" key.
Limiting parameters include:
- Minimum balance: the minimum value of the balance in the currency of the deposit;
- Maximum profit: maximum profit in the deposit currency;
- Minimum margin level%: minimum margin level in percent;
- Maximum drawdown%: maximum drawdown in percent;
- Continuous loss: the maximum cumulative loss in one series. A losing streak is called several of the following in a row unprofitable transactions;
- Continuous number of losing trades: the maximum number of losing trades in one series;
- Continuous Win: the maximum total profit in one series. Several profitable trades in a row are called a profitable series;
- Continuous number of profitable trades: the maximum number of profitable trades in one series.
After all the changes, click on the "OK" button.
We put a tick on "Optimization" and press "Start".
The optimization process has started - as you can see from the screenshot, there will be 10,496 passes, with an optimization time of almost 175 hours ... But we will not wait so long - as soon as we see an excellent option / options (for example, with a solid profit and an acceptable drawdown), we can stop the optimizer.
Open the "Optimization Results" tab and observe the process. The runs will line up vertically in a row. You can sort any cell - left-click on the title of the desired cell and the values will be sorted in ascending order from top to bottom, click on the title again and the values will be sorted in descending order from top to bottom.
I think 10 positive passes of the optimizer will be enough for the example. Stop the optimizer - the "Settings" tab, the "Stop" button.
So what do we see? We have some good passes, but the best one is the top-most — the highest profit and the smallest drawdown of all 10 passes. We will take these settings.
The settings in the Expert Advisor from the optimizer can be introduced in two ways: double-click on the desired pass (left button) or click on the desired pass with the right mouse button and then "Set input parameters".
Remember our advisor lost the entire deposit? Well, now we press the "Start" button and test the Expert Advisor with new optimized settings.
Great, isn't it? The settings turned out to be excellent.
We open on home page of the strategy tester "Expert properties" and click the save button - we need to save this file with the settings for ourselves, so that later it can be used with this Expert Advisor on different terminals at any time.
We select where we will save the file and come up with a name for it, then press the "Save" button. In this case, the file will be saved to the desktop.
To embed any file with settings in an advisor in the strategy tester, click on the “Expert properties” button and then “Load” - specify the path to the file, select the required file with the mouse and click “Open”. The settings will be integrated into the Expert Advisor - after that do not forget to click on the "OK" button in the Expert Advisor properties.
The results of this optimization testing and the settings file are included in the EA archive.
Now you know how to test an Expert Advisor and how to optimize it correctly. Good luck!
Features of Expert Advisors Testing in MT4
Mechanical trading systems are increasingly used in the work of a trader. One of the advantages is the reduction of the negative influence of psychological factors on the trading process. Trading platform MetaTrader 4, being the most widespread and popular trading terminal, allows you to create and use a variety of automatic and mechanical trading systems, as well as test and optimize them, both on historical data and in demo mode.
Preparing an Expert Advisor for testing in MetaTrader 4. Loading Quotes History
To test the Expert Advisor in the MetaTrader 4 trading terminal, first of all, you need to download the history of quotes of the financial instruments with which you plan to work. In this case, the quotes of the minute interval are loaded. This makes it possible to more accurately approximate price movements within a bar in the testing mode of trading strategies on large time frames (H1, H4, D).
To download minute data, you need to set the size of historical data in the MetaTrader 4 terminal (menu “Tools -> Settings):
In the field “Max. history bars "in the" Charts "tab, set the number manually, according to the following calculations: minute data of one year contains 525600 bars. Accordingly, more than 5 million bars will be needed for a 10-year history. For the values of the new parameters to take effect, the program must be restarted.
The history data is loaded in the program module "Quotes Archive" (item "Service -> Quotes Archive").
In the window that appears, you need to select a period - 1 minute, as well as the symbol of the trading instrument for which you want to load the history. Then click on the "Download" button. Now, after loading, the database contains the required number of quotes. It should be remembered that the amount of downloaded data may differ for different brokers.
It is also necessary to carry out the consistency of quotes at different time intervals, which is achieved by recalculating the data of the minute interval into the data of larger time frames. Such an operation is performed using the "period_converter" script, which should be dragged onto the one-minute chart of the financial instrument:
In this case, in the window of input parameters, you should specify the duration of the recalculated time in minutes (M15-15; H1-60;…). Negotiation must be repeated for all time intervals.
Algorithm for testing an Expert Advisor in the MT4 trading terminal
To test Expert Advisors, use the "Strategy Tester" module (item "View -> Strategy Tester"):
The following settings must be specified in the strategy tester window:
analyzed expert advisor, as well as properties
the need to visualize the testing process
(if the "Use date" option is not set, testing will be carried out on all historical data)
the need to optimize the parameters of the advisor
Choosing an Expert Advisor and Testing Parameters in the Strategy Tester
It is necessary to select an Expert Advisor for testing in the "Expert Advisors" list. All compiled experts are located in the list of the trading terminal in the “experts” folder. The Expert Properties button allows you to open a list of additional settings for the Expert Advisor. In the "Testing" column, you can view and set the general parameters of the Expert Advisor:
You can set here the currency of the deposit, the initial size of the trading account, the nature of trade transactions: all transactions - Short and Long, only buy positions - Only Long, only sell positions - Only Short. Optimization parameters will be discussed below.
Below is the "Input Parameters" tab, which contains the main variables that influence the algorithm of the Expert Advisor:
If you need to change the values of the parameters, then for this you need to edit the column of values. The set parameters should be saved to disk and loaded later. To return to the default values, click on the "Reset" button.
Settings "Period" and "Symbol" of the strategy tester
In the "Symbol" field, financial instrument, on which the testing of Expert Advisors will be carried out, and in the "Period" - the time frame. Necessary and essential condition carrying out qualitative testing, the obligatory presence of one-minute historical quotes of a financial instrument.
Tester simulation method
In the "Model" drop-down list, select the "Every tick" item. This method provides an accurate emulation of the price dynamics inside the bar and makes the testing process more reliable.
Testing time range
If you need to use not all of the historical data, but only a part, you must enable the tester's "Use date" option and enter the date values you need in the "From" and "To" fields of the window.
Test visualization effect
This option allows the trader to monitor the testing process, as well as adjust the rate of receipt of historical quotes. Also, in this mode, the moments of opening positions and their closing by an expert will be displayed on the chart.
Starting the testing process and analyzing the results obtained
The testing process is started by pressing the "Start" button of the strategy tester. Based on the progress indicator, you can estimate the time it takes to complete the operation:
After the testing process is completed, windows of new tabs will appear on the screen: "Results", "Graph", "Log" and "Report".
In the "Results" tab, you can view all events and their sequence during strategy testing:
This table contains calendar parameters (date and time) of testing, type (placing an order, modifying a position, opening, closing or deleting an order, closing a position by stop loss or take profit). Each trade operation is associated with an order number assigned to it during installation. The remaining columns, respectively, indicate the result of the last trade operation, as well as the total balance of the trading account.
The "Log" tab contains debug information directly from the EA testing process itself. It contains successfully completed operations, as well as errors that occurred during the operation of the advisor:
The "Chart" tab of the strategy tester displays the balance (blue line), as well as the dynamics of the trading account taking into account open positions (free funds - green line). These lines often coincide, and a strong divergence suggests that positions are overexposed.
The "Report" tab of the strategy tester displays the most important results of testing the Expert Advisor.
It is generally accepted that the test results are sufficiently accurate if the simulation indicator is equal to or more than 90%, and the mismatch error rate is zero. If the results are worse than these indicators, you need to restart the history for the one-minute time interval.
The most important indicators of the system are the maximum drawdown, net profit, and the number of trades.
Amount of deals reflects the frequency of market entries, that is, the approximate amount of time a trader needs to spend in the market when trading this tested system.
Maximum drawdown- means maximum amount losses, as well as indicates the required minimum size starting trading account for the normal operation of the tested trading system.
Net profit means the difference between the initial and final state of the account balance.
Recovery factor(the ratio of profit to maximum drawdown) is an important indicator of the advisor's performance and its effectiveness. When working effectively, the recovery factor should be more than three.
Also, the important characteristics of the advisor are the average profitable / unprofitable trade. The best option is the ratio of average profit to average losses 1: 3, as well as the excess of the number of losing trades over profitable ones at the level of 1: 2. That is, profit should grow, and losses should be quickly fixed.
Of great importance is the indicator of the psychological factor, which is determined by the maximum number of continuous losing trades. If it is high, then it is better to postpone the use of such a trading system, or the trader must be prepared to mentally survive the "black" band.
Visualization of testing an Expert Advisor in the MT4 terminal
The strategy tester allows a trader to view trading events directly on the chart that occurred during the analysis of the EA. There are two visualization methods: during the EA test and after the test.
For visualization in the mode after the test, click on the "Open chart" line on the "Settings" tab. A new tab will open in the MT4 window with symbols of completed trades and a chart of the tested currency pair.
The second mode allows you to view the chart of the tested instrument directly during the testing period. This mode can be activated by the "Visualization" option located on the "Settings" tab of the tester. After clicking on "Start", the chart of the tested currency instrument will be opened automatically, and sequentially modeled ticks will be sent to it. At the same time, you can adjust the rate of their receipt, as well as suspend the receipt of quotes completely. Using the "Skip to" button, the trader has the ability to start visualization from a certain point in time.
Position opening is indicated by red and blue arrows. Gold arrows show the moment when a trade is closed, and the sloping lines show the time of its existence in the market.
Optimization of the advisor in the MT4 terminal
In the process of optimizing the Expert Advisor, it is possible to select parameters trading strategy, which will show the most profitable trading results on the studied section of history. The optimization process itself consists in the automatic run of several test cases. Each run is carried out with its own individual set of parameters, and then the run with the parameters that showed the optimal result is selected. As a criterion of the system, the indicator of net profit is most often taken into account.
The EA optimization parameters are configured in the EA properties:
To do this, select a criterion for choosing a strategy in the "Optimized parameter" list. Most often, the "Balance" value is selected. At the same time, turning on the "Genetic algorithm" option accelerates the optimization process, using the data obtained from the worked passes earlier. This introduces some error in the calculations, so the final optimization should be carried out with the genetic algorithm turned off.
In the "Input parameters" of the expert properties, the range variations of the expert parameters are marked. The parameters participating in the optimization are marked with checkboxes, and the step of changing the parameter, as well as the initial and final values, are set for them.
The Optimization tab allows the trader to reject any of the optimization results if one of the following conditions is met during the run:
To trigger on a marked condition, you must mark it with a checkbox and set the numerical limit value of this condition.
To perform optimization, set the Optimization option in the Strategy Tester in the Settings tab and press the Start button:
The optimization process will take some time:
After its completion, the following tabs will appear: "Optimization graph", as well as "Optimization results". The optimization results obtained include all the results of the runs:
All data is sorted and arranged according to the optimized parameter. To set the selected optimal parameters of the advisor, you need to double-click on the line with the mouse in the properties of the expert.
The optimization chart shows the area of possible profitable settings:
The axes show the optimized parameters, and the brighter color indicates the maximum balance.
Practical use of MTS
It should be remembered that even a well-tested system on history is never a guarantee of successful performance when trading on a real account. Therefore, the main task of testing, as well as optimization of advisors, is to analyze the market and develop trading rules. And the complete transfer of control of the trading account to a robot is a risky decision and hardly anyone will give you a guarantee of making a profit.
Today we will consider a practical guide to optimizing Expert Advisors in MetaTrader 4... Or, as one blog reader put it - "a culture of communication with advisers" -)
If you have already worked with strategies, then you understand that the same strategy, at different times and on different days, will work out completely differently.
And, as you might guess, the reason is not in the strategy, but in the behavior of the market, since it, in turn, depends on many factors, such as sessions: the number of players, news, etc.
And since the advisors are based on indicator and martingale strategies, they also react to such changes, since the expansion or contraction of price fluctuations immediately disable the system for tracking open deals.
Thus, no matter how confident you are, from time to time it is necessary to work on the settings, as well as to do a more global process - optimization.
In this article, you will learn about the correct optimization scheme, as well as see in practice how this simple process takes place in the MT4 terminal ...
If you delve deeper into the topic of optimization of advisors, you can see that only three schemes are used, and many traders do not even know about two of them -)
Under terminology "Optimization schemes" we mean a selection of historical quotes for optimization and further control. So let's take a quick look at these circuits ...
1. Optimization without forward test
This optimization scheme is popular with beginners, but it is not only illogical to apply it in practice, but also unsafe for your deposit.
On practice: a trader using this approach optimizes the Expert Advisor in MT4 in the past, the historical site of the market, starting from a certain day to this day.
Having seen excellent results in the tester, this trader immediately puts the obtained parameters into the set file. The result is that it falls into the so-called "optimization trap" when the parameters, in fact, in real time, turn out to be inoperative.
2. Optimization with forward test
Forward test optimization is the optimization of the EA parameters in the past, with the control of the received settings in the future.
In practice: the trader divides the historical site into two zones. In the first section, he conducts optimization, after which he tests the obtained parameters in the second historical section.
If the yield curve in the second section after optimization coincides with the first optimized section, the settings are saved and applied on a real account.
The optimization method with a forward test will give better settings than without a forward test, but it's still better to go even further, since your deposit is at stake, you know-)
3. Optimization with forward and back test
The third optimization scheme for an advisor is to some extent similar to the second and is most often used by more professional traders.
The essence of the scheme is that the historical site is divided into three parts.
First, the EA is optimized on the middle (second) area. After that, a test for the stability of the obtained settings is carried out in the third section (in the future). If the optimization and forward test parameters are the same, the EA is finally optimized by the control test, in the first segment of the market.
Using the method optimization of the Expert Advisor in MT4 with a forward test and a back test, you will get the most resistant to market changes settings.
Before proceeding with the optimization of an Expert Advisor, you need to make sure that the historical quotes are complete and, if necessary, load them.
To do this, in the top menu bar, enter "Service" and select "Quotes Archive". Then find the required currency pair and download the M1 minute quotes, all other timeframes will be loaded automatically.
After the tester window opens, you need to set the following settings:
- On the left, under the chart, note that the value is “Expert Advisor”;
- By clicking on the drop-down menu button on the right, in the same line, select the required advisor by double-clicking on the name;
- Next, select the currency pair on which the advisor and the timeframe will work;
- Below is the testing method "Every tick" and the spread on the selected currency pair. It should be borne in mind that different brokers have different spreads, so I recommend only a broker for work.
- Even lower, it is necessary to set a time period on which the advisor will be optimized;
- I recommend turning off the visualization, as it can make the optimization process take a long time;
- Be sure to enable "Optimization".
After such a simple preparation, go to the settings of your Expert Advisor by clicking on the "Expert Properties" button and set the optimization criteria.
In the "Testing" tab set:
- The value of your deposit;
- Leave Long & Short positions, because our advisor opens orders, both in buy and in sell;
- Below, in the "Optimization" select which parameter you will optimize. Usually, the Expert Advisor optimizes the Profit Factor, that is, the number of losing trades in relation to profitable ones;
- Check the box (if not) in the Genetic Algorithm field, it will also save you time for optimization.
There is no point in describing everything here, since the Romum settings are described in the article about it, and what parameters of the advisor to optimize first of all you can read in
You can specify your values, or you can load the initial set, which is in the archive with the advisor ...
Please note that there is a checkbox next to the parameter that you are going to optimize, then click "OK" and close the settings.
Although there is also a tab "Optimization", but usually no one uses the values in it, since in reality they will not show anything -)
That's it, click on the "Start" button and the tester will start optimizing the advisor.
Optimization speed depends on the number of parameters that you set, as well as on the power of your computer. Therefore, the optimization process can take from several minutes to several hours.
After optimization, you can view the results with the selected parameters in the "Results" tab. This table contains data on profit, drawdown, number of transactions, and profitability, actually-)
To perform a forward test, double-click on any of the optimization results you like, after which the settings are automatically activated in the Expert Advisor.
In the future, you can save your sets through the expert settings.
In addition, if you click on the "Chart" tab, then at a glance you can assess the profitability / loss ratio of the performed optimization of the advisor:
Also, using the graph it is easier to compare the results of the forward and back tests.
Yes, it should be borne in mind that the optimization of an advisor is a matter, although not tricky, but very time consuming. Therefore, it should be done on weekends when the market is closed. Moreover, I recommend doing optimization every week. Although, it's up to you ...
And yet, despite all the measures, it is important to understand - optimization of Expert Advisors in MT4 is not the very panacea, which will save you from draining, 100 percent.
The point is that the results in the tester may differ from the results of trading on a real account. This is primarily due to the fact that the tester does not know what it is and the difficulty of opening positions on the news ...
Nevertheless, optimization of the advisor's parameters is an effective preventive measure, therefore, in no case should you neglect it.
Many traders who have recently realized all the benefits automated systems try manually optimize expert advisor parameters by enumerating key parameters and do not even assume that most of the work can be done by the trading terminal itself.
In the previous article, we already briefly got acquainted with the strategy tester and learned how to download representative quotes, so today's review will be devoted specifically to the practical part of the EA optimization in MT4.
If the source code of the robot did not contain errors that could interfere with compilation, the installed robot will appear in the tester's drop-down list. As an example, I used the simplest Expert Advisor CCI_MA, which concludes deals on the commodity channel index and.
By by and large, this is a "sinker", which is almost impossible to manually configure, so I chose it for experiments to show the advantages of automatic optimization of Expert Advisors in MT4.
So, the Expert Advisor is selected, now on the tester's panel we set the rest of the key parameters - the trading instrument (this is the ticker of a currency pair, metal or CFD), timeframe, model type (it is advisable to always select “all ticks”), testing date and, most importantly, put a tick opposite the item "optimization".
At the second stage of the setup, you will need to set the initial parameters of the account and the robot, as well as set the step size for the functions that require optimization. To solve this problem, press the button "Expert properties".
Before our eyes, a standard settings window opened, with which many readers are probably already familiar. In the "Input parameters" tab we mark the variables that require optimization with checkboxes, and also set their initial values (the start column), the adjustment step and the final value (stop).
In the presented example, I decided to "fit" three functions - CCI_per (main index), MA_per (signal moving), and CCI_close_per (index, according to the values of which the deal is closed), so the checkboxes are only in front of the listed variables.
The parameters of all other functions will not change during the EA optimization in MT4, so they are set immediately in the "Value" column.
Thus, if a parameter is being optimized, it is necessary to fill in the "Start", "Step" and "Stop" columns, but if the variable does not change during the tests, it is configured only once in the "Value" field.
Then we go to the “Testing” tab and set the value of the initial deposit here, allow the advisor to open deals in both directions (buy and sell), and also disable the “genetic algorithm” function.
The genetic algorithm is a special "smart" module, with the help of which the terminal searches for profitable "runs", after which it begins to adjust the values of key variables in such a way that all potentially profitable combinations are tested first.
Practice shows that such an approach often interferes with evaluating the test results, since the variables of the Expert Advisor are selected randomly, for example, in the first run CCI_per will be 25, in the second 55, and in the third 15. I like it when everything is ordered, so I disable this function.
But that is not all. To reduce the time to optimize an Expert Advisor in MT4, it is advisable to set limits on the maximum drawdown, profit, and other statistical variables. This can be done in a special tab of the same window.
When everything is ready, just click on the "start" button, as with a normal unit test. From this point on, the optimization began.
As you can see, two new tabs appeared on the tester's working panel, which were not there before - "Optimization Results" and "Optimization Graph". Considering the fact that the information we need is collected here, let us dwell on each of them in more detail.
The table "Optimization results" displays the totals of all "runs", i.e. when the terminal once again adjusts one of the key variables of the robot by the value of a given step, it starts retesting the algorithm on the selected time interval, after which it records the total in a separate column.
By default, only profitable results are shown here, but I recommend enabling the display of all tests, including unprofitable ones. This can be done using the right mouse button:
As you might guess, the test results can be sorted according to a certain parameter, for example, it is reasonable to arrange them in descending order of the final balance.
The “Optimization Graph” is also a source of important information, in particular, its dotted version allows you to estimate how the profits and losses changed as one or another parameter was adjusted.
For the sake of fairness, it should be noted that this method of presenting the results is used quite rarely, since much more information can be obtained from a two-dimensional matrix graph, the easiest way to switch to it is using the "Space" key.
On this diagram, you can immediately see at what combinations the EA optimization in MT4 showed best result, in particular, the more saturated the color of the squares, the closer the balance value to the largest of all the values obtained.
The converse is also true - the pale areas of the matrix correspond to the most "unsuccessful" tests, so such "data pools" can be safely discarded from further research.
Thus, using a standard strategy tester, you can significantly save time spent on optimizing robots, while automation allows you to maximize potential profit and minimize possible drawdown, which is almost impossible to achieve manually.
- How to get a Metro Cash & Carry card for an individual - getting a card and a list of documents Metro card registration
- An example of registration of an act of reconciliation of mutual settlements
- How to withdraw money from YouTube (YouTube) and Google Adsense (Google Adsense) to a Sberbank card: A Complete Guide
- Active income: types and creation of sources