MQL4 Book  Variables

Upgrade to
Book in One File


For creating programs in any algorithmic language knowing different variable types is very important. In this section we will analyze all types of variables used in MQL4.

  • Predefined Variables and RefreshRates Function.
    First of all predefined variables should be learned. Names of predefined variables are reserved and cannot be used for creating custom variables. It is predefined variables that bear the main information necessary for analyzing current market situation. For updating this information RefreshRates() function is used.
  • Types of Variables.
    Variables are very important in writing a program. They are divided into local and global, external and internal. Statistic variables preserve their values between function calls, it is useful for remembering some values of local variables without creating global variables.
  • GlobalVariables.
    Beside global variables on the level of a separate program, the values of which are available from any part of the program, there are global variables on terminal level. Such global variables are called GlobalVariables. They make it possible to establish interaction between independent parts of programs written in MQL4. They can be used for sharing values between scripts, indicators and Expert Advisors. At terminal closing values of GlobalVariables are also preserved for being available at the next MetaTrader 4 start. It must be remembered that if there were no calls to a global variable during 4 weeks, it will be deleted.
  • Arrays.
    If you need to save or process large volumes of one-type values, you cannot do without arrays. Before using an array, it should be declared like a variable. Calling of array elements is performed via specifying index(es) of an element. Array indexation starts from zero. Number of array dimensions is called dimensionality. Arrays larger than four-dimensional ones are not accepted. Array values must be clearly initialized in order to avoid difficult-to-locate errors.