Lucrative trading in automated mode is possible and working expert advisors do exist. However, nobody uploads efficient trading robots online. Of the hundreds of publicly available advisors, hardly a few will be able to consistently make profit. The way out of this situation is creation of your own trading robot.

A special programming language mql4 (MetaQuotes Language 4) is used to create advisors. mql4 EA is just one of the features of the mql4 programming language. Apart from it, the user can create:


  • their own indicator. Despite the fact that the trading terminal contains several dozens of built-in indicators, some traders prefer using only their own developments;
  • a library. Is a repository of individual blocks of custom programs. Allows to cut the time spent on writing programs;
  • a script – a simple program that is used for a single execution of an action;
  • an include file. Functionally, this element is similar to a library: it stores the text of the code of the custom program blocks. It is also used to cut the time spent on writing programs. It is more preferable than the libraries in terms of speed.


mql4 EA: structure and stages of creation

To create an advisor, you equally need the following components: basic knowledge of programming and a working strategy. That is, the trader must have a working algorithm, which they just automate. Before you start, you need to soberly assess the possibility of automated trading.

The language understood by the computer best describes the indicator strategies and strategies that use averaging or Martingale principle. It is almost impossible to automate trading on the basis of charts construction.

Before writing the code, it is desirable to think through the advisor scheme, its division into separate functional blocks. mql4 EA usually includes the following blocks:

  • program launch;
  • data preprocessing;
  • orders accounting;
  • definition of conditions of a deal opening;
  • calculation of orders costs and lot size (for dynamic lot);
  • orders opening;
  • orders closing;
  • block for detecting errors is usually provided (for example, in the case of loss of connection with the server);
  • message block;
  • program termination.


How to make mql4 EA simpler and more stable

It is advisable that the trader thoroughly understood the strategy that lies in the basis of the advisor. This will help bring EA code to perfection. In the case of mindless copying other people's ideas or borrowing of individual blocks from other advisors at the output, you will most likely get the average product.

It is recommended to create mql4 advisor from separate blocks. This rule can be ignored if the advisor is fairly simple and its code doesn’t exceed a few dozen lines. But if you are going to create a complex trading system with a heavy code, the person can simply get lost in the intricacies of the code.

At the stage of creating a trading robot, you shouldn’t try to make the code too beautiful and elegant. The main condition for this stage is performance of the advisor, and you can polish it later, at the stage of the code optimization.

Compilation will identify errors in the code: during this process the code is checked for errors and converted into a set of commands that a computer understands. The final step before launching the advisor on a real account is backtesting.

Social button for Joomla