has SymbolInfoSessionTrade() behavior changed?

 

It seems like SymbolInfoSessionTrade() has changed recently. In my EA I check for the end of the session time, calling from OnTimer() and send a message at the end of the session. This has been working fine for more than a year. Recently, I'm receiving those messages on the weekend, when the server time is midnight. So it seems like SymbolInfoSessionTrade is now returning true even when there is no trading hours for that day.


I wrote this simple EA to prove my point:


int OnInit()
  {
   MqlDateTime  server_time        = {};
   datetime     now                  = TimeTradeServer(server_time);
   datetime     session_start_time,  session_end_time, time;



   if(!SymbolInfoSessionTrade(_Symbol, (ENUM_DAY_OF_WEEK)server_time.day_of_week, 0, session_start_time, session_end_time))
     {
      return false;
     }
   return(INIT_SUCCEEDED);
  }



here is a screenshot of me debugging the code on real data. Notice that the code is currently on line 27, which means the if condition above must have returned true. Look at the MqlDateTimeStruct data. it's currently day of the week 0(Sunday) and the session_end/start_time are 00:00:00. Ive also attached the screenshot for the symbol showing that there is no trading session on the weekend. 


I would expect the function to return false if the day of the weekend is zero. And I'm telling you, this used to work. I would never get push notifications from my EA on the weekend, now, without changing that part of the code I do. The only logical conclusion I can arrive is that the function has changed its behaviour. 


The documentation says the following, which isn't super clear to me.  


Return value

If data for the specified session, symbol and day of the week are received, returns true, otherwise returns false.


