MQL5 Programming Language

Fundamentals of the MQL5 programming language

MetaQuotes Language 5 (MQL5) is a programming language for automated trading applications developed by MetaQuotes Software Corp. The syntax of MQL5 is similar to C++ with some exceptions.

Technical indicators are written in the language of MQL5, trading robots, Advisors and other applications for trading on the forex market. MQL5 programs in the object-oriented programming (OOP) format. A special environment MetaEditor and MQL5 Storage are created for MQL5 program.

The basic components of the language are the same as in other programming languages, and there are a number of specific features. Data in the MQL5 language can be of different types - integers, boolean, literals, strings, date, time, enumerations, and others. Complex data types (abstract data types) include structures and classes.

Different operations and expressions are possible in MQL5. Operators in MQL5 are algorithms of problem solving, which form the body of the problem. Program code is written with functions.

The library of user functions is intended for storage and distribution of blocks of user programs. Included file is the source code of user files, - EAs, scripts, libraries at compile time.

The MQL5 language has a specific subsystem of the compiler, which carries out the preliminary preparation of the source code before compilation. Using the preprocessor, functions are introduced into MQL5 programs, constants are declared, files are inserted, etc.

How to use the MQL5 language

MQL5 allows creating interactive programs tailored to the individual needs of any trader.

There are three main types of programs in MQL5 - script, indicator and Expert Advisor. One script runs once on the price chart, and stops after performing its tasks. Also a script can run, performing a single operation, in an infinite loop format, until it is stopped by the trader.

There can be many indicators on the chart, they work until they are stopped. Indicators calculate values based on price data contained in indicator buffers.

Advisors and robots are designed to automate trading operations, and can also be used to analyze the current situation in the market and perform other tasks.

The MQL5 language allows you to create your own modules for building trading robots through the MQL5 Wizard.

Programs in MQL5 are created using the event-driven model. They react to any event - price change, implementation of an order, timeframe change, etc.

How to write an Expert Advisor in MQL5

The MQL5 language contains all the necessary elements for writing Expert Advisors. In general terms, step by step it looks like this. Start MetaEditor through the trading interface of MT5 (picture 1) (it is loaded on your computer simultaneously with the trading service), for example, by clicking on the appropriate icon or by pressing F4 on your keyboard. The editor will appear (fig. 2):

MQL5 Programming Language

Image. 1

Fundamentals of the MQL5 programming language

Image. 2

In MetaEditor click the "Create" button and the corresponding window with the list of applications that can be created in the editor appears (fig. 3)

How to use the MQL5 language
Image. 3

In this window you can choose between "Expert Advisor (template)" and "Expert Advisor (generate)". We choose and click on the "Next" button. In both cases a window will appear in which you should first give a name to the created Expert Advisor (Fig. 4) and you can write a link to your website, email in the "Name" field:

How to write an Expert Advisor in MQL5
Image. 4

In the version with the template, by clicking on the "Add" button, you must select the parameters that the Expert Advisor will have (Fig. 5). The selected parameters can also be deleted by clicking on the appropriate button.

MQL5 programming for forex

Image. 5

Already at this stage, the trader is required to have strong skills and programming and understanding of trading.

After selecting the option, click "Next", a window will appear, in which you will be prompted to select event handlers for the Expert Advisor (Fig. 6).

MQL5 forex robots and advisors

Image. 6

Continuing to create the Expert Advisor by clicking "Next", you will need to select more test event handlers and click "Done", after which a code template will appear (Fig. 7) with the parameters set by the trader.

MQL5 Language Guide
Image. 8

Additional parameters are added to the code template according to the rules, which are specified in the detailed MQL5 language manual.

If after calling the MQL Wizard the "Expert Advisor (Generate)" function is selected, then step by step select the name (the symbols and timeframe are already specified in the parameters), add parameters for signals, add trading parameters, money management parameters (Fig. 8) and after clicking "Done" the code template will appear.

MQL5 programming


The editor also has services for testing and debugging the Expert Advisor, the work of which should be studied in the detailed instructions for the MQL5 language.

Community of traders and forum

All questions on the development and use of MQL5 are addressed in the community pages. In particular, - The forum of traders, where you can find answers to most, if not all, of your questions.

The problem is that the forum is very large and it takes time to find the information you need. Questions from those who are just beginning to learn the language are addressed at this address:

There is also a library of articles about the language at the MQL5 website:

But the best way to start learning a language is with the MQL5 reference book.

In the MQL5 community, you can simply buy an Expert Advisor, ask to develop a robot, or offer your own EA for sale.

Trading signals with the help of Expert Advisors posted on the MQL5 website

The MQL5 website has a signals section for MetaTrader 5 for automated trading First of all, you should read the rules of the section.

On the site, you can register as a subscriber or as a signal seller. Subscription can be paid or free, and it allows you to apply trading signals on your own trading account. Each member of can provide their signal for free to other traders.

A member of the community can also sell signals if he accepts the terms of the Trading Signals Broadcasting Agreement and goes through a special registration procedure.

The user selects signals according to the criteria of maximum profitability, reliability, rating and so on. He can also select a new signal.

The system also selects signals according to user requirements for certain Forex brokers or search for signals by their author. It is worth noting that the service indicates a disclaimer of responsibility for the signals (Fig. 9) - the trader subscribes to the signals only at his own risk.Trading signals with the help of Expert Advisors posted on the MQL5 website

Image. 9

Which Advisor to choose offers a wide range of Expert Advisors and trading robots with source codes: The site has two sections - EAs designed for MetaTrader5 and EAs designed for MetaTrader4. In the service you can also download indicators, scripts and libraries.

