Libraries: Calendar - page 8

 
AdrianR007 #:
I am using the code from your example but the current value is not being updated when the event occurs. Any suggestion about it?

This example was made to demonstrate how the calendar works in Tester. It comes with this instruction.

Run it once in MT5-Terminal to save all historical data (~60 Mb). After that they will be available in the Tester.

Unfortunately, you keep making inarticulate statements, taking my time to hypothesise "what did he mean?".

 
fxsaber #:

This example was made to demonstrate how the calendar works in Tester. It comes with the following instructions.

Unfortunately, you keep making inarticulate statements, taking my time to hypothesise "what did he mean by that?".

At the instant the news occurs, the Current value is not being updated with respect to the expected value, therefore the operation is not executed. I'm talking about the operation in a news item in real time and not in a test. In test mode it works very well.
 
AdrianR007 #:
At the instant the news occurs, the Current value is not being updated with respect to the expected value, therefore the operation is not executed. I'm talking about the operation in a news item in real time and not in a test. In test mode it works very well.

Forum on trading, automated trading systems and testing trading strategies.

Libraries: Calendar

BillionerClub, 2023.02.23 19:35

it's not self refreshing library, use id, from calendar, for obtaining fresh data from mql5.


 
Enrique Dangeroux #:

Thanks Enrique. Maybe you have an example to do this?
 
AdrianR007 #:
Thanks Enrique. Maybe you have an example to do this?

I do not have time to give basic coding lesson. Either read the documentation or ask on the forums.

On a side note. If you want to trade the news, the MQL calendar is useless. There are delays from seconds, minutes even hours.

 
AdrianR007 #:
At the instant the news occurs, the Current value is not being updated with respect to the expected value, therefore the operation is not executed. I'm talking about the operation in a news item in real time and not in a test. In test mode it works very well.

I don't know what you are running. Regarding calendar data updates, read the following discussion.


The library provides only the data that is available in the Calendar tab.

MetaTrader5 calendar updates - I'm looking to improve my news trading robot for MT5 platform calendar updates: Is it possible the same broker-by-broker
MetaTrader5 calendar updates - I'm looking to improve my news trading robot for MT5 platform calendar updates: Is it possible the same broker-by-broker
  • 2022.07.14
  • www.mql5.com
I would like to ask about mt5 platform calendar updates: is platform's calendar updated about actual values in real time. Is it possible  updating time is not the same broker-by-broker. Yes, i'm looking how to improve my news trading robot
 
fxsaber #:

I don't know what you are running. Regarding calendar data updates, read the following discussion.


The library only provides the data that is available in the Calendar tab.

Thank you so much. It is clear for me now!!!....
 

The only way to understand the MT5 calendar is to compare the BEFORE/After values.

#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)) // Loaded absolutely all events (history + future) from MT5-Terminal.
  {
    const string FileName = "Calendars\\" + AccountInfoString(ACCOUNT_SERVER) + "\\Calendar_" +
                            AccountInfoString(ACCOUNT_SERVER) + "_" + TimeToString(TimeCurrent(), TIME_DATE) + ".bin";
    
    Calendar.Save(FileName); // Saved for future comparison when USA/Europe synchronise.
  }
}

Obviously, no one will do that.

 

Forum on trading, automated trading systems and testing trading strategies

Libraries: Calendar

fxsaber, 2023.01.07 21:31.

Looks like we should make an automatic corrector in calendar dates.

It seems to get a Calendar corrector that matches the trading server.

#property script_show_inputs

input ulong inEventID = 840030006; // EventID
input string inName = ""; // Name -> EventID (Nonfarm Payrolls -> 840030016)
input datetime inFrom = D'2020.01.01';
input bool inDST = true;

void OnStart()
{
  CALENDAR Calendar;
    
  if (inName == "")
  {
    Calendar.Set(inEventID);
    Calendar.FilterByTime(inFrom, TimeCurrent());
    
    Calendar.CorrectTime(); // Bypass MQL-calendar peculiarities: https://www.mql5.com/ru/forum/444094/page14#comment_46213385
    
    if (inDST)
      Calendar.DST(); // Call if the trade server is synchronised with European time.
  
    for (int i = Calendar.GetAmount() - 1; i >= 0; i--)
    {
      const EVENT Event = Calendar[i];    
      const datetime ChartNews = ChartNewsTime(Event.time); // https://www.mql5.com/ru/forum/357793/page5#comment_44225999
      
      if (Event.time != ChartNews)    
        Print("-" + (string)Event.EventID + ": " + TimeToString(ChartNews) + " != " + Event.ToString());
      else
        Print("+" + (string)Event.EventID + ": " + TimeToString(ChartNews) + " == " + Event.ToString());
    }
  }
  else // Get EventID by name.
  {
    string Currencies[2];
    
    // Get the currencies of the current character.
    Currencies[0] = ::SymbolInfoString(_Symbol, SYMBOL_CURRENCY_BASE);
    Currencies[1] = ::SymbolInfoString(_Symbol, SYMBOL_CURRENCY_PROFIT);
    
    if (Calendar.Set(Currencies, CALENDAR_IMPORTANCE_MODERATE, inFrom) && Calendar.FilterByName(inName))
      for (int i = Calendar.GetAmount() - 1; i >= 0; i--)
        Print((string)Calendar[i].EventID + ": " + Calendar[i].ToString());
  }
}


Result.

+840030016: 2023.04.07 15:30 == 2023.04.07 15:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 236 K | -8 K | 311 K | 326 K
+840030016: 2023.03.10 15:30 == 2023.03.10 15:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 311 K | -35 K | 517 K | 504 K
+840030016: 2023.02.03 15:30 == 2023.02.03 15:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 517 K | 16 K | 223 K | 260 K
+840030016: 2023.01.06 15:30 == 2023.01.06 15:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 223 K | 57 K | 263 K | 256 K
+840030016: 2022.12.02 15:30 == 2022.12.02 15:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 263 K | -30 K | 261 K | 284 K
+840030016: 2022.11.04 14:30 == 2022.11.04 14:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 261 K | -97 K | 263 K | 315 K
+840030016: 2022.10.07 15:30 == 2022.10.07 15:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 263 K | 33 K | 315 K | 
+840030016: 2022.09.02 15:30 == 2022.09.02 15:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 315 K | 156 K | 528 K | 526 K

It matches the Web-calendar. If anyone sees any obvious discrepancies, let me know.

That seems to be the correct way to use the calendar for backtests now.

 
fxsaber #:

Looks like it turned out to be a Calendar corrector that matches the trade server.


Result.

Matches the Web Calendar. If anyone sees any obvious discrepancies, let me know.

Now it seems to be correct to use the calendar for backtests.

But what if it is the time of another country? I know that different countries have different dates for different times.