MQL5 Programming Language

Published:28 December 2018 Updated:4 January 2024

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 (it is loaded on your computer simultaneously with the trading service), for example, by clicking on the appropriate icon or by pressing the F4 key on your keyboard. The editor will appear:

In MetaEditor, click the “Create” button and the corresponding window with the list of applications that can be created in the editor will appear.

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 must first give a name to the created Advisor and you can write a link to your website, email in the “Name” field:


In the variant with a template, by clicking on the “Add” button, you must select the parameters that the Expert Advisor will have. The selected parameters can also be deleted by clicking on the appropriate button.

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

After selecting the parameter, you must click “Next”, a window will appear, in which you will be prompted to select event handlers for the Expert Advisor.

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

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 and after clicking “Done” the code template will appear.

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, https://www.mql5.com/ru/forum – 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: https://www.mql5.com/ru/forum/6343

There is also a library of articles about the language at the MQL5 website: https://www.mql5.com/ru/articles

But the best way to start learning a language is with the MQL5 reference book. https://www.mql5.com/ru/docs

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 https://www.mql5.com/ru/signals. 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 MQL5.community 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’ performance – the trader subscribes to the signals only at his own risk.

Which Advisor to choose

MQL5.community offers a wide range of Expert Advisors and trading robots with source codes: https://www.mql5.com/ru/code/mt5/experts. 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: https://www.mql5.com/ru/job, or just buy (or download for free) from the trading robot store: https://www.mql5.com/ru/market. 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++.

Conclusions

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

Reviews

  • The MQL5 website is a scam. Taking advantage of the monopoly, are engaged in aggressive advertising, recently appeared in the terminal in the upper right corner of the red background unit, which at first caught the eye and interfered with the work, as for fruitful work in Forex need to be focused on work and not distracted by various advertisements. Notifications about trades and market closings started to be given in English, again distracting from work. When I expressed my doubts on the forum I was simply banned until 2030 without bothering to write the reason for the ban. By the way to say that the moderator except that with not very mildly speaking high intelligence so also allows grammatical errors and insults. I personally encountered so-called programmers when I was studying programming language. I asked a question why I couldn’t do this and that, and they gave me a ready-made code. When I asked them to explain why the code was written this way and not the way I had written it, I got the answer as a direct punch in the jaw, they wrote that I should use the code they gave me. That is, the programmer himself does not understand anything in programming, but just takes ready-made codes and writes owls, turkeys and everything else. Naturally, nothing works after such programmers. I’m not speaking for all programmers, but most of them are like this. So the moral is this. Before trusting a written, and even more so, a purchased Expert Advisor, you should critically evaluate the proposed product. To prove what I wrote above, I attach a screenshot of my page, which shows the ban.

    Reply to a review
  • Video of MQL5 scammers faking statistics and tricking subscribers. https://www.youtube.com/watch?v=h9bEzoivCLU&t=117s

    Reply to a review
  • Mql5 – fraudsters. MQL5 website fakes trading history of trading accounts, trading positions that are published in the trading history on the MQL5 website do not correspond to the trading positions that are in the mt4 trading platform. The MQL5 website can show only positions with profit on its website, while the positions with losses, which are in the trading history of the platform, the MQL5 website can not show. This results in an ideal monthly trading history, but after publication, the account burns out with subscribers within 1-2 months.
    Also, the account drawdown is published only from the moment of account registration on the MQL5 website, not from the trading history. If the account drawdown was 90%, the MQL5 website will not show it in the trading history, but will show the drawdown from the day of account registration on the MQL5 website.
    That is why there are many trading accounts with maximum drawdown of 2-10% on the site, and monthly profit of 100-250% per month. Traders who lost their money on the MQL5 website by copying trading signals have the right to demand from the MQL5 website the return of lost funds and compensation in court.
    As for trading robots, it is just 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 in the advertisement updated robot, and sells the same algorithm that opens positions at random. Think logically, if the trading robot sold on the MQL5 website can trade well, why should the MQL5 website sell this robot for 50-100$? Why doesn’t the MQL5 website do independent trading? Because this robot will blow up your deposit within a month.

    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

Site Map