Compiling MQL5 from the command line
MetaEditor compiles without its GUI. Run metaeditor64.exe with /compile: pointed at an .mq5 file (or a folder) and add /log to get the result in a file:
"C:\Program Files\MetaTrader 5\metaeditor64.exe" /compile:"C:\Users\you\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\MQL5\Experts\MyEA.mq5" /log
That writes MyEA.ex5 next to the source and a MyEA.log beside it with the error and warning counts. Everything else on this page is detail around those two flags.
The documented flags
MetaQuotes documents four options for command-line use, on the Integration with other IDEs page of the MetaEditor Help:
| Flag | What it does |
|---|---|
/compile:"<path>" | The file or folder to compile. Required. |
/include:"<path>" | Path to the MQL5 folder to resolve #include files and resources from. |
/log | Writes a compilation log named after the source file, in the source file's folder. |
/s | Syntax check only — reports errors without producing an .ex5. |
Quote every path. Absolute paths only: MetaEditor resolves relative paths against its own working directory, not your shell's, and the failure is silent enough to waste an afternoon.
Point /include at the right folder
Leave /include off and MetaEditor resolves includes from the data folder of the terminal it belongs to, which is what you want when your sources already live under ...\MQL5\Experts. You need it when the code sits somewhere else — a git checkout, a build agent's workspace, a shared network folder:
"C:\Program Files\MetaTrader 5\metaeditor64.exe" ^
/compile:"D:\repos\my-strategies\src\MyEA.mq5" ^
/include:"C:\Users\you\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\MQL5" ^
/log
/include takes the MQL5 folder itself, not its Include subfolder. Pointing it one level too deep is the most common reason a build fails with "cannot open include file" while the same code compiles fine by pressing F7.
Compile a whole folder
Give /compile: a directory instead of a file and MetaEditor compiles every source in it — this is what MetaQuotes calls mass compilation:
"C:\Program Files\MetaTrader 5\metaeditor64.exe" /compile:"D:\repos\my-strategies\src" /log
Handy after a batch conversion — if you've run several TradingView scripts through Convert Pine Script to MT5, drop the .mq5 files into one folder and compile them in a single pass instead of opening each one.
Reading the log
The log is written as UTF-16, so type and a plain Get-Content will show it as spaced-out characters or mojibake. Read it with the encoding stated:
Get-Content -Encoding Unicode "D:\repos\my-strategies\src\MyEA.log"
The last line carries the verdict — the number of errors and warnings. That count, not the process exit code, is what a build script should branch on: MetaQuotes doesn't document a return-code contract for the compiler, and it has varied between builds.
$log = Get-Content -Encoding Unicode "D:\repos\my-strategies\src\MyEA.log" -Raw
if ($log -notmatch '0 error') { throw "MQL5 compile failed`n$log" }
Wait for it in a script
metaeditor64.exe is a GUI application, so a shell will usually hand control straight back and your script reads a log file that hasn't been written yet. Wait for it explicitly:
Start-Process -FilePath "C:\Program Files\MetaTrader 5\metaeditor64.exe" `
-ArgumentList '/compile:"D:\repos\my-strategies\src\MyEA.mq5"', '/log' `
-Wait
In cmd.exe, the equivalent is start /wait "" "C:\Program Files\MetaTrader 5\metaeditor64.exe" .... A first run can also be slow while the compiler warms up — allow for it before you call a build hung.
Use it as the build task in another editor
Because compilation is just a process call, any editor can drive it. A minimal VS Code task:
{
"version": "2.0.0",
"tasks": [
{
"label": "MQL5: compile",
"type": "shell",
"command": "C:\\Program Files\\MetaTrader 5\\metaeditor64.exe",
"args": ["/compile:${file}", "/log"],
"group": { "kind": "build", "isDefault": true }
}
]
}
You still get MetaEditor's own error list — read the .log file it drops next to the source. Editing outside MetaEditor costs you the built-in MQL5 autocomplete and the debugger, so most people keep MetaEditor open for the debugging work and use the command line only for builds.
When it doesn't work
- Nothing happens and no log appears. The path is wrong or unquoted. Check for a stray space, and use absolute paths.
- "Cannot open include file".
/includeis missing, or points at...\MQL5\Includeinstead of...\MQL5. - The
.ex5compiles but MT5 can't see it. You compiled outside the data folder. Copy the.ex5into...\MQL5\Experts(orIndicators,Scripts) and refresh the Navigator — see how to open MetaEditor in MT5 for where those folders are. metaeditor.exeisn't found. Current MT5 ships 64-bit only: the file ismetaeditor64.exe. A plainmetaeditor.exeis MetaTrader 4's editor and compiles MQL4, not MQL5.- Portable installs. An MT5 started with
/portablekeeps itsMQL5tree next to the executable rather than under%APPDATA%, so both/compile:and/include:need those paths instead.
Next steps
- Intro to MetaEditor — the overview hub: paste code, compile, deploy
- How to open MetaEditor in MT5 — the GUI route, F7 and the Errors tab
- Downloading and installing MetaEditor 5 — where
metaeditor64.execomes from
Related guides
- Backtesting in the MT5 desktop app — run the compiled EA
- Using the Journal — runtime errors after a clean compile
- Convert Pine Script to MT5 — where the
.mq5files come from
Official reference: Integration with other IDEs and Compilation in the MetaEditor Help.