MQL5 Programming Language

The basics of the MQL5 programming language

MetaQuotes Language 5 (MQL5) happens to be a programming language to develop automated trading applications. The language was created by MetaQuotes Software Corp. Apart from some exceptions, the syntax of the MQL5 language has much in common with the C++ language.

MQL5 is utilized for developing trading robots, technical Forex indicators, advisors as well as other applications for trading in the Forex. MQL5 programs in the format of object-oriented programming or OOP for short. For MQL5 programs a special MetaEditor environment and MQL5 Storage have been created.

The key components of this programming language are the same as in others, although there’re several specific features. Here data can be of various types: integers, Boolean data, literals, strings, date, time, enumerations, etc. The complex types of data (abstract data types) include classes and structures.

In MQL5, a variety of expressions and operations is possible. The MQL5 language operators appear to be problem-solving algorithms forming the body of the task. Functions are used to write the program code.

The library of user-defined functions is used to store and distribute blocks of user programs. The include file appears to be the source text of the user files at compile time – libraries, scripts, and advisors.

MQL5 features a specific compiler subsystem performing the preliminary preparation of the source code of a program prior to compiling. By means of the preprocessor, functions are entered into MQL5 programs, files are inserted, constants are declared, etc.

 

How to use MQL5

MQL5 enables you to create interactive programs suited for the individual needs of any investor. MQL5 has three key types of programs: an indicator, a script, and an adviser. One script is run one time on the price chart, and having accomplished its tasks it stops. Additionally, the script is capable of performing a single operation in the infinite loop format, until it’s stopped by the investor.

The chart may have many indicators, they perform until they’re stopped. They calculate values making use of price data in the indicator buffers. Robots and advisors are designed to automate trading operations. Moreover, they can be also utilized to analyze the current market situation and accomplish other tasks. MQL5 enables you to create your own modules for making trading robots by means of the MQL5 Wizard. Programs in MQL5 are created with the help of an event model. So, they react to any event, whether it’s an order execution, price change, time frame, etc.

 

How to create an Expert Advisor in MQL5

MQL5 already comes with all the necessary tools for creating so-called Expert Advisors. In simple terms, it looks like this. We launch MetaEditor via the MT5 trading platform (the figure 1) (it’s downloaded to the computer simultaneously with the trading service), for instance, by clicking on the corresponding icon or making use of the F4 key on the keyboard. As a result, the editor will show up (the figure 2):

How to create an Expert Advisor in MQL5

Fig. 1

Editor to create an Expert Advisor in MQL5

Fig. 2

In MetaEditor, you require clicking on the «Create» button and the corresponding window will arise with a list of applications, which can be created in the editor (the figure 3):

List of applications

Fig. 3

In this window, you can choose between the advisor «Template» and the advisor «To generate». Choose it and click on the «Next» button. In both cases, a window will arise in which you should first give the name of the created adviser (the figure 4). You’re free to provide a link to your website, or specify your email address in the «Name» field:

The parameters the adviser should have

Fig. 4

In the version with the template, by clicking on the «Add» button, you can choose the parameters that the adviser should have (the figure 5). You can delete the selected parameters by clicking on the corresponding button. At this stage, you’re expected to have substantial programming skills and deep understanding of trading. Having chosen the parameter, you require clicking «Next», and a window will arise in which you’ll be offered to choose event handlers for the advisor.

Choose event handlers for the advisor

Fig. 5

Proceeding with creating the advisor, you need to click «Next». You’re expected to choose another test event handler and click the «Finish» button. As a result, the code template will show up (the figure 6) with the parameters set by you:

Code template

Fig. 6

Extra parameters are added to the code template in compliance with the rules specified in the MQL5 Detailed Guide. If the Expert Advisor function (to generate) is chosen after calling the MQL wizard, you need to choose the name (the symbols and the timeframe are already specified in the parameters), the parameters for the signals are added, and the trading parameters, as well as the money management parameters, are added. After you click the «Done» button, a code template will appear. The editor also has expert testing as well as debugging services. You can learn how they work from the detailed instructions for MQL5.

 

The trader community and forum

The trader community offers you ready-made answers to any questions about MQL5. In particular, you’re highly recommended to attend a trader forum available at https://www.mql5.com/en/forum. It has answers to nearly all questions on the subject.
However, considering that the forum is very large, it takes much time to find the required information.

Questions from newcomers who are making their first steps in mastering this programming language are addressed to this url: https://www.mql5.com/en/search#!keyword=mql&page=1.

