Libraries: Local Timezones and Local Session Hours

 

Local Timezones and Local Session Hours:

Class to access to the local time for the specified location, as well as time zone information and the local trading session hours.

Local Timezones and Local Session Hours

Author: amrali

 

Update 1 March 2024 - version 1.40

Removed redundant code in CTimeZoneInfo class (used during testing).

Added more methods to CSessionHours class.

Updated TestIndi.mq5 to reflect the new changes.

 
Good work. Thank you.
 

Update 3 March 2024

Updated the example code for "Working with Local Session Hours - CTimeZoneInfo Class".

 
An excellent piece of code for anyone, searching to handle time in different zones. The set of CTimeZoneInfo, CSessionHours, and CTimeGMT is very helpful for tracking times in different sessions at the current point of time. For looking at times in history or forecasting time, you may need to tweak a bit and you can get it. Amrali was very helpful in updating his code, based on some of my requirements. I am thankful to him for all his support that enabled me to find Forex time sessions for one of my indicator code.
 
Brilliant!
 
Anil Varma #:
An excellent piece of code for anyone, searching to handle time in different zones. The set of CTimeZoneInfo, CSessionHours, and CTimeGMT is very helpful for tracking times in different sessions at the current point of time. For looking at times in history or forecasting time, you may need to tweak a bit and you can get it. Amrali was very helpful in updating his code, based on some of my requirements. I am thankful to him for all his support that enabled me to find Forex time sessions for one of my indicator code.

Thanks Anil,

I updated the lib to v1.50, I think that will fix the issue you had with broker offset being one hour different. Please check it.

 

Update 8 March 2024 - version 1.50

Added two internal methods HistoryBrokerOffset() and FirstBarOfWeek() to CTimeZoneInfo class.

Handling of server time in the past (UTC offset, text formatting, conversions, etc..).

Better support for indicators dealing with bar times or past local session hours.

Updated examples.mq5 to demonstrate the new functionality.

 

Update 15 March 2024 - version 1.56

Added script "SydneySession_Script.mq5" to to show how the session hours in Sydney are fluctuating throughout the year.

 

I think there is still a problem with a one hour difference in V1.62

When I run the example I get the following incorrect (trade server is two hours in advance) output:

Fri, 2024.03.29 09:31:11 GMT+1 [Frankfurt] | Fri, 2024.03.29 11:31:11 GMT+3 [AdmiralMarkets-Demo]

Yet when I print the different times manually I get the correct times (where the trade server is one hour in advance):

Trade server time: 2024.03.29 10:38:00

Local time: 2024.03.29 09:38:00

Time GMT: 2024.03.29 08:38:00

GMT Offset: -3600

Daylight savings correction: 0


Please note that I'm located in the Frankfurt timezone.

Would be great if you can have a look into the issue.

 
I tried also the SidneySession_Script and changed the location from Sidney to Frankfurt and there you see the same issue:

2024.03.29 12:43:04.335 SydneySession_Script (GERMANY40,M2) Sun, 2024.01.07 09:00:00 GMT+1 [Frankfurt]      | Sun, 2024.01.07 09:00:00 GMT+1 [Frankfurt]      | Sun, 2024.01.07 10:00:00 GMT+2 [AdmiralMarkets-Demo]
2024.03.29 12:43:04.336 SydneySession_Script (GERMANY40,M2) Sun, 2024.01.14 09:00:00 GMT+1 [Frankfurt]      | Sun, 2024.01.14 09:00:00 GMT+1 [Frankfurt]      | Sun, 2024.01.14 10:00:00 GMT+2 [AdmiralMarkets-Demo]
2024.03.29 12:43:04.336 SydneySession_Script (GERMANY40,M2) Sun, 2024.01.21 09:00:00 GMT+1 [Frankfurt]      | Sun, 2024.01.21 09:00:00 GMT+1 [Frankfurt]      | Sun, 2024.01.21 10:00:00 GMT+2 [AdmiralMarkets-Demo]
2024.03.29 12:43:04.336 SydneySession_Script (GERMANY40,M2) Sun, 2024.01.28 09:00:00 GMT+1 [Frankfurt]      | Sun, 2024.01.28 09:00:00 GMT+1 [Frankfurt]      | Sun, 2024.01.28 10:00:00 GMT+2 [AdmiralMarkets-Demo]
2024.03.29 12:43:04.336 SydneySession_Script (GERMANY40,M2) Sun, 2024.02.04 09:00:00 GMT+1 [Frankfurt]      | Sun, 2024.02.04 09:00:00 GMT+1 [Frankfurt]      | Sun, 2024.02.04 10:00:00 GMT+2 [AdmiralMarkets-Demo]
2024.03.29 12:43:04.336 SydneySession_Script (GERMANY40,M2) Sun, 2024.02.11 09:00:00 GMT+1 [Frankfurt]      | Sun, 2024.02.11 09:00:00 GMT+1 [Frankfurt]      | Sun, 2024.02.11 10:00:00 GMT+2 [AdmiralMarkets-Demo]
2024.03.29 12:43:04.336 SydneySession_Script (GERMANY40,M2) Sun, 2024.02.18 09:00:00 GMT+1 [Frankfurt]      | Sun, 2024.02.18 09:00:00 GMT+1 [Frankfurt]      | Sun, 2024.02.18 10:00:00 GMT+2 [AdmiralMarkets-Demo]
2024.03.29 12:43:04.336 SydneySession_Script (GERMANY40,M2) Sun, 2024.02.25 09:00:00 GMT+1 [Frankfurt]      | Sun, 2024.02.25 09:00:00 GMT+1 [Frankfurt]      | Sun, 2024.02.25 10:00:00 GMT+2 [AdmiralMarkets-Demo]
2024.03.29 12:43:04.336 SydneySession_Script (GERMANY40,M2) Sun, 2024.03.03 09:00:00 GMT+1 [Frankfurt]      | Sun, 2024.03.03 09:00:00 GMT+1 [Frankfurt]      | Sun, 2024.03.03 10:00:00 GMT+2 [AdmiralMarkets-Demo]
2024.03.29 12:43:04.336 SydneySession_Script (GERMANY40,M2) Sun, 2024.03.10 09:00:00 GMT+1 [Frankfurt]      | Sun, 2024.03.10 09:00:00 GMT+1 [Frankfurt]      | Sun, 2024.03.10 11:00:00 GMT+3 [AdmiralMarkets-Demo]
2024.03.29 12:43:04.336 SydneySession_Script (GERMANY40,M2) Sun, 2024.03.17 09:00:00 GMT+1 [Frankfurt]      | Sun, 2024.03.17 09:00:00 GMT+1 [Frankfurt]      | Sun, 2024.03.17 11:00:00 GMT+3 [AdmiralMarkets-Demo]
2024.03.29 12:43:04.336 SydneySession_Script (GERMANY40,M2) Sun, 2024.03.24 09:00:00 GMT+1 [Frankfurt]      | Sun, 2024.03.24 09:00:00 GMT+1 [Frankfurt]      | Sun, 2024.03.24 11:00:00 GMT+3 [AdmiralMarkets-Demo]



Reason: