Optimization of forex advisors in MT4


The basis of profitable trading is a simple principle – “Know your strategy”. For forex advisors, the principle will be slightly different – “Optimize your advisor”. The only caveat is the choice of the correct historical generation period in MT4.

From the point of view of professional traders, there is no point in optimizing the entire historical sample.The reason is trivial – the market is changing, so the results for the sample may not correspond to the current situation. The optimal period is from 6 months to 1 year.

The optimization question arises when the forex advisor shows good results during the initial testing. And since most traders and investors use the Meta Trader 4 (MT4) terminal, which is popular today, we will consider the optimization of advisors using its example.

Choosing a model for generating quotes

Choosing a model is an important part of testing a forex advisor. The MT4 terminal offers only three testing models. But before choosing, you need to know about the ways to generate models. An incorrectly chosen model can greatly change the test results.

How generation works in models:

Control points – Forex advisor is optimized at OHLC prices, the nearest shorter time frame. This model is considered a rough one, but most EAs do not require accurate minute or even tick data. Therefore, the model is used to test simple Expert Advisors;

Every tick is a more complex plotting model. Differs from “control points” in the depth of time-frame generation. The model should be used for EAs that rely on minute OHLC data;

By opening prices – this model should be used at an early stage of testing the Expert Advisor. For enumerating parameters in MT4, the model is not suitable.

The “all ticks” generation model is considered the optimal choice. But without a genetic algorithm, results can be expected for years.

Here is an example of how much the test results can differ depending on the choice of the testing model.

  • Every tick
  • Control points
  • Opening prices

Genetic Algorithm

Let’s dwell a little on the genetic algorithm in MT4 (activated by default). It is better not to remove the tick from the algorithm, I will explain why.

Despite the vastness of this topic, we will highlight several important points:

The first is that any genetic algorithms are based on the random search method. This is partly a disadvantage, since it is not clear how long such a search will take;

Second, to get around this shortcoming, the genetic method for MT4 was supplemented with Holland’s Reproductive Plan. What is this plan? – a separate topic.

As a result, we get a method that allows us to reduce the optimization time for a forex advisor. To be precise, the time is reduced by a factor of 100 or more.

How Much Does Testing Accuracy Suffer? The accuracy does not change at all. The only moment that was revealed during testing is the identity of the result with the “Control Points” model.

With an increase in the number of searches, the genetic algorithm shows the best results in terms of time. That is why it is better not to disable the genetic algorithm, because we do not want to optimize the advisor for 35 years.

Choosing parameters

After we have decided on the model and turned on the genetic algorithm, it’s time to choose the parameter to be optimized. The MT4 terminal offers five main and one arbitrary optimization parameters.

The point is to get the optimal trading settings at the exit. For example, let’s run optimization based on the “Balance” parameter. After completion, on the “Optimization Graph” tab, we will see a map of parameters. If you hover the mouse over the greenest block, then we will receive information about the profit and the parameters that provided this profit.

Optimized parameters

Optimized parameters criteria:

Balance – at the exit we get the settings that give the maximum profit;

Profit Factor is when the amount of winning trades is divided by the amount of losing ones. We need settings that will show a result greater than 1;

Expected Payoff – search for the optimal result based on mathematical expectation. The higher the mat. waiting, the better the advisor works;

Maximal Drawdown – optimization of the maximum drawdown in relation to the local maximum. The higher the drawdown, the higher the risk;

Drawdown Percent – optimization of the maximum drawdown in relation to the current deposit. The conditions are the same, the higher the drawdown, the higher the risk;

Custom – the enumeration is performed according to the specified settings of the user himself.

Most often, traders optimize the “Balance” parameter, and do not pay attention to the drawdown or checkmate. expectation. But in the long term, the magnitude of the risk sometimes plays a big role.

Setting initial parameters and restrictions

The next step is setting the input parameters. This can be done on the next tab. Depending on the forex advisor, only those settings are selected, the optimization of which will give the desired result. As a rule, this is profit, stop or lot.

Installation of input parameters


The “Value” column contains standard parameters. But in the columns “Start”, “Step” and “Stop”, you need to manually register the data. Start sets the beginning of the search, step is the next parameter, and stop sets the end point.