Additionally, on the MQL5 website, you can find a collection of articles about the language, just follow https://www.mql5.com/en/articles.

You’d better start mastering MQL5 from this book: https://www.mql5.com/en/docs. In the MQL5 community, you can purchase an advisor, order a trading robot or offer your advisor for sale.

 

Trading signals generated by Expert Advisors available on the MQL5 website

The MQL5 website has a section of signals for MetaTrader 5 for automated trading: https://www.mql5.com/en/signals. First, you need to get familiar with the rules section.

On the website, you can register either as a subscriber or a seller of signals. The subscription can be paid or free, and it enables you to utilize trading signals in your own trading account. At the same time, every MQL5 community member can allow other traders to use his own signal for free.

A community member can also sell signals on the condition he or she accepts the terms of the Trade Signals Broadcast Agreement and undergoes a special registration procedure. The user chooses signals in compliance with the criteria of maximum profitability, reliability, rating, etc. He or she can also pick up a new signal. The system also picks up signals according to user requirements for certain Forex brokers or seeks signals by their author. By the way, the service comes up with a disclaimer for the operation of signals (the figure 9). So, the trader subscribes to signals on his own responsibility.

Automated Forex trading

 

Choosing the right advisor

The MQL5.community offers a wide choice of advisors as well as trading robots with source codes: https://www.mql5.com/en/code/mt5/experts. The website has two separate sections for advisors for MetaTrader5 and MetaTrader4. The service also allows you to download indicators, scripts, and libraries.

The advisor can be chosen according to the simplified rating. Well, to the right of the list of advisers there’re two sections: the last and the best advisors. The best advisors are chosen by user rating. Moreover, the rating of trading robots is indicated to the right of each of them with asterisks varying from 1 to 5. You also have an opportunity to add your code to the list for users to download.

However, It’s possible to order an adviser tailored to your requirements. For this purpose, you should take advantage of a freelance exchange: https://www.mql5.com/en/job. Alternatively, you can purchase this stuff (or download for free) in the shop of trading robots: https://www.mql5.com/en/market. You can also put up a trading robot for sale.

When purchasing an advisor, just relying on user ratings, indicated by asterisks under every trading robot isn’t enough. It’s recommended to ask for feedback. Take some time to study the features of the robot you’re interested in, whether it’s worth the money it’s sold for (many trading robots are extremely expensive).

 

Useful materials

You can find tons of materials about MQL5 on the web, including step-by-step tips for creating advisors and robots from experienced programmers. However, the MQL5 website is the leader in presenting educational materials on the subject.

The choice of books on the subject is rich enough. For instance, you can read a textbook on this programming language by T. Mashnin. Moreover, you can take advantage of numerous lessons and free video courses from enthusiasts on the trader forums. These materials will come in handy not only for newcomers but also for those who are eager to enrich their knowledge.

You should realize that any lessons become obsolete over time. The programming language keeps evolving and improving, and the same applies to the platform on which it’s utilized. Therefore, it makes sense to look for relevant and up-to-date materials. Unfortunately, it’s not easy to do because most of the materials have been in the network for years.

Since the MQL5 language has much in common with C++, many experienced users recommend reading C++ books, such as «A First Book of C++» by Bronson G.J., «C++ for dummies» by Davis Stefan R. as well as «C/C++ and MS Visual C++ 2010 for beginners» by Pakhomov B. N., etc. You can easily download all these books on the Internet. Having learned C++ you won’t have great difficulties in mastering C++.

 

Conclusion

MQL5 is a well-proven tool for creating trading programs with enormous potential. In the network, some folks dare to ascertain that you can learn this programming language just for a month. Don’t take such doubtful statements serious.

Perhaps, it’s possible to learn its syntax in a relatively short period of time, but programming, in particular, complex applications, will be a time-consuming undertaking. As for learning to program really worthy applications, it will take more time, of course. It should be noted that the most difficult and long-term option would be your independent study of this programming language with the help of books and video courses and without an experienced tutor-programmer who can provide crucial prompts on the subject.

Another more important question is whether it makes sense for you to learn it. It’s worth learning only if you have already decided to develop and sell trading robots and advisors. However, if you need to just optimize your trading, then it makes sense to properly choose and use already developed products, which can be useful to you.


Choosing A Reliable Broker

BrokerBonusMin DepositPayoutReviewOpen Account
OlympTradeUp to 100% deposit$10Up to 90%ReviewVisit Broker
IQ Option$10Up to 91% *ReviewVisit Broker
BinomoUp to 100% deposit$10Up to 90%ReviewVisit Broker

Сomments