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.

Compilation mode #

The editor provides two compilation modes: with maximum code optimization and without optimization.

The time required to create an executable file is significantly reduced when optimization is disabled. Use this mode during the active development stage, when you need to quickly check the written code. Then, during the final program compilation, turn on the maximum optimization mode for the best performance.

To switch between the modes, use the "Build" menu or the compilation command menu on the toolbar:

Control the compilation mode

The "Maximum optimization" parameter in project settings performs the same function.

  • 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.

Compiling for processors with different architectures #

Modern processors provide a set of advanced instructions which significantly accelerate mathematical calculations: AVX, AVX2, AVX512, and FMA3. These instructions are supported in the MQL5 compiler to enable the generation of more efficient and faster codes. The use of such instructions is optional:

  • If you are creating an application for yourself and you are sure that it will run on a processor that supports the desired architecture, you can compile it using advanced instructions. This will provide an increased performance.
  • If you are creating a program for public use or for sale, compile it with the basic instruction set in X64 Regular mode. This will ensure maximum compatibility of the application with user hardware.

To find out which instructions are supported on your processor, use the CPU-Z free utility. After installation, open the 'CPU' section and check the 'Instructions' field:

Check which instructions your processor supports using CPU-Z

To select a processor architecture, use the compilation menu. Next, click 'Compile'. You can also specify the architecture in the MetaEditor settings and in separate project settings.

Select the processor architecture for which the program will be compiled

If the application is compiled for an architecture that is not supported by the user's processor, then an attempt to run it will cause the following message to be printed in the platform log:

your CPU architecture does not allow to run the file '<file-name>.ex5': AVX512 required, you have AVX2 only


  • Programs compiled for processors with AVX512 are not yet supported in the MQL5 Cloud Network and in the built-in VPS.
  • Only files compiled under X64 Regular can be uploaded to the Market. This is required to ensure maximum application compatibility with user hardware.