MQL4 : TimeDaylightSavings() - How it works ???

 

Hi coders,

int DLSSec= TimeDaylightSavings();

I'm a trader in Asia country, the forex market open local time is either 06:00 or 05:00 daily (broker's server time = 00:00). It is in winter period right now, the DLSSEc output = 0 and the forex market open local time is at 06:00.

I checked with 2 AI chatbots, both are giving me totally opposite answers on DLSSec.

AI Chatbot A :-
It said that the DLSSec is applying to and following the broker's server time to adjust, it means that :-
1) if the market open local time is at 06:00 (winter period) and the DLSSEc output = 0.
2) if the market open local time is at 05:00 (summer period) and the DLSSEc output = 3600 (1 hour).

AI Chatbot B :-
It said that the DLSSec is applying to and following the user's computer local time and my host country in Asia has no DLS, therefore :-
1) if the market open local time is at 06:00 (winter period) and the DLSSEc output = 0.
2) if the market open local time is at 05:00 (summer period) and the DLSSEc output = 0.
In other words, DLSSEc output is always 0 throughout the entire year.

Which is the correct answer ? Kindly advise, thanks

Documentation on MQL5: TimeTradeServer / Date and Time
Documentation on MQL5: TimeTradeServer / Date and Time
  • www.mql5.com
Returns the calculated current time of the trade server. Unlike TimeCurrent() , the calculation of the time value is performed in the client...
 

I don't know how that function works, but it looks like the documentation should partially answer your question.

https://docs.mql4.com/dateandtime/timedaylightsavings

TimeDaylightSavings - Date and Time - MQL4 Reference
TimeDaylightSavings - Date and Time - MQL4 Reference
  • docs.mql4.com
TimeDaylightSavings - Date and Time - MQL4 Reference
 
Vladislav Boyko #:

I don't know how that function works, but it looks like the documentation should partially answer your question.

https://docs.mql4.com/dateandtime/timedaylightsavings

I already read the link 2 days ago but I don't know how it works ...
 
Chin Min Wan:
AI Chatbot A :-
It said that the DLSSec is applying to and following the broker's server time to adjust, it means that :-

AI Chatbot B :-
It said that the DLSSec is applying to and following the user's computer local time and my host country in Asia has no DLS, therefore :-
https://docs.mql4.com/dateandtime/timedaylightsavings


It depends on the time settings of your computer.

 
Vladislav Boyko #:
What kind of settings ?
 
Chin Min Wan #:
What kind of settings ?
I don't know. But from the documentation it is clear that the function follows the local time of the computer, not the server time. That's what I was trying to tell you.
 
Vladislav Boyko #:
I don't know. But from the documentation it is clear that the function follows the local time of the computer, not the server time. That's what I was trying to tell you.

So, you mean in my country (Asia), we do not have DLS, means the DLSSEc output is always 0 throughout the entire year ?

 
Chin Min Wan #:

So, you mean in my country (Asia), we do not have DLS, means the DLSSEc output is always 0 throughout the entire year ?

I didn't say that, and I don't know much about it. But, by the way, your assumption sounds logical.

 
Chin Min Wan #:

So, you mean in my country (Asia), we do not have DLS, means the DLSSEc output is always 0 throughout the entire year ?

Yes, because there is no summer switch.

I suspect that the missing piece of the puzzle that you're trying to solve is TImeGMTOffset().

GMT adjusts for Daylight Savings, your computer does not, and TimeGMTOffset() calculates the difference between the two. So, you can write something like...

// globals
int lastOffset;

// initialization
lastOffset = TimeGMTOffset();

// main event handler
//...

if(lastOffset == TimeGMTOffset() - 3600)
 {
  // do something
  lastOffset = TimeGMTOffset();
 }

if(lastOffset == TimeGMTOffset() + 3600)
 {
  // do something
  lastOffset = TimeGMTOffset();
 }

Just a note: Time is technically a ulong in MQL5 even though an int works. If the same is true for MQL4, you might want to use a ulong to be technically correct.

TimeGMTOffset - Date and Time - MQL4 Reference
TimeGMTOffset - Date and Time - MQL4 Reference
  • docs.mql4.com
TimeGMTOffset - Date and Time - MQL4 Reference
 
Ryan L Johnson #:
TimeGMTOffset()
OK, I'll study what is TImeGMTOffset() later, thanks
TimeGMTOffset - Date and Time - MQL4 Reference
TimeGMTOffset - Date and Time - MQL4 Reference
  • docs.mql4.com
TimeGMTOffset - Date and Time - MQL4 Reference