We set the limitation

Restrictions are set in order to reduce the time to optimize Expert Advisors. There are eight restriction parameters available in MT4. As you can see in the screenshot, the main task is to stop the optimization when the specified conditions are met. For example, we are not satisfied with an Expert Advisor that goes into a drawdown of 30%. If you set the required parameter in the “Maximum drawdown” column, the optimization will stop at 30% drawdown.

We put the test limits

We set limits

An example of Expert Advisor optimization

As an example, we will use the “Pump and Dump” Forex Expert Advisor for MT4. The EA uses a simple TS – buy low, sell high. There are many settings and a good trading history, plus monitoring.

Load-Minister-of-store MQL5

Downloading an Expert Advisor from an MQL5 Store



After downloading “Pump and Dump” from the store to MT4, go to the “Tester” tab and select our advisor in the corresponding menu. To set parameters and restrictions, go to the “Input Parameters” tab in the properties.



Setting optimization-Pump-and-Dump



The Forex Expert Advisor page contains a detailed description of all parameters. Our task is to set values ​​only for those of them that make sense to optimize.

Description of parameters:

IPump_Indicator is the main indicator by which the EA opens orders. We set values ​​from higher sensitivity to lower – value 0.2, start 0.2, step 0.1 and stop 1.0;

Multiplication Profit is a permission to add orders along a trend. We set the start position – false and stop at true. This will optimize both options;

Lot_Proc_from_Balance – the parameter is responsible for the order volume and its increase. We iterate over values ​​from 0.1 to 1.0, step 0.1. Set the initial value to 0.6;

TP_pips – iterate over the profit value. The default is 300 pips, the start is 100, the step is 100, and the stop is 700 pips.

Distance – looking for the optimal distance for a series of open orders. We start the search from 100 points, with a step of 100 and a stop at 700. The default value can be set at 450 points;

Step Distance – the only difference from the previous parameter is the step size. We will sort it out too – the start is 100 points, the step is 50 and the stop is at 600. The default value is set at 100 points;

Plus – affects the number of points to no-loss for open orders. We go through from the starting position of 50 points to the final position of 500 points. Let’s set the step to 50, and the default value is 150.

We save our settings via the “Save” button in the lower right corner. In the future, the saved settings can be restored. We press the “OK” button.

The rest of the parameters are “optional”. Setting them up for optimization is not very important. However, they are worth paying attention to during initial and routine testing.

We start testing

After adjusting the EA properties, let’s move on to the final touch. Once again we check all the settings.

Last settings:

  • We put a tick on “Use date” and set the testing period;
  • Uncheck the “Visualization” box;
    Select a time frame for the “Period” parameter and set the spread value for the “Spread” value;
  • We put a tick on “Optimization”.

Run-optimizatsiyu- (last-bar)

Run-optimization- (final-touch)

After all the settings, you can start testing with optimization parameters.

Running the testing-with-optimization


​Optimization results

After the end of the test, we will get two additional tabs “Optimization Results” and “Optimization Graph”. Go to the chart and see a lot of blocks. Each block is a ready-made run according to certain parameters. In our case, the balance was optimized, so the greenest block indicates the highest profit.

The result of optimization, on-balance sheet


How to transfer parameters to settings?

We double-click on the required block. We will be transferred to the results tab;

Double click on the highlighted value. The settings will be automatically entered into the properties of the expert.



All that remains is to go to properties and save the new parameters. And then, uncheck the optimization box and conduct regular testing. You can use the entire history, or choose certain periods.


In conclusion, I would like to note the following – Expert Advisors should be constantly tested, as the market profile is changing. But optimization can be done once every half a year. Moreover, the optimization should cover the data of the last six months. You can then compare the new results with the old ones and make changes if necessary.

1 thought on “Optimization of forex advisors in MT4”

Leave a Comment

Your email address will not be published. Required fields are marked *

📨 Subscribe to our newsletter

Scroll to Top

📨 Подпишись на рассылку новостей

Не шлем СПАМ! Гарантия

Subscribe to our Telegram channel
Открыть чат
Scan the code
Hello 👋
How can I help you?