Windows yerel saatinin MT5 sunucusuyla senkronizasyonu - sayfa 2

 
Kodla ilgili başka bir isteğiniz veya yorumunuz var mı?
 
prostotrader :
Önemsiz (milisaniye) ve yüzüyor, "hava durumu" yaratmayacağını düşünüyorum.
authorized on BCS-MetaTrader5 through Access Server # 1 ( ping: 50.30 ms )
12:29: 59.970 saatini alırsanız, saati tam olarak 12:30 olarak ayarlamanız gerekir.
 
fxsaber :
authorized on BCS-MetaTrader5 through Access Server # 1 ( ping: 50.30 ms )
12:29:59.970 saatini alırsanız, saati tam olarak 12:30 olarak ayarlamanız gerekir.

Evet, muhtemelen yüksek bir pinginiz var (4-6 ms'm var)

Ping almanın en iyi yolu nedir?

Katma

Herkes ortalama pingini biliyor, belki sadece sabit olarak girin

input ushort Ping = 5 ; //Средний пинг
 
prostotrader :

Ping almanın en iyi yolu nedir?

TERMINAL_PING_LAST
 
fxsaber :
TERMINAL_PING_LAST
Teşekkürler, bilmiyordum, koda koyacağım.
 
// loc_time.wMilliseconds=ushort(ulong(curr_tick[0].time_msc)-ulong(curr_tick[0].time)*1000); // Было
loc_time.wMilliseconds=ushort(curr_tick[0].time_msc % 1000); // Стало
 

Değerli yorumlar için fxsaber'a teşekkürler, işte olanlar

//+------------------------------------------------------------------+
//|                                              Time_sync_forts.mq5 |
//|                                      Copyright 2016 prostotrader |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016 prostotrader"
#property link        "https://www.mql5.com"
#property version    "1.00"
//---
struct _SYSTEMTIME
  {
   ushort             wYear;
   ushort             wMonth;
   ushort             wDayOfWeek;
   ushort             wDay;
   ushort             wHour;
   ushort             wMinute;
   ushort             wSecond;
   ushort             wMilliseconds;
  };

_SYSTEMTIME loc_time;

#import "kernel32.dll"
void GetLocalTime(_SYSTEMTIME &sys_time);
bool SetLocalTime(_SYSTEMTIME &sys_time);
#import
//---
bool is_sync;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit ()
  {
   is_sync= false ;
   MarketBookAdd ( Symbol ());
   return ( INIT_SUCCEEDED );
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit ( const int reason)
  {
   MarketBookRelease ( Symbol ());
  }
//+------------------------------------------------------------------+
//| Expert On book event function                                    |
//+------------------------------------------------------------------+
bool ConvertToTime( const long n_value,_SYSTEMTIME  &a_time)
  {
   a_time.wMilliseconds= ushort (n_value% 1000 );
   ulong new_time=( ulong (n_value)- ulong (a_time.wMilliseconds))/ 1000 ;
   MqlDateTime cur_time;
   cur_time.year= 0 ;
   TimeToStruct ( datetime (new_time),cur_time);
   if (cur_time.year> 0 )
     {
      a_time.wDay= ushort (cur_time.day);
      a_time.wDayOfWeek= ushort (cur_time.day_of_week);
      a_time.wHour= ushort (cur_time.hour);
      a_time.wMinute= ushort (cur_time.min);
      a_time.wMonth = ushort (cur_time.mon);
      a_time.wSecond= ushort (cur_time.sec);
      a_time.wYear= ushort (cur_time.year);
       return ( true );
     }
   return ( false );
  }
//+------------------------------------------------------------------+
//| Expert On book event function                                    |
//+------------------------------------------------------------------+
void OnBookEvent ( const string &symbol)
  {
   loc_time.wYear= 0 ;
   GetLocalTime(loc_time);
   if (loc_time.wYear> 0 )
     {
       if ((loc_time.wHour== 9 ) && (loc_time.wMinute>= 50 ) && (loc_time.wMinute<= 59 ))
        {
         MqlTick curr_tick[ 1 ];
         if ( CopyTicks (symbol,curr_tick, COPY_TICKS_ALL , 0 , 1 )== 1 )
           {
             MqlDateTime sv_time;
             TimeToStruct (curr_tick[ 0 ].time,sv_time);
             if (!is_sync)
              {
               long last_ping= long ( NormalizeDouble ( double ( TerminalInfoInteger ( TERMINAL_PING_LAST ))/ 1000 , 0 ));
               if ((loc_time.wDayOfWeek== ushort (sv_time.day_of_week)) &&
                  (loc_time.wHour== ushort (sv_time.hour)))
                 {
                   long mcs_time= long (curr_tick[ 0 ].time_msc% 1000 );
                   if ((mcs_time+last_ping)> 999 )
                    {
                     mcs_time= long (curr_tick[ 0 ].time_msc)+last_ping;
                     if (!ConvertToTime(mcs_time, loc_time)) return ;
                    }
                   else
                    {
                     loc_time.wMinute = ushort (sv_time.min);
                     loc_time.wSecond = ushort (sv_time.sec);
                     loc_time.wMilliseconds= ushort (mcs_time);
                    }

                   if (SetLocalTime(loc_time))
                    {
                     is_sync= true ;
                     Print ( "Local time sync is done." );
                    }
                 }
              }
           }
        }
       else is_sync= false ;
     }
  }
//+------------------------------------------------------------------+
 
Çok akıllı bir şey. Okumadım, aceleye geldi
//   ulong new_time=(ulong(n_value)-ulong(a_time.wMilliseconds))/1000;
   ulong new_time= ulong (n_value / 1000 );
   MqlDateTime cur_time = { 0 };
//   cur_time.year=0;

//.......
//               long last_ping=long(NormalizeDouble(double(TerminalInfoInteger(TERMINAL_PING_LAST))/1000,0));
             long last_ping= long ( TerminalInfoInteger ( TERMINAL_PING_LAST ))/ 2000.0 + 0.5 );
 
fxsaber :
Çok akıllı bir şey. Okumadım sadece aceleye geldi
//   ulong new_time=(ulong(n_value)-ulong(a_time.wMilliseconds))/1000;
   ulong new_time= ulong (n_value / 1000 );
   MqlDateTime cur_time = { 0 };
//   cur_time.year=0;

//.......
//               long last_ping=long(NormalizeDouble(double(TerminalInfoInteger(TERMINAL_PING_LAST))/1000,0));
             long last_ping= long ( TerminalInfoInteger ( TERMINAL_PING_LAST ))/ 2000.0 + 0.5 );

:)

//+------------------------------------------------------------------+
//|                                              Time_sync_forts.mq5 |
//|                                      Copyright 2016 prostotrader |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016 prostotrader"
#property link        "https://www.mql5.com"
#property version    "1.00"
//---
struct _SYSTEMTIME
  {
   ushort             wYear;
   ushort             wMonth;
   ushort             wDayOfWeek;
   ushort             wDay;
   ushort             wHour;
   ushort             wMinute;
   ushort             wSecond;
   ushort             wMilliseconds;
  };

_SYSTEMTIME loc_time;

#import "kernel32.dll"
void GetLocalTime(_SYSTEMTIME &sys_time);
bool SetLocalTime(_SYSTEMTIME &sys_time);
#import
//---
bool is_sync;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit ()
  {
   is_sync= false ;
   MarketBookAdd ( Symbol ());
   return ( INIT_SUCCEEDED );
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit ( const int reason)
  {
   MarketBookRelease ( Symbol ());
  }
//+------------------------------------------------------------------+
//| Expert On book event function                                    |
//+------------------------------------------------------------------+
bool ConvertToTime( const long n_value,_SYSTEMTIME  &a_time)
  {
   a_time.wMilliseconds= ushort (n_value% 1000 );
   ulong new_time= ulong (double(n_value)/ 1000 );
   MqlDateTime cur_time = { 0 };
   TimeToStruct ( datetime (new_time),cur_time);
   if (cur_time.year> 0 )
     {
      a_time.wDay= ushort (cur_time.day);
      a_time.wDayOfWeek= ushort (cur_time.day_of_week);
      a_time.wHour= ushort (cur_time.hour);
      a_time.wMinute= ushort (cur_time.min);
      a_time.wMonth = ushort (cur_time.mon);
      a_time.wSecond= ushort (cur_time.sec);
      a_time.wYear= ushort (cur_time.year);
       return ( true );
     }
   return ( false );
  }
//+------------------------------------------------------------------+
//| Expert On book event function                                    |
//+------------------------------------------------------------------+
void OnBookEvent ( const string &symbol)
  {
   loc_time.wYear= 0 ;
   GetLocalTime(loc_time);
   if (loc_time.wYear> 0 )
     {
       if ((loc_time.wHour== 9 ) && (loc_time.wMinute>= 50 ) && (loc_time.wMinute<= 59 ))
        {
         MqlTick curr_tick[ 1 ];
         if ( CopyTicks (symbol,curr_tick, COPY_TICKS_ALL , 0 , 1 )== 1 )
           {
             MqlDateTime sv_time;
             TimeToStruct (curr_tick[ 0 ].time,sv_time);
             if (!is_sync)
              {
               long last_ping= long ( NormalizeDouble ( double ( TerminalInfoInteger ( TERMINAL_PING_LAST ))/ 1000 , 0 ));
               if ((loc_time.wDayOfWeek== ushort (sv_time.day_of_week)) &&
                  (loc_time.wHour== ushort (sv_time.hour)))
                 {
                   long mcs_time= long (curr_tick[ 0 ].time_msc% 1000 );
                   if ((mcs_time+last_ping)> 999 )
                    {
                     mcs_time= long (curr_tick[ 0 ].time_msc)+last_ping;
                     if (!ConvertToTime(mcs_time, loc_time)) return ;
                    }
                   else
                    {
                     loc_time.wMinute = ushort (sv_time.min);
                     loc_time.wSecond = ushort (sv_time.sec);
                     loc_time.wMilliseconds= ushort (mcs_time);
                    }

                   if (SetLocalTime(loc_time))
                    {
                     is_sync= true ;
                     Print ( "Local time sync is done." );
                    }
                 }
              }
           }
        }
       else is_sync= false ;
     }
  }
//+------------------------------------------------------------------+
 
Ping yarıya bölünmelidir - ileri geri değil, sadece geriye ihtiyacınız var.