The trading platform contains a built in programming language MetaQuotes Language 5 (MQL5), the MetaEditor development environment and strategy testing tools.
Any information about the development of trading strategies in MQL5 can be found on the official MQL5.community site. The website section Code Base contains examples of ready-to-use applications. |
The trading platform has its own built-in language for programming trading strategies MetaQuotes Language 5. It is the fifth generation of MQL languages. It allows developing Expert Advisors to automate trading processes, as well as implementing your own trading strategies. MQL5 also allows creating custom indicators, scripts and function libraries.
MQL5 Features:
A detailed description of all language constructions and functions is provided in the MQL5 Reference. All the necessary information about MQL5 can also be found on the developer community website at https://www.mql5.com.
MetaEditor is an integrated MQL5 development environment. It is a component of the trading platform. MetaEditor allows you to create, edit, compile and debug source code written in MQL5.
More details about MetaEditor can be found in its built-in help files. The description of MQL5 can be found in the built-in reference and the official MQL5.community website.
MQL5.community website features an extensive library of articles on MQL4/MQL5 programming. Articles are an excellent guide for creating applications, since they cover a lot of practical tasks involving algorithmic trading. New articles are published every week.
List of all available articles is displayed directly in MetaEditor. To find the necessary material, use the online search.
Three major types of trading applications are available.
Expert Advisors are mechanical trading systems that allow complete automation of analytical and trading activities for the efficient operation in the financial markets. They allow to perform prompt technical analysis of price data and control trading activities on the basis of signals received. They also help to strictly follow a trading strategy eliminating emotions.
All Expert Advisors are stored in the /MQL5/Experts folder of the trading platform.
Custom Indicators are custom developed technical indicators intended for analyzing price dynamics. Trading tactics and Expert Advisors are developed based on algorithms of indicators. Custom indicators are only used for analyzing symbol price dynamics. Indicators cannot trade and do not have access to charts.
All indicators are stored in the /MQL5/Indicators folder of the trading platform.
A script is an application written in MQL5 designed for a single execution of an action. A script can perform both analytical and trading functions. Unlike Advisors, scripts are executed on request. In other words, if an Expert Advisor works almost continuously, a script executes its function and quits.
All scripts are stored in the /MQL5/Scripts folder of the trading platform.
Services enable the use of custom price feeds for the platform and to implement price delivery from external systems in real time, just like it is implemented on brokers' trade servers. Services can also be used to perform other service tasks in the background.
Unlike Expert Advisors, indicators and scripts, services are not linked to a specific chart. Such applications run in the background and are launched automatically when the terminal is started (unless such an app was forcibly stopped).
All services are stored under the /MQL5/Services folder of the trading platform.
Inside folders Experts, Indicators, Scripts and Services, applications can be sorted into subfolders. The structure of their location is displayed in the Navigator window. |
Click " Create in MetaEditor" in the context menu of the Navigator window in section Expert Advisors, Indicators or Scripts. MetaEditor can also be launched by pressing F4.
This launches MetaEditor with an automatically opened MQL5 Wizard. Use it to generate the necessary program template to quickly start software development. Let's create a simple script writing a message "Hello world" into the journal.
In the resulting template, we add the code Print("Hello World"); and compile it by pressing F7 to receive an executable file. The executable file has an extension EX5 and can be run in the trading platform.
Compilation results are added to the editor log.
In accordance with the application type, the source code is saved to the folder MQL5\Scripts\. The executable file is created in the same folder. You can now return to the trading platform and run the generated script.
Specifics of use of automated trading programs are described in section "Expert Advisors and custom indicators". |
To edit a trading robot or a custom indicator, click " Modify" in its context menu in the Navigator window or select it and press Enter. This opens MetaEditor with the source code of the selected indicator. After you have modified the indicator, re-compile it (F7). Otherwise its previous unchanged version will be used in the platform.
There are many ways to shut down a trading application in the platform.
Trading robot |
Custom technical indicator |
Script |
---|---|---|
|
|
|
|
If you only have a source code file (*.MQ5), save it in a folder corresponding to the application type:
To quickly navigate to the trading platform data folder, click " Open data folder" in the File menu.
To run a file in the trading platform, compile it in the MetaEditor:
This creates an executable *.EX5 file that can be run in the trading platform.
Source files (*.MQ5) are not displayed in the Navigator window of the trading platform. |