Getting the list and descriptions of available countries

You can get a complete list of countries for which events are broadcast on the calendar using the CalendarCountries function.

int CalendarCountries(MqlCalendarCountry &countries[])

The function fills the countries array passed by reference with MqlCalendarCountry structures. The array can be dynamic or fixed, of sufficient size.

On success, the function returns the number of country descriptions received from the server or 0 on error. Among the possible error codes in _LastError we may find, in particular, 5401 (ERR_CALENDAR_TIMEOUT, request time limit exceeded) or 5400 (ERR_CALENDAR_MORE_DATA, if the size of the fixed array is insufficient to obtain descriptions of all countries). In the latter case, the system will copy only what fits.

Let's write a simple script CalendarCountries.mq5, which gets the full list of countries and logs it out.

void OnStart()
{
   MqlCalendarCountry countries[];
   PRTF(CalendarCountries(countries));
   ArrayPrint(countries);
}

Here is an example result.

CalendarCountries(countries)=23 / ok
     [id]           [name] [code] [currency] [currency_symbol]       [url_name] [reserved]
[ 0]  554 "New Zealand"    "NZ"   "NZD"      "$"               "new-zealand"           ...
[ 1]  999 "European Union" "EU"   "EUR"      "€"               "european-union"        ...
[ 2]  392 "Japan"          "JP"   "JPY"      "¥"               "japan"                 ...
[ 3]  124 "Canada"         "CA"   "CAD"      "$"               "canada"                ...
[ 4]   36 "Australia"      "AU"   "AUD"      "$"               "australia"             ...
[ 5]  156 "China"          "CN"   "CNY"      "¥"               "china"                 ...
[ 6]  380 "Italy"          "IT"   "EUR"      "€"               "italy"                 ...
[ 7]  702 "Singapore"      "SG"   "SGD"      "R$"              "singapore"             ...
[ 8]  276 "Germany"        "DE"   "EUR"      "€"               "germany"               ...
[ 9]  250 "France"         "FR"   "EUR"      "€"               "france"                ...
[10]   76 "Brazil"         "BR"   "BRL"      "R$"              "brazil"                ...
[11]  484 "Mexico"         "MX"   "MXN"      "Mex$"            "mexico"                ...
[12]  710 "South Africa"   "ZA"   "ZAR"      "R"               "south-africa"          ...
[13]  344 "Hong Kong"      "HK"   "HKD"      "HK$"             "hong-kong"             ...
[14]  356 "India"          "IN"   "INR"      "₹"               "india"                 ...
[15]  578 "Norway"         "NO"   "NOK"      "Kr"              "norway"                ...
[16]    0 "Worldwide"      "WW"   "ALL"      ""                "worldwide"             ...
[17]  840 "United States"  "US"   "USD"      "$"               "united-states"         ...
[18]  826 "United Kingdom" "GB"   "GBP"      "£"               "united-kingdom"        ...
[19]  756 "Switzerland"    "CH"   "CHF"      "₣"               "switzerland"           ...
[20]  410 "South Korea"    "KR"   "KRW"      "₩"               "south-korea"           ...
[21]  724 "Spain"          "ES"   "EUR"      "€"               "spain"                 ...
[22]  752 "Sweden"         "SE"   "SEK"      "Kr"              "sweden"                ...

It is important to note that the identifier 0 (code "WW" and pseudo-currency "ALL") corresponds to global events (concerning many countries, for example, the G7, G20 meetings), and the currency "EUR" is associated with several EU countries available in the calendar (as you can see, not the entire Eurozone is presented). Also, the European Union itself has a generic identifier 999.

If you are interested in a particular country, you can check its availability by a numerical code according to the ISO 3166-1 standard. In particular, in the log above, these codes are displayed in the first column (field id).

To get a description of one country by its ID specified in the id parameter, you can use the CalendarCountryById function.

bool CalendarCountryById(const long id, MqlCalendarCountry &country)

If successful, the function will return true and fill in the fields of the country structure.

If the country is not found, we get false, and in _LastError we will get an error code 5402 (ERR_CALENDAR_NO_DATA).

For an example of using this function, see Getting event records by country or currency.