MetaQuotes (MQL) Programming
MetaQuotes Language (MQL) is a programming language used exclusively with MetaTrader Software to create automated trading robots and financial market indicators. Programmers who write MQL scripts must have a strong grasp of object-oriented programming, MQL syntax, and the financial markets in which they plan to deploy MQL scripts.
The goal of writing MQL scripts is to automate the process of analyzing financial markets, primarily foreign currency exchange markets (Forex), and trading financial instruments based on that analysis.
The first version of MQL was released in 2001 as an integrated programming language in the MetaQuotes trading platform. In 2002, an updated and rebranded version of the MetaQuotes platform was released, named MetaTrader, and packaged up with MQL II which was an updated version of the MetaQuotes programming language.
MQL, as it is known and used today, was released on July 1, 2005 along with MetaTrader 4 (MT4). The new language was called MQL4. The platform and integrated programming language were a hit and rapidly became the de facto standard-bearing trading platform within the forex trading marketplace.
In 2010, MetaTrader 5 (MT5) was released along with MQL5, and was MetaQuotes Software's first attempt to branch out beyond the forex market. The software was a modest success, but was not able to supplant MT4's position as the market leader.
Today, MT4 and MQL4 programming are still used extensively to automate the analysis and trading of forex financial instruments. MT5 is also used within forex markets, but can also be used to program and facilitate the trade of other instruments such as stocks, bonds, and commodities. As of 2011, more than 450 brokerage companies and banks had deployed MetaTrader platforms for trading in forex and other financial instruments.
MQL is an object-oriented programming language with syntax based on the C programming language. As a result, programmers who already know C, or closely related languages such as Java or C++, will find MQL syntax familiar, and pick up the language quickly.
In 2014, MetaTrader 4 600 Build was released. This new version of MetaTrader 4 significantly expanded the capabilities of MQL4 to the point that performance of the programming language is now much closer to the performance of MQL5. While MQL4 and MQL5 are similar, MQL5 includes many functions and features that MQL4 does not. In addition, some of the fundamental ways that processes are handled vary between the languages. As a result, while scripts can be ported between MQL4 and MQL5, extensive rewriting is often required.
For this reason, when learning MQL, it's important that programmers focus on the language applicable to the trading platform they will be using. MQL scripts can only be deployed on the MetaTrader platform. Before selecting MQL4 or MQL5, programmers should confirm which version of the MetaTrader platform their broker offers, MT4 or MT5, and learn the applicable language based on the platform they will be using.
Setting Up an MQL IDE
While MQL can be written in a plain text editor, it must be compiled in MetaTrader. The client versions of MT4 and MT5 are free and both include an integrated development environment (IDE) known as MetaEditor. The simplest place to write MQL is within MetaEditor.
To get MetaEditor, you will need to get the version of MetaTrader your broker runs on their servers.
- MQL4 IDE: Download MetaTrader 4 from the official MetaTrader 4 website.
- MQL5 IDE: Download MetaTrader 5 from the official MetaTrader 5 website.
With MetaTrader installed, you can write MQL scripts and execute them using a free demo account trading in fictional currency. To deploy the scripts for live trades you will have to sign up for a trading account with the brokerage of your choice and connect MetaTrader to the broker's MetaTrader servers.
MetaQuotes Language 4 (MQL4) Resources
MetaQuote Software maintains a very thorough MQL4 documentation website which includes a wealth of content for programmers of all levels. If you're new to MQL4, here are a few pages that may be helpful:
- MQL4 Introductory Course in HTML ebook format;
- MQL4 Codebase with thousands of free scripts to learn from and use;
- MetaTrader 4 forum where you can interact with and learn from other MQL4 programmers (think of it as a StackOverflow-equivalent for MQL4 programmers);
- MQL4 Programming Articles database: get started start with the MQL4 Language for Newbies article.
If you learn more effectively by following a defined training program with videos to supplement written content, consider the following premium online courses:
- Algorithmic Trading In Forex: create Your First Forex Robot! Offered by Udemy.
- MQL4 Tutorial Bootcamp: trading Robot Coding in Metatrader4 hosted at Udemy.
- Black Algo Trading: Build Your Trading Robot, an online Udemy course.
- MQL4 Tutorial: algorithmic Trading in MQL4 for Complete Beginners, offered by Forex Boat.
MetaQuotes Language 5 (MQL5) Resources
MetaQuotes Software also maintains an official documentation site for MQL5 programmers. Some of the most valuable content for new programmers includes:
- Official MQ5 Reference Documents;
- MetaTrader 5 Forum where other MQL5 programmers can weigh in on the challenges you face writing MQL5 scripts.
- MQL5 Codebase is where you'll find more than a thousand MQL5 scripts written by other programmers. Learn how to write MQL5 by reviewing, breaking, fixing, and adjusting these scripts.
- The MQL5 Programming Articles database is where you'll find a wealth of articles and tutorials addressing specific programming tasks. Some of the most useful posts for beginners include:
If you would prefer to learn from a structured programming course, a MQL Tutorial Bootcamp premium online course is available at Udemy.
MQL4 and MQL5 are programming languages used to create trading robots and financial analysis tools to deploy on the MetaTrader 4 and 5 trading platforms. The primary sources of educational resources for aspiring MQL programmers are the official MQL4 and MQL5 documentation websites. Since MQL4 and MQL5 scripts can only be executed within the corresponding version of MetaTrader, beginning programmers should take care to learn the language that is applicable to the version of MetaTrader that is offered by their broker.