MetaQuotes Language MQL4 / MQL5

from Wikipedia, the free encyclopedia
MetaQuotes Language
MQL4 logo
Basic data
Publishing year: 2005

MQL4 (MetaQuotes Language 4) and MQL5 (MetaQuotes Language 5) are integrated programming languages for the development of trading robots, technical market indicators, scripts and function libraries within the MetaTrader software.

The main goal of MQL4 and MQL5 is automated trading and facilitating ongoing evaluations. MQL4 and MQL5 have extensive codebase libraries with source codes for developing trading robots .

development

On 1 July 2005 published MetaQuotes Software to MetaTrader 4 - a trading platform for the financial market. MQL4 - an object-oriented programming language - was specially developed for this platform. Its syntax is originally based on C. The other platform, MetaTrader 5, was released in 2010 together with MQL5 - its new language.

The release of MetaTrader 4 build 600 in 2014 included extensive further development of its language. It brought them to the level of the more modern MQL5. The MetaEditor development environment has been standardized for both languages.

Since then, MQL4 has new graphic objects and functions from MQL5 for chart analysis. The system protection was completely modified for the executable files EX4. The standard libraries of MQL5 were almost completely transferred with the exception of the trading system, with the necessary adjustments. New data types and an extended microsubstitution (conditional compilation #ifdef, #ifndef, #else, #endif) have been introduced, which allow the use of the code of other programming languages ​​on the basis of С / C ++. Structures, classes and pointers to objects have also been adopted (the pointers to objects in MQL4 / MQL5 are not exactly the same as in С ++). The updated MQL4 offers the strict compilation mode, which avoids many possible programming errors. In MQL5 this mode is preset and cannot be deactivated.

Both languages ​​support almost all standards of object-oriented programming with the exception of multiple inheritance : data encapsulation and type expansion, inheritance , polymorphism , overloading , virtual methods .

Compiler

A compiler has been integrated into the development environment for program development in MQL4 and MQL5 with the MetaEditor. It is part of the MetaTrader 4 / MetaTrader 5 trading terminals. The MetaEditor enables comfortable editing of the program source code, the automatic creation of projects based on a template, the creation of profiles and the joint development of applications with other people at different locations.

Differences between MQL4 and MQL5

One of the fundamental differences is the setup of the trading system. In MQL4 trading programs are developed on the basis of trade orders, in MQL5 a positioning system is implemented instead. In the MetaTrader 5 trading terminal there is a strict separation between the concept of position , order and deal . A request ( order ) is a request for execution of commercial activities, which can lead to a commercial transaction. A position is the sum of the transactions in a particular financial instrument.

MQL5 includes an extended list of trading functions for working with open orders, a list of open positions, order history and the history of deals. In MQL4, the various integrated functions, such as OrderSend (), OrderClose (), OrderCloseBy (), OrderModify (), OrderDelete (), are used to carry out the individual trading operations. These functions are also used to open, close and delete pending orders.

In MQL5, all trading operations are carried out by sending trade requests with only one function: OrderSend (). The orders - be it placing a pending order, opening a market order or canceling an order that has already been placed - are transferred to the function as parameters. With the introduction of the new OrderSendAsync () function, MQL5 now also has asynchronous trading activities.

An important novelty of MQL5 is the Depth of Market and a new type of event for the treatment of the depth of market information.

options

MQL4 / MQL5 is aimed directly at meeting the needs and requirements of traders. They are designed for writing trading programs and will only be used for that purpose. Functions for carrying out trading operations OrderSend (), OrderClose (), OrderCloseBy (), OrderModify (), OrderDelete () are part of the languages ​​from the beginning and are used to change the status of the trading account.

There are four types of programs that can be created with MQL4 / MQL5.

  • Expert Advisor . Automatic systems that act with certain parameters and follow a programmed algorithm. The occurrence of a predetermined event, such as B. the receipt of a new rate, the notification of a new trade or the pressing of a key or a mouse click, triggers the execution of a programmed action in the Expert Advisor.
  • User indicators . Written by the user, they can be used together with the indicators built into the terminal . Their function is purely analytical. Indicators do not trade or perform any operations that slow down the data flow of the interface, such as: B. the sending of emails or random delays. The main job of indicators is to monitor a situation, reflect and interpret it, and then present it to a trader for analysis.
  • Scripts . A script is a program for performing an action once. Start is the only type of event handled by the script.
  • Custom function libraries . It is also possible to create your own include files (#include). With include files you can include the most frequently used functions and classes without having to insert their source code directly into the program. The use of functions and classes simplifies creating, debugging and compiling, since when dynamic libraries are used, the functions are only loaded if they are called directly.

MQL4 and MQL5 syntax and how they differ from С ++

The syntax of the languages ​​is similar to that of C ++, with exceptions. MQL4 and MQL5 do not have pointer arithmetic . There are also neither goto statements in the MQL languages, nor the possibility to define anonymous enumerations or multiple inheritance .

  • Text formatting : Any number of spaces such as the space itself, tabs, and empty strings can be used to make the code more readable and easier to edit. There are, however, exceptions. A line break must not be used immediately after a hash, and spaces cannot be placed within constants , identifiers and keywords .
  • Comments : As in C / C ++, comments in MQL4 / MQL5 can be one or more lines. A single-line comment begins with // and ends with the end-of-line character. Multi-line comments start with / * and end with * /. They cannot be nested.
  • Identifiers : Identifiers can be used as names for variables and functions. The length of an identifier may not exceed 63 characters. The following characters can be used when writing an identifier: The numbers 0–9, Latin upper and lower case letters AZ and the underscore character (_) are recognized as different characters. A number cannot be used as the first character.

Data types

The most important data types in MQL4 / MQL5 are:

  • Whole numbers (char, short, int, long, uchar, ushort, uint, ulong);
  • Boolean or logical type (bool);
  • Single character (ushort);
  • String;
  • Floating point numbers (double, float);
  • Colors (color);
  • Date and time (datetime);
  • Enumeration (enum).

Structures and classes are complex (abstract) data types that can be used in MQL4 / MQL5. Classes differ from structures in the following ways:

  • The class keyword in the declaration;
  • By default, all members of a class can access elements declared as 'private', whereas the members of a structure are only allowed to access those elements that are declared as 'public';
  • Class objects always have a table of virtual functions, something that structures don't;
  • The statement new can only be used on class objects, not on structures;
  • Inheritance: A class can only be derived (inherited) from one class, a structure only from one structure.

Instructions and expressions

All common instructions - arithmetic, logical, binary, etc. - exist in MQL4 / MQL5. The order of precedence of the statements corresponds to that in C ++.

criticism

The main disadvantage of the languages ​​of the MQL family is the impossibility of creating independent applications, since each language is connected to its corresponding platform (MetaTrader 4 / MetaTrader 5) and the EX4 / EX5 programs only work in them.

Individual evidence

  1. MetaTrader 4 Official Release (s) . In: MetaQuotes Software Corp. , July 1, 2005. Retrieved August 23, 2017. 
  2. MetaTrader 5: Official Release (s) . In: MetaQuotes Software Corp. , June 1, 2010. Retrieved August 23, 2017. 
  3. MetaQuotes Releases Build 600: Marketplaces, MT5 and Regulation in the Balance (en) . In: Finance Magnates , February 4, 2014. Retrieved August 23, 2017. 
  4. Updated MQL4 ( en ) Retrieved August 23, 2017.

literature

Web links