MQL4 Reference

MQL4 Basics:Syntax

MetaQuotes Language 4 (MQL4) is a new integrated language for programming of trading strategies. This language allows users writing of their own programs (Expert Advisors) that automate trading management and ideally suit for implementing of their own trading strategies. Besides, one can create one’s own technical indicators (Custom Indicators), scripts, and libraries in MQL 4.

Syntax of MQL4 is much a C-like syntax, apart from some features:

  • no address arithmetic;
  • no operator do … while;
  • no operator goto …;
  • no operation of [condition]?[expression 1]:[expression 2];
  • no compound data types (structures);
  • complex assignments are impossible; for example, val1=val2=0; arr[i++]=val; cond=(cnt=OrdersTotal)>0; etc.;
  • calculation of a logical expression is always completed, never early terminated.



Multiline comments start with /* symbols and end with */ symbols. Such comments cannot be nested. Single comments start with // symbols, end with the symbol of a new line and can be nested into multiline comments. Comments are allowed where blank spaces are possible and tolerate any number of spaces.


// single comment
/*  multi-
    line         // nested single comment



Identifiers are used as names of variables, functions, and data types. The length of an identifier cannot exceed 31 character.

Symbols you can use: numbers from 0 to 9, Latin capital and small letters a to z, A to Z (recognized as different symbols), the symbol of underlining (_). The first symbol cannot be a number. The identifier must not coincide with any reserved word.


NAME1 namel Total_5 Paper


Reserved words

The identifiers listed below are fixed reserved words. A certain action is assigned to each of them, and they cannot be used for other purposes:

Data types Memory classes Operators Other
bool extern break false
color static case true
datetime   continue  
double   default  
int   else  
string   for  
void   if  
This article url:

Please login to post comment, if you haven't account you can register free