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:
|
To obtain an executable program file, open the main source file or project via Navigator and click 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.
If there are errors or warnings, they are displayed on the Errors tab.
Compilation errors are marked with 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 command in the context menu. The string and the column where an error is detected are displayed in the appropriate columns.
Warnings marked with 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.
icons stand for various info messages, for example, messages about include files the program accessed during compilation.
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:
The "Maximum optimization" parameter in project settings performs the same function.
|
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:
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:
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.
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 |
Restrictions: