Libraries: Calendar - page 4

 
fxsaber:

This is not done. Contact a specialist.

Sure, I just realised what you mean. Thanks
 
I noticed backtesting seems to be limited to about 5 years (from 2017 onwards), even though all news events are dowloaded correcly (BIN file is 67mb). Is there a limit to how many events MT5 can handle in memory for backtesting?
 
mqtrader #:
I noticed backtesting seems to be limited to about 5 years(from 2017 onwards), even though all news events are dowloaded correcly (BIN file is 67mb). Is there a limit to how many events MT5 can handle in memory for backtesting?
#property script_show_inputs

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

input bool inFromFile = false;

#define  CALENDAR_FILENAME "Calendar.bin" // File name for reading/writing the Calendar.

void OnStart()
{
  CALENDAR Calendar;
  
  if (inFromFile)
    Calendar.Load(CALENDAR_FILENAME);
  else
  {
    Calendar.Set(NULL, CALENDAR_IMPORTANCE_NONE, 0, INT_MAX); // Took the WHOLE calendar.
    Calendar.Save(CALENDAR_FILENAME); // > > 65 MB.
  }
  
  Print(Calendar[0].ToString());
}


Result.

2007.01.06 23:30 USD 1 CFTC Crude Oil Non-Commercial Net Positions(cftc-crude-oil-non-commercial-net-positions), United States(US) | 2.2 K |  | 19.8 K | 

The first event in the calendar database is January 2007.

 
I just realised that the "Forecast" values start from 2017.05.05, which is why the backtest can only start from that date when running the example. Other values can be used prior to that date.

Thank you once more fxsaber for this very useful library!
 

calendar of events is prescribed significantly forward into the future. That's why you can use a reminder in MT4, having saved a file from MT5 data beforehand (a month before, for example).

This is what I do for MT4.

Steps for working with the calendar in MT4.


1. Run a script in MT5 that will save the calendar to a Common file.

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

#define  CALENDAR_FILENAME "Calendar.bin" // File name for reading/writing the Calendar.

void OnStart()
{
  CALENDAR Calendar;
  
  Calendar.Set(NULL, CALENDAR_IMPORTANCE_NONE, 0, INT_MAX); // Took the WHOLE calendar.
  Calendar.Save(CALENDAR_FILENAME, true); // Recorded calendar. > 65 MB.
}


2. Load the calendar from the Common file into MT4.


As an example below is a reminder of important events on currencies of the current symbol, working in MT4.

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

#define  CALENDAR_FILENAME "Calendar.bin" // File name for reading/writing the Calendar.

int OnInit()
{
  return(!EventSetTimer(1));
}

void OnTimer()
{
  static CALENDAR Calendar;

  if (Calendar.GetAmount()) // If the calendar is not empty.
  {
    static int Pos = 0;
    
    Pos = Calendar.GetPosAfter(TimeCurrent(), Pos); // Found Future Events.
    
    Comment(Calendar.ToString(Pos, 5, true)); // Printed them out.
  }
  else if (Calendar.Load(CALENDAR_FILENAME, true)) // Loaded the calendar from a file.
  {
    string Currencies[2];
    
    // Get the currencies of the current character.
    Currencies[0] = ::SymbolInfoString(_Symbol, SYMBOL_CURRENCY_BASE);
    Currencies[1] = ::SymbolInfoString(_Symbol, SYMBOL_CURRENCY_PROFIT);
          
    Calendar.FilterByCurrency(Currencies); // Left the events on the currencies of the symbol.
    Calendar.FilterByImportance(CALENDAR_IMPORTANCE_HIGH); // Only the important events were left behind.
  }    
}


After launching we have a chart updated (countdown) reminder of important events on the currencies of the symbol directly in MT4.


Similarly Calendar can work in MT4-Tester.

 
Mark Taylor #:

I keep hitting an issue though, I do the standard download of the calendar file

then set a starttime and get events after this time in a loop for each currency.

Try to paste the sources so that they can be read.

 

Thanks for the strong labours useful stuff.

Of course, such works should be developed and corrected and describe the documentation, the whole community and not just one person. But for some reason the administration itself does not give such provisions as well as does not insert a link to the same GitHub, for proper organisation. Although there are projects, their use, almost the same GitHub.

Thank you! for the code, it is very interesting to read such code, honestly: overloading templates lack of comments )) what is worth this creativity, 5 minutes thought what is it? an instance of a class or an array with data. In general, everything for brain development.
CALENDAR Calendar;
Calendar[i].time
The work is certainly cool, you should only understand how it works
 

It would be nice if the function sorted by time the whole array after merging

int operator +=( const CALENDAR &Value )
  {
    const int Size1 = this.GetAmount();
    const int Size2 = Value.GetAmount();

    if (!Size1)
      for (int i = ::ArrayResize(this.Events, Size2) - 1; i >= 0; i--)
        this.Events[i] = Value.Events[i];
    else if (Size2)
    {
      EVENT Array[];

      ::ArrayResize(Array, Size1 + Size2);

      int i = 0;
      int j = 0;
      int k = 0;

      while ((i < Size1) && (j < Size2))
        Array[k++] = (this.Events[i] < Value.Events[j]) ? this.Events[i++] : Value.Events[j++];

      while (i < Size1)
        Array[k++] = this.Events[i++];

      while (j < Size2)
        Array[k++] = Value.Events[j++];

    #ifdef __MQL5__
      ::ArraySwap(this.Events, Array);
    #else // #ifdef __MQL5__
      ::ArrayFree(this.Events);

      ::ArrayCopy(this.Events, Array);
    #endif // #ifdef __MQL5__ #else
    }

    return(this.GetAmount());
  }
bool operator <( const EVENT &Value ) const
  {
    return(!Value.time || (this.time < Value.time));
  }
 
BillionerClub #:

It would be nice if the function sorted by time the whole array after merging

Give an example where it doesn't do that.

 
fxsaber #:

Give me an example where this is not the case.

Your code is hard to understand, but I assume that there is a final sorting in the code above, but the code is probably in error. Not often, but when merging arrays, the final array comes with errors in the form of lack of sorting, because the most recent elements in the array should have a longer period of time.

2022.11.04 07:05:33.053 EventsManager (FUTSP500CONT,M15)        2022.11.04 08:00
2022.11.04 07:05:33.053 EventsManager (FUTSP500CONT,M15)        2022.11.04 13:30
2022.11.04 07:05:33.053 EventsManager (FUTSP500CONT,M15)        2022.11.04 16:30
2022.11.04 07:05:33.053 EventsManager (FUTSP500CONT,M15)        2022.11.04 20:00
2022.11.04 07:05:33.053 EventsManager (FUTSP500CONT,M15)        2022.11.05 00:00
2022.11.04 07:05:33.053 EventsManager (FUTSP500CONT,M15)        2022.11.07 00:00
2022.11.04 07:05:33.053 EventsManager (FUTSP500CONT,M15)        2022.11.04 00:30
2022.11.04 07:05:33.053 EventsManager (FUTSP500CONT,M15)        2022.11.04 00:30
2022.11.04 07:05:33.053 EventsManager (FUTSP500CONT,M15)        2022.11.04 00:30
   int totall = Calendar+=Calendar3;

for(int i=0;i<totall;i++)
  {
   Print(TimeToString(Calendar[i].time));
  }