This article will show you how to optimize and test advisors on your MT4 terminal. There have been many discussions concerning the optimization process, and many users have concluded that advisors should be tested based on ticks in order to get the best results. We believe that it is better to test an advisor based on those quotes that you'd like to use for your trading. For example, if you are planning to trade on an MT4 terminal by using quotes provided by Alpari or FXDD, then testing based on quotes from, say, Dukascopy will skew your test results, and leave you with a poor understanding of your advisor and how it actually works. That is because many brokers apply filters in an MT4 environment. These filters can efface the wicks on the candlesticks. Also, if you use ticks from an API broker, then the number of ticks in one second will obviously be greater with the FIX API broker; and price volatility will be many times, if not hundreds of times, higher with the FIX API broker than it will be with any MT4 broker. Testing, therefore, has to be done based on those quotes that are supported by your broker. If your broker is able to provide you with tick-based quotes, you can upload them into the terminal and use them; if not, it’s advisable to use minute candlesticks. This kind of testing should produce more accurate results that will give you a better idea of how well your advisor works - certainly better than if you were to use tick-based quotes from another broker for testing purposes.

Video "How to optimize and test EAs on your MT4 terminal"

So you have an expert advisor, and you’d like to test it. What’s next? First, you need to set it up. If no installation file has been provided along with the advisor, you need to do it manually by clicking on “File” and then on “Open Data Folder”.

mt4 ea installation process

Click on “MQL4”. You can see that there are three folders: “Experts”, “Libraries”, and “Indicators”. The advisor file is placed in the “Experts” folder.

mt4 ea installation ex4

Usually, it’s an ex4 file or an MQL4 file. If it’s an MQL4 file, then it’s a source code file, in which case you can modify the advisor, since you have the code source. An ex4 file, on the other hand, is an execution file and, as such, cannot be modified - you just copy it to the “Experts” folder.

If your advisor contains a library, it should be copied to the “Libraries” folder. In our example, the advisor does come with a library, and it’s been copied to the “Libraries” folder. A library’s files can contain a .dll ending or a .ex4 ending.

By the same token, if your advisor contains custom indicators, these need to be copied to the “Indicators” folder. Again, an ex4 file is an execution file, while an MQL4 file is a source code file and can therefore be modified.

Once everything has been copied, you’ll need to relaunch the terminal, so just close it and then open the terminal again.

Once the expert has been placed into the “Experts” folder, you’ll see it under the “Expert Advisors” tab, just as you’ll see your indicators under the “Indicators” tab. For demo purposes, I will use our LRS expert advisor  in order to show you how to optimize and test it. Now that you’ve reopened the terminal, you can upload your quotes. Some brokers store quotes on their own servers, while others only allow users to download their quotes by using the MetaQuotes website. In that situation, you can do the following. Let’s say you want to test the GBPUSD quote. You can open the M1 timeframe, turn off the scroll-down functionality, and then use the “page up” button on your keyboard or your mouse to scroll up all the way to the top. In our example, you can see that the M1 quotes provided by the broker end on June 27th, 2018. We then go to the M5 folder and repeat the steps performed with M1. As we’re also working with M15, we do the same with M15. This is a good way to do your optimization and testing based on those quotes that have accumulated in your terminal. There might be gaps in these quotes, but your testing should still be fairly accurate, unless you’re dealing with a scalper. If you’re dealing with a scalper that works with low take-profit orders, you can try to obtain quotes or ticks from the broker and then upload them into the terminal for subsequent use.

To optimize your advisor, you first need to determine your optimization period. For advisors that are geared towards the short term (e.g., scalpers or high-frequency advisors), the period selected can be shorter, e.g., 1-1.5 years. This is because the market changes more quickly for a scalper, and so its parameters need to be adjusted more frequently. Some advisors do not require any optimization at all: they are designed to operate for longer periods of time and are not reoptimized. This is the case with the LRS MT4 EA, which uses inactive pairs, which means that test results that are based on historical data will present a very accurate picture of how the advisor will perform in the future; in other words, test results associated with this advisor will mirror real-life results.

mt4 ea optimization

To reiterate, if the advisor aims at short-term profits, the optimization period should be relatively short. Conversely, if the advisor works with positions that are held open for longer periods of time (1-3 hours), then your optimization period has to be longer, since your advisor in this case is more sensitive to any changes in the market and in its direction, as well as to its trends; and so a more extensive period of time has to be captured for your optimization and testing.

To optimize the advisor, you need to click on “Expert Properties” and select those parameters that you need to optimize. In our example, as some of the parameters have already been optimized, they are concealed. We’ve left the stop-loss and take-profit parameters, and we’ll use those. We need to check them off. We then need to input values for the “Start”, “Step”, and “Stop” fields. Naturally, you have to understand what these parameters represent and the ranges within which their values can fall. For example, for the size of the take-profit parameter, you can try setting a low of 10 points and a high of 100, while the step parameter can be set to “1”. You can set the size of the stop-loss parameter to a low of 5 points and a high of 200 points, and the step to 1.

If there are many parameters that have to be optimized, you can do it in several stages. For example, you can first optimize your take-profit parameter. Once the required values are entered, you can uncheck the take-profit parameter and proceed to optimize the stop-loss parameter. This will allow you to speed up the optimization process. The more parameters you select for your optimization, the longer the process will take.

You click on OK and select your optimization period. You then need to select the optimization model. We recommend going with the “control points” model, as the “every tick” model will take too long. Check off the optimization box. Finally - and this is important - you need to set the spread. You can use the current spread, or you can use the average spread for your broker, which you typically determine by observing how your broker works or by using certain indicators with that broker.

You can now click on “Start”. There is an Optimization Results tab. If you click on this tab and then right-click to remove “Skip useless results”, the checkmark will disappear, which will allow you to see both positive and negative results. The optimization process has now begun. You can sort the profit column by size. In our example, we can see our maximum profit based on the parameters that use a take-profit of 38 and a stop-loss of 11. Once the optimization process is over, you will be able to view your optimization results - in this case, our optimization results.

In our example, the optimization process was stopped, but we can still review the optimization results, bearing in mind that they are incomplete. The top result shows a very high profit, but the drawdown level also appears to be high. It’s best to aim at optimal results. Based on the optimization results that were generated, the second choice from the top is the optimal one: the profit is quite high, but the drawdown number, at some 4%, is also very acceptable.

Double-clicking on the results will cause the values used to generate these results to automatically populate the parameters of the expert advisor. So if you want to use the values for a certain result as your parameters, you need only double-click on them. You can now run a test using these parameters. At this point, it is better to use the “every tick” model. Be sure to use the same period. There’s also a little trick that can be used: you can set aside a small period of time, e.g. 2-3 months (typically the last 2-3 months), during which no optimization is done; you then do your testing based on these 2-3 months. This makes it possible for you to gauge how well your optimized advisor performs over a period that has not been covered by the optimization. You click on “Start”, and you can now review the test results based on these parameters. You can also review the graph; in our case, it shows us that our advisor is performing well with the parameters that have been selected, and that the graph is an upward one. Once the testing is over, you can save the results by right-clicking with your mouse and then selecting “Save as Report”. Multiple reports can be saved. You can review them, select the one that shows the best results, and use it in your trading.