MQL5 Economic Calendar / CalendarValueHistory in backtest - page 3

 
Enrique Dangeroux:
Do not use this code. It is very poorly written. There is a good library https://www.mql5.com/ru/code/32430 here.
I am not sure why you think it's a good library ? In my opinion it's equally "poorly written".
 
 

Hello Alain,

Unfortunately i got to the same conclusion. I am pretty new in MQL5 coding and very confused about all the curious error messages.

Meanwhile i have solved the error, mentioned in my post before. Nevertheless, when i am using the news.next Class. it doesnt show me the red line with the next upcoming news event  (in the backtester mode)

void OnTick()
  {

   //int CNews::next(int pointer_start,string currency,bool show_on_chart,long chart_id)
   
   news.next(0,_Symbol,true,ChartID());
   
  }


Do you know something that works well?  Or can you help me with this issue?


Thank You!

 
Alain Verleyen:
I am not sure why you think it's a good library ? In my opinion it's equally "poorly written".
 

Because it works, is flexible and fast. 

Granted, saber has a style of coding not everybody likes. Personally i do not see any issues with the code.

 
Enrique Dangeroux:

Because it works, is flexible and fast. 

Granted, saber has a style of coding not everybody likes. Personally i do not see any issues with the code.

Gonna side with Alain on this one. It would have been nice to see a little less overloading.
 

Is this code correct?

int idx=news.next(0,"EUR",false,0); //will fetch next news from current time

datetime time = news.event[idx].time; //gets the time of the next news found above

int imp = news.event[idx].importance; // gets the importance of the next news found above

if(imp>=2 && (time-TimeTradeServer()>0 && time-TimeTradeServer()<=checknewsduration)) return true; //if news is importance medium and above, and is within nextnewsducartion(24), do not open new trades.

 
I run news.update with a 900 sec interval in OnTick. It however only allows to re-create a FileHande for 128 times. After that the FileHandle will be -1 (and thus give errors in opening the file)
 

I am using the latest version of this code and I am getting an error that say Array out of range. I increases the size of the three array to 500000, and even larger numbers as suggested, but I still get that error. I am using the code below, which should plot the news as vertical lines...Any suggestion of how to fix this?

#include <News.mqh>

CNews news;

int OnInit()
  {
   news.GMT_offset_winter=2;
   news.GMT_offset_summer=3;
   return(INIT_SUCCEEDED);
  }
  
void OnTick()
  {
   news.update();

   static string font="Arial";
   static int fontsize=18;
   static color fontclr=clrYellow;
   chart_print("built-in TimeGMT() function: "+TimeToString(TimeGMT()),-1,-1,-1,fontsize,5,fontclr,font);
   chart_print("new.GMT() simulated GMT time: "+TimeToString(news.GMT()),-1,-1,-1,fontsize,5,fontclr,font);
   chart_print("server time: "+TimeToString(TimeTradeServer()),-1,-1,-1,fontsize,5,fontclr,font);
   int next_event=news.next(news.GMT(),"ALL");
   chart_print(" #next event (index "+IntegerToString(next_event)+"): "+news.eventname[next_event],-1,-1,-1,fontsize,5,fontclr,font);
   chart_print("event time: "+TimeToString(news.event[next_event].time),-1,-1,-1,fontsize,5,fontclr,font);
   chart_print("event sector: "+EnumToString(news.event[next_event].sector),-1,-1,-1,fontsize,5,fontclr,font);
   chart_print("affected country: "+EnumToString(ENUM_COUNTRY_ID(news.event[next_event].country_id)),-1,-1,-1,fontsize,5,fontclr,font);
   chart_print("affected currency: "+news.CountryIdToCurrency(ENUM_COUNTRY_ID(news.event[next_event].country_id)),-1,-1,-1,fontsize,5,fontclr,font);
   chart_print("event importance: "+EnumToString(news.event[next_event].importance),-1,-1,-1,fontsize,5,fontclr,font);
   chart_print("previous value: "+IntegerToString(news.event[next_event].prev_value),-1,-1,-1,fontsize,5,fontclr,font);
   chart_print("forecast value: "+IntegerToString(news.event[next_event].forecast_value),-1,-1,-1,fontsize,5,fontclr,font);
   chart_print("actual value: "+IntegerToString(news.event[next_event].actual_value),-1,-1,-1,fontsize,5,fontclr,font);
   chart_print("unit: "+EnumToString(news.event[next_event].unit),-1,-1,-1,fontsize,5,fontclr,font);
   chart_print("digits: "+IntegerToString(news.event[next_event].digits),-1,-1,-1,fontsize,5,fontclr,font);
  }
  





