MetaEditor Help

MetaEditor HelpDeveloping programsCompilation


Compilation means converting a source code of an MQL4/MQL5 program into the machine language. The result is an executable program file (*.EX4 or *.EX5) that can be launched in a trading platform.

Compilation consists of several stages:

  • Lexical analysis
  • Syntax analysis
  • Semantic analysis
  • Code generation
  • Code optimization
  • Any file (*.MQ4, *.MQ5 or *.MQH) can be compiled, but an executable file (*.EX4 or *.EX5) can be obtained only as a result of compiling a main MQ4/MQ5 program file or project.
  • The executable file is created in its own format hiding the original program algorithm.
  • Compiled executable EX4/EX5 files can be distributed without source MQ4, MQ5 and MQH files. Debugging is not possible without them. It is also not recommended to distribute executable EX4/EX5 files obtained during a debugging process.

To obtain an executable program file, open the main source file or project via Navigator and click Compile Compile in the File menu or F7. The compilation process protocol is displayed on the Errors tab of the Toolbox window. If compilation has passed with no errors, you can run the obtained program in the trading platform.

Compilation of the program and displaying the results on the Errors tab

If there are errors or warnings, they are displayed on the Errors tab.

Compilation errors are marked with Error both on the Errors tab and in the appropriate piece of code. No executable program file (*.EX4 or *.EX5) is created if they occur. To go to a string with an error, double-click on the error or click Go to Line Go to Line command in the context menu. The string and the column where an error is detected are displayed in the appropriate columns.

Warnings marked with Warning icon indicate places of potential errors. These are the source code segments that can be misinterpreted (for example, an implicit value type change). You can go to such a code string exactly the same way as in case with errors.

Information icons stand for various info messages, for example, messages about include files the program accessed during compilation.

  • The full description of the compilation errors is provided in the MQL4/MQL5 language help.
  • In case of warnings, an executable file is generated. But the warnings should not be ignored since they indicate potential code errors.
  • During the compilation, an executable file (*.EX4 or *.EX5) is generated in the same directory as the main source file of the program (*.MQ4 or *.MQ5) or a project.
  • metaeditor.exe can be used as an external compiler in third-party IDEs.