How to compile an MQL4 file using the command line tool?

I am now compiling MetaTrader files to files using . .mq4

.ex4

MetaEditor

But my files are .mq4

generated by a Java process and I would like to automate the compilation process.

Is there a command line compiler that I could call programmatic?

+5


source to share


3 answers


Yes, there is an executable file in the terminal installation directory. It's called metalang.exe.



+2


source


To compile a source code file from the command line, you can use MetaEditor to do this. For example:

metaeditor.exe /compile:"C:\Program Files\Platform\MQL5\Scripts\myscript.mq5"

      

For 64-bit, use instead metaeditor64.exe

.

On Linux / macOS this can be achieved with Wine , for example:

wine metaeditor.exe /compile:"MQL4/Experts/MACD Sample.mq4"

      

For bulk compilation, you can specify a folder, for example:

metaeditor.exe" /compile:"MQL5\Scripts"

      

To specify a custom MQL5 / MQL4 folder with included files, you can use a parameter /inc

, for example:

metaeditor.exe /compile:"./Scripts" /inc:"C:\Program Files\TradingPlatform 2\MQL5"

      

For more information on the compilation process, you can use /log

:

metaeditor.exe /compile:"C:\Program Files\Platform\MQL5\Scripts\myscript.mq5" /log 

      

To check only the syntax, add extra /s

.

If the compilation fails, a file MQL4.log

will be created in the platform folder with the appropriate details. It will be in UTF-16 format, so you may need a special tool for it (like Vim, Ruby , or ). findstr

rg

To specify a custom compilation log file, use an option /log:file.log

such as



metaeditor.exe /log:errors.log /compile:.

      

Note. Mapping to standard output is not supported (although on Linux you can use:) /log:CON

.

For more information, check: Compiling from the command line


Some time ago you could download the compiler for MQL4 / MQL5 programs, which runs separately from MetaEditor - MQL.exe

. It was distributed separately from the terminal, and you can download it from the following addresses:

https://download.mql5.com/cdn/web/metaquotes.software.corp/mt5/mql.exe

https://download.mql5.com/cdn/web/metaquotes.software.corp/mt5/mql64.exe

Usage (according to MQL4 / MQL5 Compiler build 1162 dated July 02, 2015):

mql.exe [<flags>] filename.mq5
        /mql5     - compile mql5 source
        /mql4     - compile mql4 source
        /s        - syntax check only
        /i:<path> - set working directory
        /o        - use code optimizer

      

However, the standalone compiler has been intentionally removed, so the links now point to the installer in favor of MetaEditor.


A much older version of MetaTrader before build 600 included the metalang.exe

included in the platform.

However, in build 616, MetaQuotes intentionally removed the compiler ( mql.exe

/ mql64.exe

) from the standard MetaTrader installation.

This means that if you upgrade your MT platform (> 616), the compiler executable will be removed.

+19


source


It's a bit late, but since I wrote a little script for UltraEdit / UEStudio and got a bunch of help from stackoverflow, here's my script. It then compiles an ex4 instance for multiple test installations of MT4:

The "Compile" button on the UE does:

"MT4Compile.bat" "%FilePath" "%FileName"
Start in path eg: D:\Development\MQ4 (Location of MT4Compile.bat)

      

Usually my source code is in the library tree at D: \ Development \ MQ4 [Group] [ExpertName] [FileName] .mq4

Content of D: \ Development \ MQ4 \ MT4Compile.bat:

@echo off
rem Version: 1.1
rem Date:   24 Sep 2013
rem Author: Shawky
rem Refer to HELP: for info

SET XC=xcopy /D /Y /V /F /I
SET PROGDIR=D:\Development\Go Pro Demo (MQ4 Testing)
SET DSTPATH=%PROGDIR%\experts

SET SIMPATH1=G:\Apps\MT4\BackTest IC (Recent)\experts
SET SIMPATH2=G:\Apps\MT4\BackTest IC (All)\experts
SET SIMPATH3=G:\Apps\MT4\BackTest Go (All)\experts
SET DEPLOYPATH=D:\Development\Deployment\experts

SET SRCPATH=%1
SET SRCPATH=%SRCPATH:"=%
IF "%SRCPATH%"=="" (
    SET SRCPATH=[Arg1]
)

SET APPNAME=%2
SET APPNAME=%APPNAME:"=%
IF "%APPNAME%"=="" (
    SET APPNAME=[Arg2]
)

SET SRCFILE=%APPNAME%.mq4
SET DSTFILE=%APPNAME%.ex4


SET CMD="%PROGDIR%\metalang.exe" "%SRCFILE%" "%DSTFILE%"

IF "%SRCPATH%"=="[Arg1]"  GOTO HELP
IF "%APPNAME%"=="[Arg2]"  GOTO HELP

cd %SRCPATH%

IF NOT EXIST "%SRCFILE%"  (
    SET ERROR=Error: File "%SRCFILE%" does not exist in %SRCPATH%
    GOTO HELP
)

echo .
echo Compiling %SRCFILE% to %DSTPATH%\%DSTFILE%
echo .
DEL *.log
%CMD%
IF EXIST "%DSTFILE%" (
    echo .
    echo Distributing executable to SIM and Deployment paths
    %XC% "%DSTFILE%" "%DSTPATH%\"
    IF EXIST "%SIMPATH1%"   %XC% "%DSTFILE%" "%SIMPATH1%\"
    IF EXIST "%SIMPATH2%"   %XC% "%DSTFILE%" "%SIMPATH2%\"
    IF EXIST "%SIMPATH3%"   %XC% "%DSTFILE%" "%SIMPATH3%\"
    IF EXIST "%DEPLOYPATH%" copy /B /Y "%DSTFILE%" "%DEPLOYPATH%\%APPNAME% (Dev).ex4"
)

goto END

:HELP
echo .  Metatrader 4 Command Line utility for compiling MT4 programmes.
echo .
echo .  This batch files allows MT4 applications to be compiled from a directory other than .\experts.
echo .  The output will be copied to experts after compilation.
echo .
echo .  [Arg1] = Path to MT4 application directory
echo .  [Arg2] = Name (without extension) of the main MQ4 source code to compile.
echo .
echo .  Example:
echo .      MT4Compile.bat "D:\Development\MQ4\MyExpert\" "PrimaryMQ4FileName"
echo .
echo .  Programme Directory: %PROGDIR%
echo .  Source Path:         %SRCPATH%
echo .  Source File:         %SRCFILE%
echo .  Destination File:    %DSTFILE%
echo .  Target Path:         %DSTPATH%
echo .
echo .  Argument 1:          %SRCPATH%
echo .  Argument 2:          %APPNAME%
echo .
echo .  Commands to execute would be:
echo .
echo .      %CMD%
echo .      %XC% "%DSTFILE%" "%DSTPATH%\"
echo .
echo .  %ERROR%
echo .

pause

:END

      

All the best.

Shawky

+4


source







All Articles