how get programs version in MQL?

 

for example, i want to have a condition like this;


if (ThisIsMT5) then do1(); 

else do2();



how can i automatically determine if running platform is MT5 or MT4 (mql5 or mql5) ?

 

ENUM_TERMINAL_INFO_INTEGER

Identifier

Description

Type

TERMINAL_BUILD

The client terminal build number

int

TERMINAL_COMMUNITY_ACCOUNT

The flag indicates the presence of MQL5.community authorization data in the terminal

bool

TERMINAL_COMMUNITY_CONNECTION

Connection to MQL5.community

bool

TERMINAL_CONNECTED

Connection to a trade server

bool

TERMINAL_DLLS_ALLOWED

Permission to use DLL

bool

TERMINAL_TRADE_ALLOWED

Permission to trade

bool

TERMINAL_EMAIL_ENABLED

Permission to send e-mails using SMTP-server and login, specified in the terminal settings

bool

TERMINAL_FTP_ENABLED

Permission to send reports using FTP-server and login, specified in the terminal settings

bool

TERMINAL_NOTIFICATIONS_ENABLED

Permission to send notifications to smartphone

bool

TERMINAL_MAXBARS

The maximal bars count on the chart

int

TERMINAL_MQID

The flag indicates the presence of MetaQuotes ID data for Push notifications

bool

TERMINAL_CODEPAGE

Number of the code page of the language installed in the client terminal

int

TERMINAL_CPU_CORES

The number of CPU cores in the system

int

TERMINAL_DISK_SPACE

Free disk space for the MQL5\Files folder of the terminal (agent), MB

int

TERMINAL_MEMORY_PHYSICAL

Physical memory in the system, MB

int

TERMINAL_MEMORY_TOTAL

Memory available to the process of the terminal (agent), MB

int

TERMINAL_MEMORY_AVAILABLE

Free memory of the terminal (agent) process, MB

int

TERMINAL_MEMORY_USED

Memory used by the terminal (agent), MB

int

TERMINAL_X64

Indication of the "64-bit terminal"

bool

TERMINAL_OPENCL_SUPPORT

The version of the supported OpenCL in the format of 0x00010002 = 1.2.  "0" means that OpenCL is not supported

int

TERMINAL_SCREEN_DPI

The resolution of information display on the screen is measured as number of Dots in a line per Inch (DPI).

Knowing the parameter value, you can set the size of graphical objects so that they look the same on monitors with different resolution characteristics.

int

TERMINAL_PING_LAST

The last known value of a ping to a trade server in microseconds. One second comprises of one million microseconds

int


Please see: https://www.mql5.com/en/docs/check

Documentation on MQL5: Checkup
Documentation on MQL5: Checkup
  • www.mql5.com
Checkup - Reference on algorithmic/automated trading language for MetaTrader 5
 
selnomeria:

for example, i want to have a condition like this;

if (ThisIsMT5) then do1(); 

else do2();

how can i automatically determine if running platform is MT5 or MT4 (mql5 or mql5) ?


This can only be done at compile time via prepocessor. The platform provides for you 2 values: __MQL5__ or __MQL4__ - only one of them will be defined.

https://www.mql5.com/en/docs/basis/preprosessor/conditional_compilation

Documentation on MQL5: Language Basics / Preprocessor / Conditional Compilation (#ifdef, #ifndef, #else, #endif)
Documentation on MQL5: Language Basics / Preprocessor / Conditional Compilation (#ifdef, #ifndef, #else, #endif)
  • www.mql5.com
Language Basics / Preprocessor / Conditional Compilation (#ifdef, #ifndef, #else, #endif) - Reference on algorithmic/automated trading language for MetaTrader 5
 

found better way maybe:


int MT_version;
......
......
if (MT_version == NULL){

     if(StringFind(MQLInfoString(MQL_PROGRAM_PATH),   "MQL4",0 ) > -1 ||   TerminalInfoString(TERMINAL_NAME)=="MetaTrader 4" ) MT_version = 4;

     else if(StringFind(MQLInfoString(MQL_PROGRAM_PATH),   "MQL5",0 ) > -1 ||   TerminalInfoString(TERMINAL_NAME)=="MetaTrader 5" ) MT_version = 5;

}
//if ( MT_version ==5) {}
 

If you want a variable, you can do it like this:


enum VersionEnum
  {
  MQL4,
  MQL5   
  };

#ifdef __MQL4__
   VersionEnum MT_version = MQL4;
#else  
   VersionEnum MT_version = MQL5;
#endif

// Then in the code you can use this way:
void SomeFunc()
{
  if(MT_Version == MQL5) 

Print("5"); // Here you do something useful

}

Reason: