News error from MqlCalenderEvent

 
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. ):

      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());
         }

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!
 
Trader_RM:
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!
The built-in EC is independent of the broker, except for the time offset.

Can you specify the problem in such way that it can be reproduced??? Please try to not mention brokers, if that is possible.


 

Pull the countries list for those specific brokers and check their region codes 

Also if i recall correctly , it is not working at once , you have to "load balance" it. I.e manage the requests , know what you've pulled . Once you do however it will be in the cache forever 

 
Thanks a lot @Dominik Egert and @Lorentzos Roussos for your feedback.

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
  • 2024.01.28
  • www.mql5.com
Trader's profile
 
Trader_RM #:
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"?


Referring to this question:

"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?

You need to handle the situation where the data you are requesting is not available, thus you need to handle the error properly.

I implemented the full calendar functionality, and it requires quite some error handling to get the data you request. But I was able to make it all work reliable, but I have to admit, I only tested with a few brokers, because of time zone stuff... There is no correlation between EC and broker beyond time zone, as far as I am aware.