Download MetaTrader 5

GMT to Server - page 5

To add comments, please log in or register
whroeder1
16286
whroeder1  
PieroNetto: We had to start with some time zone,
No you don't. The server time start with their TZ, GMT started with GMT TZ, and local time started with that TZ.
Doerk Hilger
1494
Doerk Hilger  

Someone thought about the difference in summer-time-rules? ;)

This is brain-fucking stuff which you will not be able to solve that way. Most servers, no matter if they are in London, Cyprus or wherever, will have a fixed GMT deviation, yes, but they don´t follow the rules of the summertime for their GMT zone, they follow the rules of the NYSE. This you have to take into account as well. And this second deviation has to be compared with your local summertime rule. If not, you will have up to 8 weeks a year where all this won´t work what you do.

Anyway, this should be done by MetaTrader, it really should not be an issue for us. I cannot understand why they don´t care about it, it´s simply annoying for probably 90% or more of all users.

PieroNetto
295
PieroNetto  
whroeder1:
No you don't. The server time start with their TZ, GMT started with GMT TZ, and local time started with that TZ.

Let’s solve Question 3) first. Thanks for responding whroeder1

The datetime type is intended for storing the date and time as the number of seconds elapsed since January 01, 1970.

January 01, 1970 can’t be everywhere to the same time. Like you saying starting all TZ to the same time whit the calculated difference of curse. Understandably.

January 01, 1970 had to be appointed to some TZ. You explant in this threat the rollover problem, is the same here or not?

PieroNetto
295
PieroNetto  
Doerk Hilger:

Someone thought about the difference in summer-time-rules? ;)

This is brain-fucking stuff which you will not be able to solve that way. Most servers, no matter if they are in London, Cyprus or wherever, will have a fixed GMT deviation, yes, but they don´t follow the rules of the summertime for their GMT zone, they follow the rules of the NYSE. This you have to take into account as well. And this second deviation has to be compared with your local summertime rule. If not, you will have up to 8 weeks a year where all this won´t work what you do.

Anyway, this should be done by MetaTrader, it really should not be an issue for us. I cannot understand why they don´t care about it, it´s simply annoying for probably 90% or more of all users.


Thanks for participating. 

You absolutely right, they should have a predefined function like TimeGMTOffset(); ,call it ServerGMTOffset(); , that’s the idea here.

PieroNetto
295
PieroNetto  

Calling it GMT is wrong. Have been reading for a bit in the net. Just a little thing on the side.

Die Greenwich Mean Time war von 1884 bis 1928 Weltzeit, in dieser Funktion wurde sie 1972 von der Koordinierten Weltzeit (UTC) abgelöst. Der Ausdruck Greenwich Mean Time (GMT) wird heute eigentlich nur noch in Großbritannien und Westafrika offiziell für die Zeitzone Westeuropäische Zeit(WEZ/WET, UTC+0) verwendet. Seit 1925 wird die Bezeichnung von unterschiedlichen Stellen für verschiedene Zeitnormale genutzt. Daher wird empfohlen, wenn man genaue Zeiterfassung erreichen möchte, diese Bezeichnung nicht zu verwenden.[1]

https://de.wikipedia.org/wiki/Greenwich_Mean_Time#Heutige_Verwendung_des_Ausdrucks_GMT

PieroNetto
295
PieroNetto  

Here i a little thing that made me thinking about the rounding (+1800), half an hour in the code.

Bemerkung: In manchen Gebieten der Erde gibt es Zonenzeiten, die sich nicht in vollen Stunden von der UTC unterscheiden. Bsp.: UTC+9:30 im mittleren Australien.

https://de.wikipedia.org/wiki/Zonenzeit

Heute offiziell verwendete Zonenzeiten

UTC−12 | UTC−11 | UTC−10 | UTC−9:30 | UTC−9 | UTC−8 | UTC−7 | UTC−6 | UTC−5 | UTC−4 | UTC−3:30 | UTC−3 | UTC−2 | UTC−1 | UTC | UTC+1 | UTC+2 | UTC+3 | UTC+3:30 | UTC+4 | UTC+4:30 | 

