Compilation in MQL5
Watch on YouTube: Compilation in MQL5: Step-by-Step Guide
Compilation in MQL5 follows a similar process to MQL4, but it generates a .ex5 file instead of .ex4. In MetaEditor, you write your code for Expert Advisors (EAs), scripts, or indicators and then compile it. The compiler checks for syntax errors, and if successful, it generates the .ex5 file, which is used by MetaTrader 5. Compilation errors must be fixed before successful deployment.
Here’s a simple script example:
void OnStart()
{
Print("Hello, MetaTrader 5!"); // Prints a message "Hello, MetaTrader 5!"
}To compile:
- Write the code in MetaEditor.
- Press F7 to compile. Errors will show in the “Errors” tab.
- After resolving errors, the compiled
.ex5file will appear in the MetaTrader 5 Navigator (Ctrl+N) under Scripts. To execute it, either right-click and select Attach to Chart or double-click the script file.
To access the file folder:
- Open MetaEditor.
- Navigate to the file (Script_01), then right-click and select Open Data Folder.
- The compiled .ex5 file will be inside the folder as well as the source code file (.mq5 extension).
Conclusion
In conclusion, after compiling your code without errors, the resulting .ex5 file is ready for use in MetaTrader 5. This file can be executed from the appropriate folder within the MT5 Navigator, such as “Experts” for Expert Advisors or “Indicators” for custom indicators.
