MetaEditor Hilfe


Compilation is the process of translating the source code of a MQL4/MQL5 program into the machine language. This process consists of several stages:

  • Lexical scan;
  • Parsing;
  • Semantic analysis;
  • Code generation;
  • Code optimization.

A successful compilation results in the creation of an executable file (*EX4 or *.EX5) of a program that can be started in the client terminal.

  • Any file (*.MQ4, *.MQ5 or *.MQH) can be compiled, but an executable file (*.EX4 or *.EX5) can be generated only as a result of the compilation of the main MQ4 or MQ5 file of a program.
  • An executable file is created in its own closed format which hides the source algorithm of a program.
  • Compiled executable EX4/EX5 files can be distributed without source MQ4, MQ5 or MQH files. Debugging is impossible without them. It is recommended not to distribute EX4/EX5 files obtained in the result of debugging.

In order to start compilation, open the source file through the "Navigator" window and execute the "Compile Compile" command in the "File" menu or in the "Standard" toolbar, or you can press the "F7" key.

The report of the compilation process will be shown in the "Errors" tab of the "Toolbox" window. If there are no errors in this tab, you can start the program in the client terminal. Error and warning messages are marked by special icons near their descriptions:


Compilation errors are marked by Error icons both in the "Errors" tab and in the code. If such errors occur, an executable program file (*.EX4 or *.EX5) won't be generated. In order to move to the line with the error, click twice with the left mouse-button on the line, or execute the "Go to line Go to line" command in the context menu. The number of the line and column, where an error has been found, is shown in corresponding columns.

The full description of compilation errors is given in the Help topics to the MQL4/MQL5 language.

The appearance of alerts denoted by the Warning icon point to places where errors can occur. I.e. the compiler points to parts of a source code, that could be incorrectly interpreted (for example, implicit change of a value type). You can go to such code lines the same as to lines with errors.

It is possible that you do not process warnings. But it is not recommended, because they indicate potential places where errors can occur.

Besides, various informational messages are shown in the journal. They are marked by icons Information. They can show, for example, include files, to which a program referred during compilation.

An executable file (*.EX4 or *.EX5) generated after a successful compilation, is located in the same place, where the main file of the program source code (*MQ4. or *.MQ5) is located.

Compilation from the Command Line

A MetaEditor executable file can be used as the compiler when working with a source code in external editors. The compiler is started from the command line, specifying the path and name of the file you want to compile:

  • metaeditor.exe /compile:"<full path to the source file>"
  • metaeditor64.exe /compile:"<full path to the source file>"


"C:\Program Files\TradingPlatform\metaeditor64.exe" /compile:"C:\Program Files\TradingPlatform\MQL5\Scripts\myscript.mq5"

Mass compilation of files in a directory

For mass compilation, set the path to a folder rather than to a file. All source code files in the specified folder will be compiled. Subfolders are not included.

Re-compilation is not performed if a source file already has the appropriate compiled version.

The example below displays mass compilation for the \MQL5\Scripts folder.


"C:\Program Files\TradingPlatform\metaeditor64.exe" /compile:"C:\Program Files\TradingPlatform\MQL5\Scripts"

Custom MQL5/MQL4 folder with include files

Programs can use include files (*.mqh) and resource files (*.bmp, *.wav, *.ex4, *.ex5), which are located outside the working directory of the current platform. (for example, in the \MQL5 folder of another platform copy on the same computer). Specify the path to this folder using the "/include" key for correct compilation. During compilation, the files will be searched as follows:

  • Include files: [specified directory]\include\[path from #include<...>]
  • Resource files: [specified directory]\[path from #resource "..."]


"C:\Program Files\TradingPlatform\metaeditor64.exe" /compile:"C:\Program Files\TradingPlatform\MQL5\Scripts" /include:"C:\Program Files\TradingPlatform 2\MQL5"

Compilation log

Specify the additional /log key for more information about the compilation process. In this case, <source file name>.log compilation log file is created in the folder containing the source file.


"C:\Program Files\TradingPlatform\metaeditor64.exe" /compile:"C:\Program Files\TradingPlatform\MQL5\Scripts\myscript.mq5" /log
Log file: C:\Program Files\TradingPlatform\MQL5\Script\myscript.log

Syntax check

To check a program syntax without compilation, launch MetaEditor from the command line with the /s and /log keys (so that results of the check are displayed in the log file).


"C:\Program Files\TradingPlatform\metaeditor64.exe" /compile:"C:\Program Files\TradingPlatform\MQL5\Scripts\myscript.mq5" /s /log
File with the results of the check: C:\Program Files\TradingPlatform\MQL5\Script\myscript.log