I checked the release notes(https://www.metatrader5.com/en/releasenotes) for changes to this function and found none. 

I know how to deal with this but just curious if this is an undocumented change(or documented and I just didn't find it).


cheers

Files:
 

Hey all.

I am currently struggling with a similar problem as well.
Over a year my EA worked just fine in real-time demo test mode with 4 different brokers, but only by a chance I decided to do some more back tests and during them I spotted a massive decrese of executed trades. In debugg mode I found a problem with the SymbolInfoSessionTrade() function, when it returns some funny values of the open times instead of the real ones (check the attached picture).

As I have mentioned eabove, the real-time trading by this EA went good till few days ago, when one of the brokers ceased trade executions although the other brokers remained tradable. I thought it happened because of my demo account expired, but after loggin to that brokers account I found there are waiting some documents to be sign. And this (and not only this) happened several times in the past yet, that this broker just ceased trading possibility, instead of sending a message, because he need from me to do some paperwork. Maybe is worth to mention a name of the MTFCKR broker, just for sake of some similarities: Admiral Brokers is the one who proly never see my real money again. And quess on which brokers data I did the back-tests?
Anyway, even my demo account didn't expired and the papers are signed, the trading with this broker wasn't restored, so with this new SymbolInfoSessionTrade() issue I don't know, what's the reason for that.
I'll do some more back-tests with another brokers data and try to do more research about it.

Otherwise I would be another grateful for any possible hint for a sollution.
Cheers too.

Files:
EA.png  107 kb
 
James T #:

Hey all.

I am currently struggling with a similar problem as well.
Over a year my EA worked just fine in real-time demo test mode with 4 different brokers, but only by a chance I decided to do some more back tests and during them I spotted a massive decrese of executed trades. In debugg mode I found a problem with the SymbolInfoSessionTrade() function, when it returns some funny values of the open times instead of the real ones (check the attached picture).

As I have mentioned eabove, the real-time trading by this EA went good till few days ago, when one of the brokers ceased trade executions although the other brokers remained tradable. I thought it happened because of my demo account expired, but after loggin to that brokers account I found there are waiting some documents to be sign. And this (and not only this) happened several times in the past yet, that this broker just ceased trading possibility, instead of sending a message, because he need from me to do some paperwork. Maybe is worth to mention a name of the MTFCKR broker, just for sake of some similarities: Admiral Brokers is the one who proly never see my real money again. And quess on which brokers data I did the back-tests?
Anyway, even my demo account didn't expired and the papers are signed, the trading with this broker wasn't restored, so with this new SymbolInfoSessionTrade() issue I don't know, what's the reason for that.
I'll do some more back-tests with another brokers data and try to do more research about it.

Otherwise I would be another grateful for any possible hint for a sollution.
Cheers too.


I do not see your reasoning as a rectification for such an almost vulgar post on this forum.

Please be respectful.

The "funny values" mentioned by you are normal and correct return values.

Calendar math is confusing by times, but once you begin to solve some of the time calculation problems, you will see why it makes sense.
 
lgb1:

It seems like SymbolInfoSessionTrade() has changed recently. In my EA I check for the end of the session time, calling from OnTimer() and send a message at the end of the session. This has been working fine for more than a year. Recently, I'm receiving those messages on the weekend, when the server time is midnight. So it seems like SymbolInfoSessionTrade is now returning true even when there is no trading hours for that day.


I wrote this simple EA to prove my point:




here is a screenshot of me debugging the code on real data. Notice that the code is currently on line 27, which means the if condition above must have returned true. Look at the MqlDateTimeStruct data. it's currently day of the week 0(Sunday) and the session_end/start_time are 00:00:00. Ive also attached the screenshot for the symbol showing that there is no trading session on the weekend. 


I would expect the function to return false if the day of the weekend is zero. And I'm telling you, this used to work. I would never get push notifications from my EA on the weekend, now, without changing that part of the code I do. The only logical conclusion I can arrive is that the function has changed its behaviour. 


The documentation says the following, which isn't super clear to me.  


Return value

If data for the specified session, symbol and day of the week are received, returns true, otherwise returns false.


I checked the release notes(https://www.metatrader5.com/en/releasenotes) for changes to this function and found none. 

I know how to deal with this but just curious if this is an undocumented change(or documented and I just didn't find it).


cheers


I see one flaw in your code, which would make it sensible to conclude a bug.

(ENUM_DAY_OF_WEEK)server_time.day_of_week

You assume the value to be compatible, but this is not a given. - Check if this assumption still holds true, and remove it via clear code later on. Then report back, please.


 

alright, new code, even simpler to demonstrate what I'm suggesting. I'm simply looping through all the days of the week and printing more info when SymbolInfoSessionTrade() returns true. BTW this is on MT5 build 4831.


int OnInit()
  {
   datetime     session_start_time,  session_end_time;

   for(int i = 0; i <= 6; i++)
     {
      if(SymbolInfoSessionTrade(_Symbol, (ENUM_DAY_OF_WEEK)i, 0, session_start_time, session_end_time))
        {
         Print("Day: ", EnumToString((ENUM_DAY_OF_WEEK)i), " Starts at: ", session_start_time, " ends at: ",  session_end_time);
        }
     }
   return(INIT_SUCCEEDED);
  }


Output upon loading it:

2025.03.25 10:41:40.855 testingtradinghours (Bra50Apr25,M5)     Day: SUNDAY Starts at: 1970.01.01 00:00:00 ends at: 1970.01.01 00:00:00
2025.03.25 10:41:40.855 testingtradinghours (Bra50Apr25,M5)     Day: MONDAY Starts at: 1970.01.01 13:00:00 ends at: 1970.01.01 22:25:00
2025.03.25 10:41:40.855 testingtradinghours (Bra50Apr25,M5)     Day: TUESDAY Starts at: 1970.01.01 13:00:00 ends at: 1970.01.01 22:25:00
2025.03.25 10:41:40.855 testingtradinghours (Bra50Apr25,M5)     Day: WEDNESDAY Starts at: 1970.01.01 13:00:00 ends at: 1970.01.01 22:25:00
2025.03.25 10:41:40.855 testingtradinghours (Bra50Apr25,M5)     Day: THURSDAY Starts at: 1970.01.01 13:00:00 ends at: 1970.01.01 22:25:00
2025.03.25 10:41:40.855 testingtradinghours (Bra50Apr25,M5)     Day: FRIDAY Starts at: 1970.01.01 13:00:00 ends at: 1970.01.01 22:25:00
2025.03.25 10:41:40.855 testingtradinghours (Bra50Apr25,M5)     Day: SATURDAY Starts at: 1970.01.01 00:00:00 ends at: 1970.01.01 00:00:00


I strongly believe that in the past we would not see SUNDAY and SATURDAY when running a code like the one above. I actually used to rely on that behavior to know which day of the week we have trading hours.

the symbol hours are attached. 

Files:
 
lgb1 #:

alright, new code, even simpler to demonstrate what I'm suggesting. I'm simply looping through all the days of the week and printing more info when SymbolInfoSessionTrade() returns true. BTW this is on MT5 build 4831.



Output upon loading it:


I strongly believe that in the past we would not see SUNDAY and SATURDAY when running a code like the one above. I actually used to rely on that behavior to know which day of the week we have trading hours.

the symbol hours are attached. 


According to docs, I would expect similar behavior as you do.


As a workaround, wrap the API call into a function and make it check the content of the variables begin and end, and adapt the return value to what you would be expecting.


 
lgb1 #:

alright, new code, even simpler to demonstrate what I'm suggesting. I'm simply looping through all the days of the week and printing more info when SymbolInfoSessionTrade() returns true. BTW this is on MT5 build 4831.



Output upon loading it:


I strongly believe that in the past we would not see SUNDAY and SATURDAY when running a code like the one above. I actually used to rely on that behavior to know which day of the week we have trading hours.

the symbol hours are attached. 

These data are provided by the broker, if you think they are not correct, ask them to fix it.