Synchronise Windows local time with the MT5 server - page 17

 

Seryozh!

I don't like either my version (syncronisation on the first deal) or your version,

because it's "around the clock" and adjusts the time almostall the time,

whereas the time only needs to be adjusted before the start and at the end of sessions.

Need to think about making a hybrid of our versions.

Take a look and tell me what you think

//+------------------------------------------------------------------+
//|                                              Time_sync_forts.mq5 |
//|                   Copyright 2017 Sergey Chalyshev & prostotrader |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017 Sergey Chalyshev & prostotrader"
#property link      "https://www.mql5.com"
#property version   "1.09"
//---
struct _SYSTEMTIME
  {
   short wYear;
   short wMonth;
   short wDayOfWeek;
   short wDay;
   short wHour;
   short wMinute;
   short wSecond;
   short wMilliseconds;
  };

_SYSTEMTIME loc_time;

#import "kernel32.dll"
//void GetLocalTime(_SYSTEMTIME &sys_time);
bool SetLocalTime(_SYSTEMTIME &sys_time);
#import
//
input ENUM_DAY_OF_WEEK FirstDay  = SATURDAY;        //Первый выходной
input ENUM_DAY_OF_WEEK SecondDay = SUNDAY;          //Второй выходной
//
MqlTick tick;
MqlDateTime sv_time, tts_time;
int st_st_mon   = 35100; //09-45
int end_st_mon  = 36000; //10-00
int st_end_mon  = 50280; //13-58
int end_end_mon = 50400; //14-00
int st_st_day   = 50460; //14-01
int end_st_day  = 50700; //14-05
int st_end_day  = 67380; //18-43
int end_end_day = 67500; //18-45
int st_st_evn   = 67560; //18-46
int end_st_evn  = 68400; //19-00
int st_end_evn  = 85680; //23-48
int end_end_evn = 85800; //23-50
//---
bool  is_sync;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
  is_sync = true;
  return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert Convert To Time function                                  |
//+------------------------------------------------------------------+
bool ConvertToTime(const ulong n_value,_SYSTEMTIME  &a_time)
  {
   MqlDateTime cur_time={0};
   TimeToStruct(datetime(n_value/1000),cur_time);
   if(cur_time.year>0)
     {
      a_time.wDay=short(cur_time.day);
      a_time.wDayOfWeek=short(cur_time.day_of_week);
      a_time.wHour=short(cur_time.hour);
      a_time.wMinute= short(cur_time.min);
      a_time.wMonth = short(cur_time.mon);
      a_time.wSecond= short(cur_time.sec);
      a_time.wYear=short(cur_time.year);
      a_time.wMilliseconds=short(n_value%1000);
      return(true);
     }
   return(false);
  }
//+------------------------------------------------------------------+
//| Expert On Tick function                                          |
//+------------------------------------------------------------------+
void OnTick()
{
  tts_time.year = 0;
  TimeTradeServer(tts_time);
  if(tts_time.year > 0)
  {
    if((tts_time.day_of_week == int(FirstDay)) ||
       (tts_time.day_of_week == int(SecondDay))) return;
    int cur_time = tts_time.hour * 3600 + tts_time.min * 60 + tts_time.sec;
    if(((cur_time >= st_st_mon) && (cur_time < end_st_mon)) ||
       ((cur_time >= st_end_mon) && (cur_time < end_end_mon)) ||
       ((cur_time >= st_st_day) && (cur_time < end_st_day)) ||
       ((cur_time >= st_end_day) && (cur_time < end_end_day)) ||
       ((cur_time >= st_st_evn) && (cur_time < end_st_evn)) ||
       ((cur_time >= st_end_evn) && (cur_time < end_end_evn)))
    {
      if(!is_sync)
      {
        if(!SymbolInfoTick(Symbol(), tick))
        {
          Print("Error SymbolInfoTick", GetLastError());
          return;
        }
        sv_time.year = 0;
        TimeToStruct(tick.time, sv_time);
        if(sv_time.year>0)
        {
          ulong last_ping=ulong(NormalizeDouble(double(TerminalInfoInteger(TERMINAL_PING_LAST))/2000,0));
          ulong mls_time=ulong(tick.time_msc%1000);
          if((mls_time+last_ping)>999)
          {
            mls_time=tick.time_msc+last_ping;
            if(!ConvertToTime(mls_time, loc_time)) return;
          }
          else
          {
            loc_time.wYear = short(sv_time.year);
            loc_time.wMonth = short(sv_time.mon);
            loc_time.wDay = short(sv_time.day);
            loc_time.wDayOfWeek = short(sv_time.day_of_week);
            loc_time.wHour = short(sv_time.hour);
            loc_time.wMinute = short(sv_time.min);
            loc_time.wSecond = short(sv_time.sec);
            loc_time.wMilliseconds=short(mls_time+last_ping);
          }
          if(SetLocalTime(loc_time))
          {
            is_sync=true;
            Print("Local time sync is done. Symbol = ",Symbol()," Sync hour = ",loc_time.wHour, " Sync min = ",loc_time.wMinute,
                  " Sync sec = ",loc_time.wSecond," Sync ms = ",loc_time.wMilliseconds);
          }
        }
      }
    }
    else is_sync = false;
  }
}  
//+------------------------------------------------------------------+

Added by

I also don't like that the ping rarely changes in the terminal

 

The first result of the new advisor

2017.02.06 09:45:04.524 Net_switcher (Si-3.17,M1)       Local time sync is done. Symbol = Si-3.17 Sync hour = 9 Sync min = 45 Sync sec = 4 Sync ms = 524

2017.02.06 10:33:04.922 Delta_time (BR-3.17,M1) ping : 5 | time current: 2017.02.06 10:33:04 | time server: 10:33:4,710 | time local: 10:33:4,922 | delta ms: -21 | min max delta: 0 : -212
2017.02.06 10:33:08.424 Delta_time (BR-3.17,M1) ping : 5 | time current: 2017.02.06 10:33:08 | time server: 10:33:8,407 | time local: 10:33:8,424 | delta ms: -22 | min max delta: 0 : -212
2017.02.06 10:33:11.244 Delta_time (BR-3.17,M1) ping : 5 | time current: 2017.02.06 10:33:11 | time server: 10:33:11,221 | time local: 10:33:11,244 | delta ms: -25 | min max delta: 0 : -212
2017.02.06 10:33:11.830 Delta_time (BR-3.17,M1) ping : 5 | time current: 2017.02.06 10:33:11 | time server: 10:33:11,806 | time local: 10:33:11,830 | delta ms: -27 | min max delta: 0 : -212
2017.02.06 10:33:11.837 Delta_time (BR-3.17,M1) ping : 5 | time current: 2017.02.06 10:33:11 | time server: 10:33:11,806 | time local: 10:33:11,837 | delta ms: -30 | min max delta: 0 : -212
2017.02.06 10:33:12.026 Delta_time (BR-3.17,M1) ping : 5 | time current: 2017.02.06 10:33:11 | time server: 10:33:11,958 | time local: 10:33:12,26 | delta ms: -37 | min max delta: 0 : -212
 

Before the end of the morning session the time was synchronised, but at 14-01 -- 14-04 it was not :(

Apparently, this is due to the fact that the applications were only taken down.

But there is still synchronisation :)

2017.02.06 13:57:59.794 Net_switcher (Si-3.17,M1)       Local time sync is done. Sync hour = 13 Sync min = 57 Sync sec = 59 Sync ms = 794

2017.02.06 14:23:10.145 Delta_time (BR-3.17,M1) ping : 7 | time current: 2017.02.06 14:23:10 | time server: 14:23:10,121 | time local: 14:23:10,145 | delta ms: -2 | min max delta: 0 : -24
2017.02.06 14:23:10.158 Delta_time (BR-3.17,M1) ping : 7 | time current: 2017.02.06 14:23:10 | time server: 14:23:10,144 | time local: 14:23:10,158 | delta ms: -3 | min max delta: 0 : -24
2017.02.06 14:23:12.188 Delta_time (BR-3.17,M1) ping : 7 | time current: 2017.02.06 14:23:12 | time server: 14:23:12,168 | time local: 14:23:12,188 | delta ms: -5 | min max delta: 0 : -24
2017.02.06 14:23:12.188 Delta_time (BR-3.17,M1) ping : 7 | time current: 2017.02.06 14:23:12 | time server: 14:23:12,168 | time local: 14:23:12,188 | delta ms: -7 | min max delta: 0 : -24
2017.02.06 14:23:14.590 Delta_time (BR-3.17,M1) ping : 7 | time current: 2017.02.06 14:23:14 | time server: 14:23:14,569 | time local: 14:23:14,590 | delta ms: -9 | min max delta: 0 : -24
2017.02.06 14:23:14.725 Delta_time (BR-3.17,M1) ping : 7 | time current: 2017.02.06 14:23:14 | time server: 14:23:14,694 | time local: 14:23:14,725 | delta ms: -13 | min max delta: 0 : -31
2017.02.06 14:23:14.727 Delta_time (BR-3.17,M1) ping : 7 | time current: 2017.02.06 14:23:14 | time server: 14:23:14,699 | time local: 14:23:14,727 | delta ms: -15 | min max delta: 0 : -31
 

Decided on the following

int st_st_mon   = 35100; //09-45
int end_st_mon  = 36000; //10-00
int st_tr_mon   = 36060; //10-01
int end_tr_mon  = 36120; //10-02
int st_end_mon  = 50280; //13-58
int end_end_mon = 50400; //14-00
int st_st_day   = 50700; //14-05
int end_st_day  = 50760; //14-06
int st_end_day  = 67380; //18-43
int end_end_day = 67500; //18-45
int st_st_evn   = 68700; //19-05
int end_st_evn  = 68760; //19-06
int st_end_evn  = 85680; //23-48
int end_end_evn = 85800; //23-50


I think the topic is exhausted

Latest version here

https://www.mql5.com/ru/forum/167309#comment_4065302

Советники: Time sync FORTS
Советники: Time sync FORTS
  • www.mql5.com
Форум алго-трейдеров MQL5
 

Developers now have the option of adding time to glasses "in small blood

From the Spectra 5.3 release

4. technological changes.

  • Separation of the trading and clearing component

Modernization of the core and risk module of the TCS, aimed at stabilizing the system.

  • Change in the implementation of the transaction flow limiter on the TCSSPECTRAcore

In version 5.3, the gateway transaction flow limiters from clients have been replaced by a single point. In previous versions, a per-gateway restrictor was used.

  • Fixing transaction logging times with nanosecond accuracy

A new moment_ns field has been added for the flow tables broadcasting transactions and requests.

URRRAAAAAAAAAAA!

Added

Spectra 5.3 will go live on the exchange on 27 february 2017.

Added

struct MqlBookInfo
  {
   ENUM_BOOK_TYPE   type;       // тип заявки из перечисления ENUM_BOOK_TYPE
   double           price;      // цена
   long             volume;     // объем
   ulong            moment_ns;  //ООООООООО-ЧЕНЬ ЖДЁМ  
  };
 
prostotrader:

Added

struct MqlBookInfo
  {
   ENUM_BOOK_TYPE   type;       // тип заявки из перечисления ENUM_BOOK_TYPE
   double           price;      // цена
   long             volume;     // объем
   ulong            moment_ns;  //ООООООООО-ЧЕНЬ ЖДЁМ  
  };

And also for sentiment (as far as I understand the info on OI, warrants etc is called that). Millisecond would be enough there. And in general, the more accurate the better, but would like one accuracy for all possible information.
 
Alexey Kozitsyn:
And it would also be for sentiment (as far as I understand the information on OI, warrants, etc. is called that). A millisecond will suffice there. And in general, the more precise the better, but I would like one precision for all possible information.

And will the ULONG non-seconds fit in?

Added

Need to see howthe moment_ns exchange announced

In 20 days it will already be live, but

documentation is not posted yet (as always) :(

 
prostotrader:

And will the ULONG non-seconds fit in?

Added

Need to see howthe moment_ns exchange announced

In 20 days it will already be live, but

documentation is not posted yet (as always) :(

It will fit and there will still be some left over. But then again, if you take that kind of accuracy, you need to have that accuracy for all the information provided. It would, of course, be unrealistically cool, but at least let them add time in milliseconds everywhere.
 
Обращаем ваше внимание, что новый релиз Spectra 5.3 состоится 27 февраля 2017 г.,
вечерняя дополнительная торговая сессия на срочном рынке 24 февраля 2017 г.
(является торговым днем на срочном рынке) будет отменена.
Waiting for time in the glass from the developers....