Problem with Calendar function

To add comments, please log in or register
Giorgio
99
Giorgio  

Hi everyone,

I can't solve this programming error: "lastTime2" and "name2" do not work (no value is assigned to them), but "lastTime1" and "name1" work. Some idea? Thank you


//Script
string name1,name2,name3;
void OnStart() 
{
   string Currency1=StringSubstr(_Symbol,0,3);
   string Currency2=StringSubstr(_Symbol,3,3);
   MqlCalendarValue values1[]; 
   MqlCalendarValue values2[]; 
   datetime date_from=TimeCurrent(); 
   datetime date_to=date_from+(3*24*60*60);
   datetime lastTime1=0;
   datetime lastTime2=0;
   datetime lastNewsTime=0;
   
   if(CalendarValueHistory(values1,date_from,date_to,NULL,Currency1)) 
   { 
      int idx = ArraySize(values1)-1;
      while (idx>=0)
      {
         MqlCalendarEvent event; 
         ulong event_id=values1[idx].event_id; 
         if(CalendarEventById(event_id,event)) 
           {
            if (event.importance>2 && event.time_mode==CALENDAR_TIMEMODE_DATETIME)
              {
               if (values1[idx].time<lastTime1||lastTime1==0)
                 {
                  lastTime1=values1[idx].time;
                  name1=event.name;
                 }
              }
           } 
         else 
            PrintFormat("Failed to get event description for event_d=%s, error %d",event_id,GetLastError()); 
         idx--;
      }
   } 
   else 
   { 
      PrintFormat("Error! Failed to receive events for country_code=%s",Currency1); 
      PrintFormat("Error code: %d",GetLastError()); 
   } 
   
   if(CalendarValueHistory(values2,date_from,date_to,NULL,Currency2)) 
   { 
      int idx = ArraySize(values2)-1;
      while (idx>=0)
      {
         MqlCalendarEvent event; 
         ulong event_id=values2[idx].event_id; 
         if(CalendarEventById(event_id,event)) 
           {
            if (event.importance>2 && event.time_mode==CALENDAR_TIMEMODE_DATETIME)
              {
               if (values2[idx].time<lastTime2||lastTime2==0)
                 {
                  lastTime2=values2[idx].time;
                  name2=event.name;
                 }
              }
           } 
         else 
            PrintFormat("Failed to get event description for event_d=%s, error %d",event_id,GetLastError()); 
         idx--;
      }
   } 
   else 
   { 
      PrintFormat("Error! Failed to receive events for country_code=%s",Currency2); 
      PrintFormat("Error code: %d",GetLastError()); 
   } 
   
   if(lastTime1<=lastTime2)
   {
      lastNewsTime=lastTime1;
      name3=name1;
      }
   else
   {
      lastNewsTime=lastTime2;
      name3=name2;
      }
   
   MqlDateTime RealLastTime;
   if(!TimeToStruct(lastTime2,RealLastTime))
      Print("ERROR: ",GetLastError());
   
   PrintFormat("%s %d %d %g %o %u",name2,RealLastTime.day,RealLastTime.mon,RealLastTime.year,RealLastTime.hour,RealLastTime.min);
} 
Seng Joo Thio
751
Seng Joo Thio  
Giorgio:

Hi everyone,

I can't solve this programming error: "lastTime2" and "name2" do not work (no value is assigned to them), but "lastTime1" and "name1" work. Some idea? Thank you


Probably no event satisfy your condition: event.importance>2 && event.time_mode==CALENDAR_TIMEMODE_DATETIME?

Giorgio
99
Giorgio  
Seng Joo Thio:

Probably no event satisfy your condition: event.importance>2 && event.time_mode==CALENDAR_TIMEMODE_DATETIME?

Thanks
To add comments, please log in or register