Dear MQL5 community,
I am using the MQL5 calender function directly from the Metatrader platform and I have the following issue:
Currently, I am using this specific code to get the required calender events ( The variable "EU_code" is an input variable and can be "WW", "EU", "US", "JP" etc. ):
Now to the problem: For some specific brokers (live account), there is the following error message:
"Error! Failed to receive events for country_code=US"
"Error code: 4011"
This can happen to "US", "JP", "AU" and so on.
Why is that and what can I do against it?
Thank you in advance for your reply!
Currently, I am using the code as follows:
int OnInit() { ... if(News_WW == true) myNews("WW"); if(News_EU == true) myNews("EU"); if(News_US == true) myNews("US"); if(News_JP == true) myNews("JP"); ... } void OnTick() { ... if(News_WW == true) myNews("WW"); if(News_EU == true) myNews("EU"); if(News_US == true) myNews("US"); if(News_JP == true) myNews("JP"); ... } void myNews(string EU_code) { //--- Events MqlCalendarEvent events[]; int events_count=CalendarEventByCountry(EU_code,events); ArrayResize(Array_event_id,events_count); ArrayResize(Array_event_name,events_count); ArrayResize(Array_event_importance,events_count); if(events_count > 0) { for(int i = 0; i < events_count; i++) { Array_event_id[i] = events[i].id; Array_event_name[i] = events[i].name; Array_event_importance[i] = events[i].importance; } } else { PrintFormat("Error! Failed to receive events for country_code=%s",EU_code); PrintFormat("Error code: %d",GetLastError()); } //--- Values MqlCalendarValue values[]; //--- set the boundaries of the interval we take the events from ulong values_id; datetime date_from = TimeTradeServer() - (0 * 604800 + 3 * 86400); datetime date_to = TimeTradeServer() + (0 * 604800 + 3 * 86400); if(CalendarValueHistory(values,date_from,date_to,EU_code)) { ... } }
As stated above, "News_WW", "News_EU" etc. is an input variable.
Basically, I am calling the function within OnInit and later also in OnTick. However, within OnTick, I am calling the function only every new M15 bar (to get an update for the newest news, see variable date_from and date_to).
The interesting fact is that sometimes, if switching the timeframe in the current symbol (where the EA initializes again), the error does not occur again. But I have to change the timeframe sometimes 4 or 5 times until the error does not occur again.
What do you think, what could be the reason for that?
@Lorentzos Roussos What do you mean with "manage the requests , know what you've pulled"?
![Dominik Egert Dominik Egert](https://c.mql5.com/36/83/dominik-egert.jpg)
Thanks a lot @Dominik Egert and @Lorentzos Roussos for your feedback.
Currently, I am using the code as follows:
As stated above, "News_WW", "News_EU" etc. is an input variable.
Basically, I am calling the function within OnInit and later also in OnTick. However, within OnTick, I am calling the function only every new M15 bar (to get an update for the newest news, see variable date_from and date_to).
The interesting fact is that sometimes, if switching the timeframe in the current symbol (where the EA initializes again), the error does not occur again. But I have to change the timeframe sometimes 4 or 5 times until the error does not occur again.
What do you think, what could be the reason for that?
@Lorentzos Roussos What do you mean with "manage the requests , know what you've pulled"?
"Error code: 4011"
This can happen to "US", "JP", "AU" and so on.
Why is that and what can I do against it?
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I am using the MQL5 calender function directly from the Metatrader platform and I have the following issue:
Currently, I am using this specific code to get the required calender events ( The variable "EU_code" is an input variable and can be "WW", "EU", "US", "JP" etc. ):
Now to the problem: For some specific brokers (live account), there is the following error message:
"Error! Failed to receive events for country_code=US"
"Error code: 4011"
This can happen to "US", "JP", "AU" and so on.
Why is that and what can I do against it?
Thank you in advance for your reply!