GMT to Server - page 4

 
Fernando Carreiro:

I sometimes don't understand you! You can't mix "humor" and "serious" together and hope that reader is able to distinguish between the two without being offended. You have to be clear!

You yourself, just stated that I mixed definitions mid post and that was causing confusion. So I say the same, you can't just state "I already said TimeCurrent() should not be used for the envisaged calculation" in the middle of a serious post and hope that we take just take that part as humor.

Please, that was not very nice of you to do, because it is misleading. So please I ask again in order to get a very clear and serious answer!

Is there or is there not an alternative to the use of TimeCurrent()?

EDIT: If you say, creating your own internal synchronised, continuous, server clock then that, I have already stated that. If on the other-hand I have caught you out on a lie, then please be man enough to admit it. There will be no ill feelings.

A lie ? Are you serious ?

When you don't understand me, just ask to explain what I mean. It's not my fault if you don't understand me. I never say (or very rarely) something to offend some. Also sometimes I used the wrong English word, sorry about that, I am still learning.

TimeCurrent() can't be use because it's a time coming from the server but it's not the server time. That's nothing new, anyone who read the documentation can know it. There was no humor. So what you need is the server time...of course if your assumption is all tick are delayed by 15 or 18 seconds it will be hard to know the server time. Otherwise it's not that complicated.

With mql5 you have TimeTradeServer(), with mql4 up to you.

Documentation on MQL5: Date and Time / TimeTradeServer
Documentation on MQL5: Date and Time / TimeTradeServer
  • www.mql5.com
Date and Time / TimeTradeServer - Reference on algorithmic/automated trading language for MetaTrader 5
 
Alain Verleyen:

A lie ? Are you serious ?

When you don't understand me, just ask to explain what I mean. It's not my fault if you don't understand me. I never say (or very rarely) something to offend some. Also sometimes I used the wrong English word, sorry about that, I am still learning.

TimeCurrent() can't be use because it's a time coming from the server but it's not the server time. That's nothing new, anyone who read the documentation can know it. There was no humor. So what you need is the server time...of course if your assumption is all tick are delayed by 15 or 18 seconds it will be hard to know the server time. Otherwise it's not that complicated.

With mql5 you have TimeTradeServer(), with mql4 up to you.

I will offer no more comments on this matter!
 
nicholishen:

I still don't see where you're going there by adding thirty minutes to the delta then dividing by 60 min... ???

Why not just keep it simple and let int division do its thing? There's no need to over-complicate it.

int gmt_offset = ((int)TimeCurrent()-(int)TimeGMT()) / 3600;

Already stated:

What if your server time read is 23:59:59 and GMT is read 21:00:01. The difference is not 3*3600; it is two seconds less and 7198/3600 is 2 not 3.

and 2 is wrong.
 
Fernando Carreiro:
I will offer no more comments on this matter!
Finally.
 
whroeder1:

Already stated:

and 2 is wrong.

Yeah I get it now. You must've missed the part where I gave you props for your sweet algorithm. 

 

This has to be one of the funniest threads I've read on here in quite some time! Thank you gentlemen :D

 
whroeder1:

Already stated:

What if your server time read is 23:59:59 and GMT is read 21:00:01. The difference is not 3*3600; it is two seconds less and 7198/3600 is 2 not 3.

and 2 is wrong.

Actually 7198/3600 is 1. Should be 10798/3600

Maybe Stuart will continue to laugh :-)

 
Alain Verleyen:

Actually 7198/3600 is 1. Should be 10798/3600

Maybe Stuart will continue to laugh :-)


 

Hi everyone!

First, I like to say thanks to all participants in this block. Where should I start? Let’s start from the beginning.

Carl Schreiber, thanks for your interests and help trying to solve my problem with your code idea, but the problem was simply shifted from midnight to noon time with this code, still trough testing and playing with it I learn a lot from it (% += ……. etc.). Like whroeder1 says in this block, “Don't look at hours. Hours rolls over, time do not.”.

Thank you, Carl,

 

Thanks to  whroeder1 for his genies code and it makes sense to calculated this way, it solves my problem with the rollover also. After this block, so far is there not much to say or argue about this code and should be understandably to anyone.

Thank you whroeder,

 

I must say thanks also to nicholishen for asking all the right questions I may had to, to understand this code.

Thank you nicholishen

 

Thanks to Fernando Carreiro  and Alain Verleyen for patience to keep this discussion going to everyone’s understanding and sharing all the knowledge about it and made Stuart laugh.

Thank you Fernando Carreiro, Alain Verleyen

 

Stuart Browne you made me laugh so it was fun to read It all again.

Thank you Stuart Browne (lol)

 

I made a little code to make the so called “jitter” visible and the GMT_to_Local and GMT_to_Server.

The “jitter” in my case is sometimes up to 3 seconds. See Image.


int start()
{
      int      GMTOffset     = TimeGMTOffset();
      int      GMT_to_Local  = TimeGMTOffset()/3600;
      datetime gmt           = TimeGMT();
      datetime GMT_Time      = TimeHour(gmt);
      datetime st            = TimeCurrent();
      datetime Server_Time   = TimeHour(st);
      datetime lt            = TimeLocal();
      datetime Local_Time    = TimeHour(lt);
      
      int      GMT_to_Server = (st-gmt + 1800)/3600;
      int      sTZ        = 3600*GMT_to_Server;
      
      Comment("Local Time     = ",lt," = ",Local_Time,"\n",
              "Server Time    = ",st," = ",Server_Time,"\n",
              "GMT Time       = ",gmt," = ",GMT_Time,"\n",
              "GMT to Server  = ",sTZ," = ",GMT_to_Server,"\n",
              "GMT to Local   = ",GMTOffset," = ",GMT_to_Local);
              
return(0);
}

 

Let’s keep going with our GMT_to_Server.

In the last post, we came up with the code to display GMT to Server difference correctly.

Question 1)

The predefined function TimeGMTOffset();  give us the different between GMT and Local Time and shows us in my case a negative -2. Should we have also a negative -3 shown us  on our code? Instead of Server_Time - GMT_Time + 1800 rounding up we take it around and have  GMT_Time  - Server_Time - 1800 rounding this way having a negative number  -3. Can we do that?

We did base our calculations on a different from +3 Server Time. In my case Germany. Please don’t take it as point of calculation, trying to make it to work for everyone anywhere.

Question 2)

If someone else drops this code, let’s say Server_Time = New_York or Tokyo, pic one. It will not show a different in +-12 system, it will show the different from 0 to 23 difference. Is this correct? If I’m correct here, then question 1 don’t need to be turn around to negative number. Why does the TimeGMTOffset();  does gives us a negative when GMT_Time < Local_Time and a positive when GMT_Time > Local_Time. Does it show in a +-12 system?

Question 3)

The datetime type is intended for storing the date and time as the number of seconds elapsed since January 01, 1970. We had to start with some time zone, I assume it was GMT and therefore it should return always the highest number of datetime. I’m correct here?