Source code
How to Compile MQL5 Source Code in MetaEditor
To compile an MT5 EA, open its main MQ5 source in MetaEditor, make its required dependencies available and choose Compile. Read the output before using the resulting EX5. Compilation checks the build; it does not test the strategy's behavior.
Prepare a reproducible workspace
Keep the delivered archive unchanged and work from a copy. Record the source release and your MetaTrader/MetaEditor build. If you have several broker terminals, decide which installation will be used for this test before placing files.
Use that terminal's File → Open Data Folder command to locate its working folders. For an EA, the normal location is inside MQL5/Experts/; follow the package instructions for includes and other dependencies. MetaQuotes documents the folder roles in its environment structure guide.
Create a short build note now, while the details are obvious. It should identify the package, main file, destination terminal and any manual changes. This prevents a common debugging dead end: finding a working EX5 later without knowing which source produced it.
Open the main file and compile
Open the main .mq5 file in MetaEditor and choose Compile or press F7. Read the Errors tab. A failed compilation does not create a new executable, while warnings can still accompany an executable. See the official compilation instructions.
Do not open a helper include and assume you have built the whole EA. Also check the exact file path in the editor: two files with identical names can exist in different project folders.
Handle diagnostics without changing the strategy blindly
| Observation | Next check |
|---|---|
| Missing include or library | Compare the path with the delivery inventory before editing references. |
| Unknown name or function | Check the platform, dependencies and supported build. |
| Type-conversion warning | Inspect whether a value could be rounded, truncated or misinterpreted. |
| Many errors after one edit | Start with the earliest relevant diagnostic and compare with your untouched copy. |
Removing a line simply because it triggers an error can remove part of the program's behavior. If you cannot explain the intended fix, keep the original file and send the diagnostic to support. Include the full message, file name and line number rather than only “it doesn't compile”.
Confirm which executable you will test
After success, check the resulting EX5's location and modification time, then select that EA in the intended terminal. A stale EX5 from a previous build can otherwise make a broken edit appear to work. MetaQuotes also describes the edit/build/run sequence in MQL5 Programming for Traders.
Keep a build record beside the test record. For your own experiments, a simple suffix such as demo-check-01 is clearer than repeatedly overwriting a file called “final”. Preserve both the changed source and the settings used for each meaningful comparison.
What to do after a clean build
- Run a short historical test to check startup and expected inputs.
- Review the tester log for initialization and runtime problems.
- Inspect individual entries, exits and position sizes.
- Expand to a documented historical test, then a demo observation period.
No-error compilation is one checkpoint. It does not establish correct order handling, restart behavior or profitability. Continue with the MT5 backtesting workflow and preserve your baseline before modifying the code again.
Back to top