Enumerations
Enumerations in MQL4 define a custom, limited set of data values using named constants. They introduce a new 4-byte integer-valued data type.
Syntax
enum
{
};
is a comma-separated list of identifiers (named constants).Value Assignment
0. Subsequent members increment by one from the previous member.Example 1 (Automatic Assignment)
enum months
{
January, // 0
February, // 1
March, // 2
April, // 3
May, // 4
June, // 5
July, // 6
August, // 7
September, // 8
October, // 9
November, // 10
December // 11
};
Example 2 (Explicit and Automatic Assignment)
enum intervals
{
month=1, // Interval of one month
two_months, // Two months (value 2)
quarter, // Three months - quarter (value 3)
halfyear=6, // Half a year
year=12 // Year - 12 months
};
Key Characteristics and Constraints
sizeof(months) returns 4).enum keyword; anonymous enumerations are not permitted (unlike C++).Related Topics
Previous
arrow_back
Bool type