// AUXILIARY FUNCTION:

//+----------------------------------------------------------------------+
//| chart print: multiple text lines, optionally  with '#' as separator  |
//+----------------------------------------------------------------------+
int chart_print(string text,int identifier=-1,int x_pos=-1,int y_pos=-1,int fontsize=10,int linespace=2,color fontcolor=clrGray,string font="Arial",string label_prefix="chart_print_",long chart_id=0,int subwindow=0)
  {
   // set message identifier
   //       negative number:      set next identifier
   //       specific number >=0:  replace older messages with same identifier
   static int id=0;
   static int x_static=0;
   static int y_static=0;   
   if (identifier>=0)
     {id=identifier;}
   else
     {id++;}
   ObjectsDeleteAll(0,label_prefix+IntegerToString(id));
   
   if (text!="") //note: chart_print("",n) can be used to delete a specific message
     {
      // initialize or set cursor position
      //       keep last line feed position: set negative number for y_pos
      //       same x position as last message: set negative number for x_pos
      if (x_pos>=0){x_static=x_pos;}
      if (y_pos>=0){y_static=y_pos;}
      
      // get number of lines ('#' sign is used for line feed)
      int lines=1+MathMax(StringReplace(text,"#","#"),0);
      
      // get substrings
      string substring[];
      StringSplit(text,'#',substring);
      
      // print lines
      for (int l=1;l<=lines;l++)
        {
         string msg_label=label_prefix+IntegerToString(id)+", line "+IntegerToString(l);
         ObjectCreate(chart_id,msg_label,OBJ_LABEL,subwindow,0,0);
         ObjectSetInteger(chart_id,msg_label,OBJPROP_XDISTANCE,x_static);
         ObjectSetInteger(chart_id,msg_label,OBJPROP_YDISTANCE,y_static);
         ObjectSetInteger(chart_id,msg_label,OBJPROP_CORNER,CORNER_LEFT_UPPER);
         ObjectSetString(chart_id,msg_label,OBJPROP_TEXT,substring[l-1]);
         ObjectSetString(chart_id,msg_label,OBJPROP_FONT,font);
         ObjectSetInteger(chart_id,msg_label,OBJPROP_FONTSIZE,fontsize);
         ObjectSetInteger(chart_id,msg_label,OBJPROP_ANCHOR,ANCHOR_LEFT_UPPER);
         ObjectSetInteger(chart_id,msg_label,OBJPROP_COLOR,fontcolor);
         ObjectSetInteger(chart_id,msg_label,OBJPROP_BACK,false); 
         // line feed
         y_static+=fontsize+linespace;
        }
     } 
   return y_static;
  }
Files:
News.mqh  26 kb
 
Hey there everyone, is there anyone who can help me with this, so, i've been using this News.mqh file to fetch news and save it in to .bin and use it in backtest mode but the problem is when backtesting certain news events are missing from that file, i've noticed several events but the important event that's been missing throughout the file is the "S&P Global United States Manufacturing Purchasing Managers Index (PMI)", does anyone ever experienced this, if anyone has any fix please help.. please refer the below attached file and search the pmi event, all the pmi events are missing (for ease of use open vs code and create a new file ctrl+n and copy the contents of the below attached text file click on ctrl + f and enter the date to navigate to the date you wanna go to or search pmi to find out).
Files:
eur-usd-events.txt  2022 kb