UTC+5 | UTC+5:30 | UTC+5:45 | UTC+6 | UTC+6:30 | UTC+7 | UTC+8 | UTC+8:30 | UTC+9 | UTC+9:30 | UTC+10 | UTC+10:30 | UTC+11 | UTC+12 | UTC+12:45 | UTC+13 | UTC+13:45 | UTC+14

Heute nicht mehr verwendet: UTC−4:30 | UTC+11:30

Doerk Hilger
1494
Doerk Hilger  

The "funny" thing is by the way, that most of the programmers dont even seem to recognize that all calculations, which are based on a time range or level range of a specific time, especially the previous day, can only produce wrong results when the time zones are not adjusted correctly. Simply some pivots points of the previous day will never be correct when the brokers server operates in a different time zone as the underlying comes from. Using daily candles for calculations like these is the best way to get bad results.

Once you fixed this and calculate different, you will wonder how precise levels can work. It would be very easy for MQ to fix issues like that, all other platforms can handle this.

What you have to use ist 4 values:

1. The local GMT

2. The server GMT

3. The local rules for summertime

4. The server rules for summertime

And for the summertime rules, you need a database to adjust the local time and the server time for every single hour in the chart by this. You need to modify the time of every single candle and this means, you definetley cannot deal with any of the standard functions, not with the standard classes and within indicators you have to adjust every single element of the array. Means, actually you have to rewrite almost everything by yourself. And anything else makes absolutely no sense, cause you must always translate between chart time and local time, for each single object, for each single candle.

In other words, it would be nice to have such functions of MQ which translate the time, but its not a reason, its just a workaround. There are only two reasons:

1. Rewrite it all, create such a database and deal with own classes instead of the standard stuff

2. Live with bad results

Doerk Hilger
1494
Doerk Hilger  

I created a class named CBars, it can handle it. Imho there should be such a class at least within the standard library. Well, I am thinking about making this class somehow public/common and to invite other developers to continue it, cause my users have access to it anyway, its not hidden. I currently implemented rules for USA NY, London, Berlin and Moscow and I also implemented only standard indicators such as MA or ATR, cause its simly too much stuff for one person.

But the code you write using this class makes live so much easier. You simply have functions like

.IsHammer(shift) 

.ATR(periods, shift)

.Time(shift)

.IsLocalHigh(nbars, shift)

and so on. I use this class since a longer time and by the way my effort to migrate indicators between MQL4 and MQL5 was ZERO. 

PieroNetto
295
PieroNetto  

Hi Doerk Hilger!

Thank you for your response and advise about our growing discussion. Please don’t jump ahead of things for now, that’s the biggest problem for beginners in this forum. People same to read the last two or three posting and giving good advice and jumping ahead, that makes it hard to understand for beginners like me. I like to go through this step by step. I know about DST, please disregard DST for now, it makes no sense to discuss it now if we don’t have first part finished.

 In #39, the beginning of this threat we solved a few things and came up with a code to show the jitter and display the right result between UTC and Server. In #40 I had still a few questions the are not answered jet. My research today even throws more questions out there, in #46. Anyhow I would love to discuss about DST when we get there

PieroNetto
295
PieroNetto  

Lets throw it out there and see what's coming my way. Please no comments about DST yet, assume there is non DST for now. Still discussing Server to UTC ,Auto adjust to Market openings


