Vous êtes sur la page 1sur 4

1/11/2017 MetaQuotes Language MQL4/MQL5 - Wikipedia

MetaQuotes Language MQL4/MQL5

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

The primary objective of MQL4 and MQL5 is automation of trading and First appeared 2005
facilitation of operational analysis. MQL4 and MQL5 comprises an Filename .ex4, .mq4, .mqh,
extensive codebase source code library used for developing trading robots. extensions .ex5, .mq5

1 History
2 Compiler
3 Differences between MQL4 and MQL5
4 Capabilities
5 The MQL4 and MQL5 Syntax and their Difference from ++
6 Data types
7 Operations and expressions
8 Criticism
9 References
10 Bibliography
11 External links

On July 1, 2005 MetaQuotes Software released MetaTrader 4 - a platform for trading on financial markets.[1] MQL4 -
an object-oriented programming language, was written specifically for work on this platform. Initially, its syntax was
based on C. Another platform, MetaTrader 5, was released in 2010 together with MQL5 - a new language created for

The release of MetaTrader 4 600 build in 2014 was a major update of the language.[3] That brought it to the level of the
more modern MQL5. The development environment MetaEditor became unified for both languages.

The updated MQL4 features new graphical objects and new functions borrowed from MQL5 and used for analyzing
charts. The protection system was completely modified for the executable files EX4. The MQL5 Standard library was
transferred almost entirely with the only exception of the trade subsystem, which required adaptation. New data types
were added and the micro substitution system expanded (conditional compiling #ifdef, #ifndef, #else, #endif),
allowing the use of code from other languages based on /C++. Structures, classes and object pointers were added as
well (it should be noted that object pointers in MQL4/MQL5 are not similar in every way to the ones in ++). The
updated MQL4 features the mode of strict compiling, which prevents a lot of potential programming errors. In MQL5
this mode is default and cannot be disabled.[4]

https://en.wikipedia.org/wiki/MetaQuotes_Language_MQL4/MQL5 1/4
1/11/2017 MetaQuotes Language MQL4/MQL5 - Wikipedia

Both languages support nearly all standards of object-oriented programming except multiple inheritance:
encapsulation and extensibility of types, inheritance, polymorphism, overload, virtual functions.

To develop programs in MQL4 and MQL5, MetaEditor - a compiler embedded in the development environment - was
created. It is integrated in the MetaTrader 4/MetaTrader 5 trading terminals. MetaEditor allows convenient editing of
program source code, automatic generating projects by a template, profiling code and remotely developing joint
applications in conjunction with other people.

Differences between MQL4 and MQL5

One of the fundamental differences is the trading system setup. MQL4 is used for developing trading programs based
on the order system and MQL5 is utilized to implement a positional system. In the MetaTrader 5 trading terminal
there are strict delimitations between the concepts of position, order and deal. An order is a request to execute a
trading operation, which may result in a trading deal. A position is the aggregate deals on a certain financial

MQL5 comprises an expanded list of trading functions for work with open orders, a list of open positions, order
history and deal history. In MQL4, different functions such as OrderSend(), OrderClose(), OrderCloseBy(),
OrderModify(), OrderDelete() were initially incorporated for performing each trade operation. These functions can be
used to open/close and delete pending orders.

In MQL5 all trading operations are carried out by sending trade requests using only one function - OrderSend(). As a
parameter, the function gets passed a request either to place a pending order, or to open by the market, or to cancel a
previously placed order. Introducing the new function OrderSendAsync() to MQL5 enabled asynchronous trading

An important novelty in MQL5 is Depth of Market and a new event type of handling Depth of Market information.

MQL4/MQL5 aims to directly address traders' needs and requirements. It was developed for writing trading programs
and is used only for that purpose. Functions for performing trade operations OrderSend(), OrderClose(),
OrderCloseBy(), OrderModify(), OrderDelete() have been initially incorporated in the language and are used for
changing the state of a trading account.

There are four program types that can be written in MQL4/MQL5.

Expert Advisors. Automatic systems trading by specified parameters and following a coded algorithm. Occurrence
of a previously specified event like receiving a new tick, an alert about a new trading operation or even pressing a
button or clicking a mouse, triggers the Expert Advisor to perform a programmed action.
Custom Indicators. Written by users, they are used along the ready-made indicators integrated in the terminals.
Their function is purely analytical. Indicators do not perform trading nor carry out operations that slow down the
interface stream such as sending emails or performing a random delay. The main task of indicators is to monitor a
situation, reflect and interpret it and then submit to a trader for analysis.
Scripts. A script is a program intended for a single execution of an action. The start event is the only event type
processed by the script.
Custom Function Libraries. In addition, there is an opportunity to create include files (#include). Include files allow
you to include most frequently used functions and classes without directly pasting their source code into its
program. Using functions and classes simplifies creating, debugging and compiling because when using dynamic
libraries, functions load only when they are called directly.

https://en.wikipedia.org/wiki/MetaQuotes_Language_MQL4/MQL5 2/4
1/11/2017 MetaQuotes Language MQL4/MQL5 - Wikipedia

The MQL4 and MQL5 Syntax and their Difference from

The syntax of the languages is similar to the one of C++, however there are exceptions. MQL4 and MQL5 do not
feature pointer arithmetic. The goto operator is also missing in the MQL languages as well as a possibility to declare
anonymous enumeration and multiple inheritance.

Text formatting. Any number of space symbols such as spaces, tabs, empty strings can be used to make the
code more readable and convenient to work with. There are exceptions, however. A line break symbol must not
be used immediately after a hash and space symbols cannot be used inside constants, identifiers and key words.
Comments. As with the C/C++, MQL4/MQL5 comments can be both single-line and multi-line. A single-line
comment starts with the // symbols and ends with the new line character. Multi-line comments start with the /*
symbols and end with */ ones. They cannot be nested.
Identifiers. Identifiers are used as names for variables and functions. The length of an identifier cannot exceed
63 characters. The following characters can be used in writing an identifier: numbers 0-9, Latin upper and lower
case letters Z, recognized as different characters and the underscore character (_). A number can not be used as
the first character.

Data types
Main data types used in MQL4/MQL5:

integers (char, short, int, long, uchar, ushort, uint, ulong);

Boolean or logical (bool) ;
literals (ushort);
strings (string);
floating point (double, float);
color (color);
date and time (datetime) ;
enumeration (enum).
Structures and classes are a complex (abstract) data type that can be operated in MQL4/MQL5. Classes differ from
structures in the following characteristics:

the key word class at declaration;

all class members have private access by default whereas structure members have public access;
class objects always have a table of virtual functions when structures cannot have it;
the new operator can be applied only to class objects. It cannot be applied to structures;
inheritance: a class inherit from a class only and a structure derives only from a structure.

Operations and expressions

All common operations - arithmetic, bool, binary etc. are present in MQL4/MQL5. The precedence of operations
corresponds to that adopted in ++.

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

1. "MetaTrader 4 Official Release" (https://www.metaquotes.net/en/metatrader4/news/3433). MetaQuotes Software
Corp. July 1, 2005. Retrieved August 23, 2017.

https://en.wikipedia.org/wiki/MetaQuotes_Language_MQL4/MQL5 3/4
1/11/2017 MetaQuotes Language MQL4/MQL5 - Wikipedia

2. "MetaTrader 5: Official Release" (https://www.metaquotes.net/en/company/news/3619). MetaQuotes Software

Corp. June 1, 2010. Retrieved August 23, 2017.
3. "MetaQuotes Releases Build 600: Marketplaces, MT5 and Regulation in the Balance" (http://www.financemagnate
s.com/forex/brokers/metaquotes-releases-build-600-marketplaces-mt5-and-regulation-in-the-balance/). Finance
Magnates. February 4, 2014. Retrieved August 23, 2017.
4. "Updated MQL4" (https://docs.mql4.com/mql4changes). MQL4 Reference. Retrieved August 23, 2017.

"MetaTrader - investicn platforma pre obchodovanie" (http://is.muni.cz/th/324627/fi_b_a2/thesis.pdf) (PDF).
Is.muni.cz. Retrieved 14 November 2014.
"Evaluating the Effectiveness and Sensitivity of Forex Trading Robots" (http://unitec.researchbank.ac.nz/bitstrea
m/handle/10652/1925/Yu%20Gu%20MComp.pdf?sequence=1&isAllowed=y) (PDF). Unitec.researchbank.ac.nz.
Retrieved 14 November 2014.
"Forex Analysis and Money Management : Interactive Qualifying Project" (http://www.wpi.edu/Pubs/E-project/Avai
lable/E-project-022912-001013/unrestricted/IQP_Final_Report.pdf) (PDF). Wpi.edu. Retrieved 14 November
"INVESTMENT AND TRADING : An Interactive Qualifying Project Report Submitted to the Faculty of
WORCESTER POLYTECHNIC INSTITUTE" (http://www.wpi.edu/Pubs/E-project/Available/E-project-031212-1800
59/unrestricted/Investment_and_Trading_IQP.pdf) (PDF). Wpi.edu. Retrieved 14 November 2014.

External links
"MQL4 documentation" (http://docs.mql4.com). Docs.mql4.com. Retrieved 14 November 2014.
"MQL5 documentation" (https://www.mql5.com/en/docs). Docs.mql5.com.

Retrieved from "https://en.wikipedia.org/w/index.php?title=MetaQuotes_Language_MQL4/MQL5&oldid=799968991"

This page was last edited on 10 September 2017, at 22:09.

Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using
this site, you agree to the Terms of Use and Privacy Policy. Wikipedia is a registered trademark of the Wikimedia
Foundation, Inc., a non-profit organization.

https://en.wikipedia.org/wiki/MetaQuotes_Language_MQL4/MQL5 4/4