MetaEditor (MT5)

Compiling MQL5 from the command line

metaeditor64.exe /compile — flags, logs, and build scripts

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:

FlagWhat 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.
/logWrites a compilation log named after the source file, in the source file's folder.
/sSyntax 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.

/s is the flag you want in a pre-commit hook or a pull-request check. It gives you the same error list without leaving a stale .ex5 on disk when the build fails halfway.

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". /include is missing, or points at ...\MQL5\Include instead of ...\MQL5.
  • The .ex5 compiles but MT5 can't see it. You compiled outside the data folder. Copy the .ex5 into ...\MQL5\Experts (or Indicators, Scripts) and refresh the Navigator — see how to open MetaEditor in MT5 for where those folders are.
  • metaeditor.exe isn't found. Current MT5 ships 64-bit only: the file is metaeditor64.exe. A plain metaeditor.exe is MetaTrader 4's editor and compiles MQL4, not MQL5.
  • Portable installs. An MT5 started with /portable keeps its MQL5 tree next to the executable rather than under %APPDATA%, so both /compile: and /include: need those paths instead.

Next steps

Official reference: Integration with other IDEs and Compilation in the MetaEditor Help.