The Expert Advisor can be selected according to a simplified rating: to the right of the list of Expert Advisors there are two sections: the latest/best. The best ones are selected according to the users' evaluation. In addition, the rating of robots is indicated to the right of each of them with asterisks from 1 to 5. By the way, the user can add his own code to the list for users to download.

But EA can be ordered and to your requirements, for this there is a freelance market:, or just buy (or download for free) from the trading robot store: There you can also put the robot for sale.

When buying an Expert Advisor, it is better not to limit yourself to the evaluation of users, which is indicated by the stars under each robot, but to ask for feedback and, in general, do not be lazy to study the features of the robot - whether it is worth the money for which it is sold (many robots are very expensive).

Useful Materials

There are a lot of materials on programming in MQL5 on the Internet. These are step-by-step detailed guides to creating Expert Advisors and Expert Advisors from experienced programmers. Most of the explanatory and training materials can be found on the MQL5 website.

Quite a large selection of books on the subject, in particular, "Tutorial (guide) to the MQL5 programming language" by T. Mashnina (download for free), there are free video courses and numerous lessons by enthusiasts on the traders' forums. The materials are not only for beginners, but also for users who want to deepen their knowledge.

You have to keep in mind that any lessons get outdated, the language itself is constantly evolving and improving, as well as the platform on which it is applied and look for better training materials relevant - and in this there is already some difficulty, most materials are on the network for more than one year.

By the way, since MQL5 language is close to C++ language, many experienced users recommend to read books on C++, such as Bronson G.J., A First Book of C++. A First Book of C++, Stephan R. Davis "C++ for Dummies", S. Lippman "C++ for Beginners", B.N. Pakhomov "C/C++ and MS Visual C++ 2010 for Beginners" and others - all these books can be easily downloaded from the Internet. Mastering MQL5 will not be difficult, - after mastering C++.


The MQL5 language is a well-proven tool for writing trading programs with great possibilities. At the same time, you can find statements on the Internet that MQL5 is easy to learn and can be mastered "from scratch" even in a month. There are very big doubts about such statements.

It is probably possible to learn the syntax in a short time, but it will take a long time to program, especially complex applications. And it takes even longer to learn how to program truly valuable applications.

It should also be noted that the most difficult and time-consuming option is self-learning programming from books and video courses without an experienced programmer, who can advise the important points.

Another question, which is more important, is whether it is necessary to learn. Learning to program can make sense if you intend to develop and sell the same trading robots and Expert Advisors later on.

But if it is just a question of optimizing trading, it might be more effective to be able to evaluate already developed applications and choose the ones that are really useful.

3.70 / 3
Leave a review


  • The MQL5 website is a scam. Taking advantage of the monopoly, they are engaged in aggressive advertising, recently appeared in the terminal in the upper right corner of the red background unity, which at first struck the eye and interfered with work because for fruitful work in forex you need to be focused on work instead of being distracted by various advertisements. Notices about trades and market closings began to be given in English, again distracting from work. When I expressed doubts on the forum I was just banned until 2030 without dignity to write the reason for the ban. By the way to say that the moderator in addition that with not a very, to put it mildly, high intelligence and also makes grammatical errors and insults. I have encountered so-called programmers personally when I was learning a programming language. I asked a question why I could not do so-and-so, to which I was given ready-made code. When I asked explain why the code is written as written and not as I wrote, the answer was a direct hit in the jaw, I wrote that would use the code that was given. That is. The programmer himself understands nothing about programming, but just takes ready-made codes and writes owls, turkeys and everything else. Naturally, after such of programmers, nothing really works. I do not speak for all programmers, but most are like that. So the moral is this. Before you trust The written, let alone the purchased Expert Advisor, needs to critically assess the product offered. As a proof of the above, I attach a screenshot

    Reply to a review
  • Video of MQL5 scammers faking statistics and tricking subscribers.

    Reply to a review
  • Mql5 — cheaters. MQL5 site fakes trading account history, trading positions that are published in the trading history of the MQL5 site are not correspond to trading positions, which are in the mt4 trading platform. The MQL5 site can show on its website only positions with profit, and positions with The MQL5 website may not display losses that are not reflected in the trading history of the platform. From here you get a perfect monthly trading history, and after of the publication, the account is burned together with the subscribers within 1-2 months.
    Also, the drawdown on the account is published only from the moment of account registration on If the drawdown of the account was 90%, the MQL5 site will not show it in the trading history, but will show the drawdown, with The number of the account registration day on MQL5 website.
    That’s why there are many trading accounts with maximal drawdown of 2-10% and monthly profit of 100-250% in month. The MQL5 website does not inform subscribers about that, thus misleading traders, Copying trading signals, you have the right to claim the return of lost funds from the MQL5 website and get compensated by a court of law.
    About trading robots, is simply the same algorithm that opens trading positions automatically, at random. Then the administration of the site changes the name of the robot, uploads a new cover photo, writes an updated robot in the ad, and sells the same algorithm that opens positions at random. Think

    Reply to a review
    • Konstantin 12 July 2019 at 09:47

      Well, about the fact that the site sells experts, you can argue. They are only a platform through which programmers sell programs. The percentage is deducted from the sale in favor of the service. The trading history can be corrected in DC and their signals can be published. They will also share the interest with the service. And they will take the main profit.
      So, there is no need to cut corners without understanding the essence of the matter.

    • Vladimir Mosevnin 2 March 2020 at 17:09

      Even if an indicator or expert advisor worked perfectly, you can run it for free on historical events and find out the level of profitability or drawdown