int start()
{
      int      UTCOffset     = TimeGMTOffset();
      int      UTC_to_Local  = TimeGMTOffset()/3600;
      datetime utc           = TimeGMT();
      datetime UTC_Time      = TimeHour(utc);
      datetime st            = TimeCurrent();
      datetime Server_Time   = TimeHour(st);
      datetime lt            = TimeLocal();
      datetime Local_Time    = TimeHour(lt);
      
      if(utc<st)
      {
      int UTC_to_Server = (utc - st - 1800)/3600;
      int sTZ           = 3600*UTC_to_Server;
      }
      else
      if(st<utc)
      {
      UTC_to_Server = (utc - st + 1800)/3600;
      sTZ           = 3600*UTC_to_Server;
      }
      int Switch_Time = UTC_to_Server;
      switch(Switch_Time)
      {
      case -12:Switch_Time=18;break;
      case -11:Switch_Time=17;break;
      case -10:Switch_Time=16;break;
      case - 9:Switch_Time=15;break;
      case - 8:Switch_Time=14;break;
      case - 7:Switch_Time=13;break;
      case - 6:Switch_Time=12;break;
      case - 5:Switch_Time=11;break;
      case - 4:Switch_Time=10;break;
      case - 3:Switch_Time= 9;break;
      case - 2:Switch_Time= 8;break;
      case - 1:Switch_Time= 7;break;
      case   0:Switch_Time= 6;break;
      case   1:Switch_Time= 5;break;
      case   2:Switch_Time= 4;break;
      case   3:Switch_Time= 3;break;
      case   4:Switch_Time= 2;break;
      case   5:Switch_Time= 1;break;
      case   6:Switch_Time= 0;break;
      case   7:Switch_Time=23;break;
      case   8:Switch_Time=22;break;
      case   9:Switch_Time=21;break;
      case  10:Switch_Time=20;break;
      case  11:Switch_Time=19;break;
      case  12:Switch_Time=18;break;
     }
     {
     int Frankfurt_Open  = Switch_Time + 0; int FO ;if(Frankfurt_Open >24){FO = Frankfurt_Open  - 24;}else{FO = Frankfurt_Open;}
     int Frankfurt_Close = Switch_Time + 8; int FC ;if(Frankfurt_Close>24){FC = Frankfurt_Close - 24;}else{FC = Frankfurt_Close;}
     int London_Open     = Switch_Time + 1; int LO ;if(London_Open>24)    {LO = London_Open - 24;}    else{LO = London_Open;}
     int London_Close    = Switch_Time + 9; int LC ;if(London_Close>24)   {LC = London_Close - 24;}   else{LC = London_Close;}
     int New_York_Open   = Switch_Time + 6; int NYO;if(New_York_Open>24)  {NYO = New_York_Open - 24;} else{NYO = New_York_Open;}
     int New_York_Close  = Switch_Time +14; int NYC;if(New_York_Close>24) {NYC = New_York_Close - 24;}else{NYC = New_York_Close;}
     int Sydney_Open     = Switch_Time +16; int SO ;if(Sydney_Open>24)    {SO = Sydney_Open - 24;}    else{SO = Sydney_Open;}
     int Sydney_Close    = Switch_Time +24; int SC ;if(Sydney_Close>24)   {SC = Sydney_Close - 24;}   else{SC = Sydney_Close;}
     int Tokyo_Open      = Switch_Time +17; int TO ;if(Tokyo_Open>24)     {TO = Tokyo_Open - 24;}     else{TO = Tokyo_Open;}
     int Tokyo_Close     = Switch_Time +25; int TC ;if(Tokyo_Close>24)    {TC = Tokyo_Close - 24;}    else{TC = Tokyo_Close;}
     }
      Comment("Local Time        = ",lt,"  = ",Local_Time,"\n",
              "Server Time      = ",st," = ",Server_Time,"\n",
              "UTC Time        = ",utc," = ",UTC_Time,"\n",
              "UTC to Server  = ",sTZ,"         = ",UTC_to_Server,"\n",
              "UTC to Local     = ",UTCOffset,"          = ",UTC_to_Local,"\n",
              "Frankfurt          = ",FO,":00  -  ",FC,":00  Server Time","\n",
              "London             = ",LO,":00  -  ",LC,":00  Server Time","\n",
              "New York         = ",NYO,":00  -  ",NYC,":00  Server Time","\n",
              "Sydney            = ",SO,":00  -  ",SC,":00  Server Time","\n",
              "Tokyo              = ",TO,":00  -  ",TC,":00  Server Time");
              
return(0);
}
To add comments, please log in or register