How to take trade only on those days which have some upcoming highly impactful economic news ?

 
I want to program an EA in mql5 which could check if there is highly impactful economic event relating to a currency on current day, and then take trade. I am stuck on how to achieve this. Can anyone help?
 

Here: https://www.mql5.com/en/docs/calendar

you have all the function to find when what kind of events are coming up.

Some have examples to copy and paste.

Documentation on MQL5: Economic Calendar
Documentation on MQL5: Economic Calendar
  • www.mql5.com
Economic Calendar - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

Hello sir,

I am facing difficulty in accessing date range and importance together. I can get importance of events but can't filter them for current days event only. Also, I can get current days event, but then i can't access the importance of the event. I am attaching my piece of code. Can you find errors and correct me? I would be really grateful.

Here, I was trying to set the value of global variable if_event as true if there is event with high importance in current day.


 MqlDateTime time;

     TimeToStruct(TimeCurrent(),time);

     int currentDay= time.day;

     int currentMonth= time.mon;

     int currentYear= time.year;

     

     MqlDateTime from_to;

     TimeCurrent(from_to);

     from_to.day = currentDay;

     from_to.mon = currentMonth;

     from_to.year = currentYear;

     datetime from_to_date = StructToTime(from_to);

     

     MqlCalendarEvent events[];

     ulong event_imp;

     ulong event_id;

     int event_count = CalendarEventByCurrency("USD",events);

     if (event_count > 0){

     ArrayResize(events,15);

     }

     for(int i=0; i<=15; i++){

     event_imp = events[i].importance;

     event_id = events[i].id;}

     

     MqlCalendarValue values[];

     if(CalendarValueHistoryByEvent(event_id,values,from_to_date,from_to_date)){

     if(event_imp = CALENDAR_IMPORTANCE_HIGH){

     if_event = true;

     }else {if_event = false;}

     }

Carl Schreiber #:

Here: https://www.mql5.com/en/docs/calendar

you have all the function to find when what kind of events are coming up.

Some have examples to copy and paste.

Reason: