Библиотеки: Calendar - страница 6

 
Automated Trading :

Calendar :

Author: fxsaber

Thanks fxsaber,
This library is so great. 
May I ask would the.bin file be readable by notepad++? The file created by my EA is not readble by notepad++, and during BT, the calendar.Load returns nothing. Do you have any hint on this? 

Thanks
 
eepatk #:
May I ask would the.bin file be readable by notepad++? The file created by my EA is not readble by notepad++, and during BT, the calendar.Load returns nothing. Do you have any hint on this? 

It is better to immediately formulate what the task is.

 
fxsaber # :

It is better to immediately formulate what the task is.

Sorry fxsaber, let me clarify.

Basically, I start with the example code you shared, I am able to download and create a .bin file.

I am trying to code the below for Backtest, objective is to load the .bin in every iteration, so as to check for news/events of each currency listed in the class.

However, when I am doing backtesting, The Calendar.ToString returned blank.(the "Print" are for debugging)


thanks,

 if ( MQLInfoInteger ( MQL_TESTER )) 
 {
    NF_Stopped_CCY="";  
      for(int i=0;i<8;i++)        
        {
                Calendar.Load(CALENDAR_FILENAME);
                Print("Raw",Calendar.ToString(0,10,false));  

                Calendar.FilterByTime(TimeCurrent()-NF_Stop_in_Days*24*60*60,TimeCurrent()+NF_Stop_in_Days*24*60*60);
                Print("FilterByTime",Calendar.ToString(0,10,false));  

                Calendar.FilterByCurrency(CCYP[i].Cname);
                Print("FilterByCCY",Calendar.ToString(0,10,false));  

                Calendar.FilterByImportance(NF_Stop_Importance);  
                Print("FilterByImp",Calendar.ToString(0,10,false));  
 
                          
                CCYP[i].Stop_By_News=Calendar.GetAmount();
                if (CCYP[i].Stop_By_News) 
                {
                  int temp=StringConcatenate(NF_Stopped_CCY,NF_Stopped_CCY," ", CCYP[i].Cname);
                  Print(Calendar.ToString(0,-1,false));  
                }
        } 
   Print("NF list(BackTest)   :",NF_Stopped_CCY);
   NEWS_RefreshTime.day =CurrentDay.day;
  }
 
eepatk #:

I am trying to code the below for Backtest, objective is to load the .bin in every iteration, so as to check for news/events of each currency listed in the class.

You only need to load the data from the file into a static variable once.

#define CALENDAR_FILENAME "Calendar.bin" // Название файла для чтения/записи Календаря.
#property tester_file CALENDAR_FILENAME  // Указание, чтобы MT5-Тестер подхватывал данный файл.

#include <fxsaber\Calendar\Calendar.mqh> // https://www.mql5.com/ru/code/32430

CALENDAR CalendarFull; // Объект с данными календаря.

int OnInit()
{      
  return(CalendarFull.Load(CALENDAR_FILENAME) == -1); // Загрузили события из файла
}

void OnTick()
{
  CALENDAR Calendar = CalendarFull;
  
  //....
}
 
fxsaber # :

You only need to load the data from the file into a static variable once.


Thanks a lot, it is nice and precise.

 
fxsaber # :

You only need to load the data from the file into a static variable once.

Thanks fxaber,

I was able to tidy up the code with your suggestion, but still, the CalendarFULL is also empty after loading the .bin.

the CalendarFULL.Load does return a "1", but there seems nothing inside CalendarFULL.

Would it be some sort of encoding issue of the .bin?

THanks

 
eepatk #:

the CalendarFULL.Load does return a "1", but there seems nothing inside CalendarFULL.

Run this script once in the MT5-terminal to generate the bin-file.

#define CALENDAR_FILENAME "Calendar.bin" // Название файла для чтения/записи Календаря.

#include <fxsaber\Calendar\Calendar.mqh> // https://www.mql5.com/ru/code/32430

void OnStart()
{
  CALENDAR Calendar;

  if (Calendar.Set(NULL, CALENDAR_IMPORTANCE_NONE, 0, 0)) // Загрузили абсолютно все события (история + будущее) из MT5-Терминала.
    Calendar.Save(CALENDAR_FILENAME);                     // Сохранили их в файл.
}
 
fxsaber # :

Run this script once in the MT5-terminal to generate the bin-file.

Thanks fxsaber, I did that and it did generate a 7xmb .bin file. However, still once I attempt to load and print out, it returned blank. 
 
eepatk #:
Thanks fxsaber, I did that and it did generate a 7xmb .bin file. However, still once I attempt to load and print out, it returned blank. 
#define CALENDAR_FILENAME "Calendar.bin" // Название файла для чтения/записи Календаря.
#property tester_file CALENDAR_FILENAME  // Указание, чтобы MT5-Тестер подхватывал данный файл.

#include <fxsaber\Calendar\Calendar.mqh> // https://www.mql5.com/ru/code/32430

const string inSymbols[] = {"EURUSD", "AUDCAD"};

CALENDAR Calendars[];

int OnInit()
{      
  CALENDAR Calendar;
  const bool Res = (Calendar.Load(CALENDAR_FILENAME) != -1);

  if (Res)
    for (int i = ArrayResize(Calendars, ArraySize(inSymbols)) - 1; i >= 0; i--)
    {
      Calendars[i] = Calendar;
      
      Calendars[i].FilterBySymbol(inSymbols[i]);
    }

  return(!Res);
}

string NewsToString( const CALENDAR &Calendar, const datetime From, const datetime To )
{
  CALENDAR CalendarTmp = Calendar;
  
  CalendarTmp.FilterByTime(From, To);
  
  return(CalendarTmp.ToString(0, 10));
}

#define HALF_INTERVAL (6 * 3600)

void OnTick()
{  
  string Str = NULL;
  
  for (int i = ArraySize(Calendars) - 1; i >= 0; i--)
  {
    const datetime From = TimeCurrent() - HALF_INTERVAL;
    const datetime To = TimeCurrent() + HALF_INTERVAL;
    
    Str += "\n\n" + inSymbols[i] + "-news (" + (string)From + " - " + (string)To + "):\n" + NewsToString(Calendars[i], From, To);
  }
  
  Comment(Str);
}

 
fxsaber #:

Thanks fxsaber,

Eventually, I found out the problem with my code, my .mq5 was saved as Unicode somehow, that made the fileread didnt work, once I change it to ANSI, it works.


Thanks,