Synchroniser l'heure locale de Windows avec le serveur MT5 - page 3

 
fxsaber:
Le ping doit également être divisé par deux - vous n'avez pas besoin de faire des allers-retours, mais seulement des retours.

Et si les MQs ne comptaient qu'ici ?

Ajouté par

Corrigé

Ajouté

Pour que l'EA travaille avec plus de confiance

Dans Market Watch, vous devez ajouter des données actuelles très liquides

les contrats à terme tels que RTS, Si, BR

Dossiers :
 

Nous devons encore ajouter la synchronisation à la compensation du soir.

Ajouté

Transformé en clairière également

Dossiers :
 

Il y a eu une correction à la compensation (réelle)

2017.01.18 18:56:11.852 Time_sync_forts (URKA-3.17,H1)  Local time sync is done.


Mais le résultat n'était pas du tout heureux,

était 49 secondes derrière :(

Je vérifierai le pré-marché demain....

 
Mykalas, tu es mon idole ! :-)
 
Dennis Kirichenko:
Mykalas, tu es mon idole ! :-)
Monsieur ! Que voulez-vous ?
 

Voilà le problème.

Print("Local time sync is done. Symbol = ", symbol, " Sync min = ", loc_time.wMinute,
                           " Sync sec = ", loc_time.wSecond, " Sync mcs = ", loc_time.wMilliseconds);

2017.01.18 20:05:01.743 Time_sync_forts (RTS-3.17,M1)   Local time sync is done. Symbol = RTS-3.17 Sync min = 5 Sync sec = 1 Sync mcs = 428
2017.01.18 20:05:01.869 Time_sync_forts (RTS-3.17,M1)   Local time sync is done. Symbol = Si-3.17 Sync min = 5 Sync sec = 1 Sync mcs = 475
2017.01.18 20:05:01.890 Time_sync_forts (RTS-3.17,M1)   Local time sync is done. Symbol = BR-2.17 Sync min = 5 Sync sec = 2 Sync mcs = 61
2017.01.18 20:05:01.918 Time_sync_forts (RTS-3.17,M1)   Local time sync is done. Symbol = BR-2.17 Sync min = 5 Sync sec = 2 Sync mcs = 61
2017.01.18 20:05:01.942 Time_sync_forts (RTS-3.17,M1)   Local time sync is done. Symbol = RTS-3.17 Sync min = 5 Sync sec = 1 Sync mcs = 428
2017.01.18 20:05:01.942 Time_sync_forts (RTS-3.17,M1)   Local time sync is done. Symbol = Si-3.17 Sync min = 5 Sync sec = 1 Sync mcs = 475
2017.01.18 20:05:01.983 Time_sync_forts (RTS-3.17,M1)   Local time sync is done. Symbol = RTS-3.17 Sync min = 5 Sync sec = 2 Sync mcs = 156
2017.01.18 20:05:02.055 Time_sync_forts (RTS-3.17,M1)   Local time sync is done. Symbol = BR-2.17 Sync min = 5 Sync sec = 2 Sync mcs = 61
2017.01.18 20:05:02.081 Time_sync_forts (RTS-3.17,M1)   Local time sync is done. Symbol = RTS-3.17 Sync min = 5 Sync sec = 2 Sync mcs = 156
2017.01.18 20:05:02.081 Time_sync_forts (RTS-3.17,M1)   Local time sync is done. Symbol = Si-3.17 Sync min = 5 Sync sec = 1 Sync mcs = 475
2017.01.18 20:05:02.121 Time_sync_forts (RTS-3.17,M1)   Local time sync is done. Symbol = RTS-3.17 Sync min = 5 Sync sec = 2 Sync mcs = 156
2017.01.18 20:05:02.216 Time_sync_forts (RTS-3.17,M1)   Local time sync is done. Symbol = BR-2.17 Sync min = 5 Sync sec = 2 Sync mcs = 385
2017.01.18 20:05:02.242 Time_sync_forts (RTS-3.17,M1)   Local time sync is done. Symbol = BR-2.17 Sync min = 5 Sync sec = 2 Sync mcs = 385
2017.01.18 20:05:02.255 Time_sync_forts (RTS-3.17,M1)   Local time sync is done. Symbol = RTS-3.17 Sync min = 5 Sync sec = 2 Sync mcs = 156
2017.01.18 20:05:02.255 Time_sync_forts (RTS-3.17,M1)   Local time sync is done. Symbol = Si-3.17 Sync min = 5 Sync sec = 1 Sync mcs = 475
2017.01.18 20:05:02.314 Time_sync_forts (RTS-3.17,M1)   Local time sync is done. Symbol = Si-3.17 Sync min = 5 Sync sec = 1 Sync mcs = 475
2017.01.18 20:05:02.405 Time_sync_forts (RTS-3.17,M1)   Local time sync is done. Symbol = Si-3.17 Sync min = 5 Sync sec = 1 Sync mcs = 475
2017.01.18 20:05:02.432 Time_sync_forts (RTS-3.17,M1)   Local time sync is done. Symbol = RTS-3.17 Sync min = 5 Sync sec = 2 Sync mcs = 156
2017.01.18 20:05:02.432 Time_sync_forts (RTS-3.17,M1)   Local time sync is done. Symbol = Si-3.17 Sync min = 5 Sync sec = 2 Sync mcs = 614
 

La béquille précédente était beaucoup plus élégante (à dessein), mais..,

Je vais essayer celui-là.

//+------------------------------------------------------------------+
//|                                              Time_sync_forts.mq5 |
//|                                      Copyright 2017 prostotrader |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017 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;
string   symb_rts;
string   symb_si;
string   symb_gold;
string   symb_br;
string   symb_gazr;
string   symb_sbrf;
datetime last_time;
//
input string BrInstr="BR-2.17"; //Brent
//+------------------------------------------------------------------+
//| Expert set second symbol function                                |
//+------------------------------------------------------------------+
string SetSecSymbol(const string a_symbol,const string prefix)
  {
   int str_tire=0;
   ushort let_symbol;
   int str_size=StringLen(a_symbol);

   for(int i=0; i<str_size; i++)
     {
      let_symbol=StringGetCharacter(a_symbol,i);

      if(let_symbol=='-')
        {
         str_tire=i;
         break;
        }
     }
   if(str_tire>0)
     {
      return(prefix + StringSubstr(a_symbol, str_tire, str_size - str_tire));
     }
   return("");
  }
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   last_time=TimeCurrent();
   is_sync=false;
   MarketBookAdd(Symbol());
//---  
   symb_rts=SetSecSymbol(Symbol(),"RTS");
   if(!SymbolSelect(symb_rts,true))
     {
      MessageBox(symb_rts+" not found in the Market watch!","Error",MB_OK|MB_ICONERROR);
      return(INIT_FAILED);
     }
   else MarketBookAdd(symb_rts);
//---  
   symb_si=SetSecSymbol(Symbol(),"Si");
   if(!SymbolSelect(symb_si,true))
     {
      MessageBox(symb_si+" not found in the Market watch!","Error",MB_OK|MB_ICONERROR);
      return(INIT_FAILED);
     }
   else MarketBookAdd(symb_si);
//---
   symb_gold=SetSecSymbol(Symbol(),"GOLD");
   if(!SymbolSelect(symb_gold,true))
     {
      MessageBox(symb_gold+" not found in the Market watch!","Error",MB_OK|MB_ICONERROR);
      return(INIT_FAILED);
     }
   else MarketBookAdd(symb_gold);
//---
   symb_gazr=SetSecSymbol(Symbol(),"GAZR");
   if(!SymbolSelect(symb_gazr,true))
     {
      MessageBox(symb_gazr+" not found in the Market watch!","Error",MB_OK|MB_ICONERROR);
      return(INIT_FAILED);
     }
   else MarketBookAdd(symb_gazr);
//---
   symb_sbrf=SetSecSymbol(Symbol(),"SBRF");
   if(!SymbolSelect(symb_sbrf,true))
     {
      MessageBox(symb_sbrf+" not found in the Market watch!","Error",MB_OK|MB_ICONERROR);
      return(INIT_FAILED);
     }
   else MarketBookAdd(symb_sbrf);
//---
   symb_br=BrInstr;
   if(!SymbolSelect(symb_br,true))
     {
      MessageBox(symb_br+" not found in the Market watch!","Error",MB_OK|MB_ICONERROR);
      return(INIT_FAILED);
     }
   else MarketBookAdd(symb_br);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   MarketBookRelease(Symbol());
   MarketBookRelease(symb_rts);
   MarketBookRelease(symb_br);
   MarketBookRelease(symb_si);
   MarketBookRelease(symb_gold);
   MarketBookRelease(symb_gazr);
   MarketBookRelease(symb_sbrf);
  }
//+------------------------------------------------------------------+
//| 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)) ||
         ((loc_time.wHour==14) && (loc_time.wMinute>=0) && (loc_time.wMinute<=4)) ||
         ((loc_time.wHour==18) && (loc_time.wMinute>=45) && (loc_time.wMinute<=59)))
        {
         MqlDateTime sv_time;
         datetime cur_time=TimeCurrent(sv_time);
         if(ulong(cur_time) == ulong(last_time)) return;
         if((loc_time.wDayOfWeek==ushort(sv_time.day_of_week)) &&
            (loc_time.wHour==ushort(sv_time.hour)))
           {
              
               if(!is_sync)
                 {
                  loc_time.wMinute = ushort(sv_time.min);
                  loc_time.wSecond = ushort(sv_time.sec);
                  loc_time.wMilliseconds=0;
                  if(SetLocalTime(loc_time))
                    {
                     is_sync=true;
                     Print("Local time sync is done. Symbol = ",symbol," Sync min = ",loc_time.wMinute,
                           " Sync sec = ",loc_time.wSecond);
                    }
                 }
              
           }
        }
      else
        {
         is_sync=false;
         last_time=TimeCurrent();
        }
     }
  }
//+------------------------------------------------------------------+
 
prostotrader:

La béquille précédente était beaucoup plus élégante (à dessein), mais..,

Je vais essayer celui-là.

Cela ne fonctionnera pas avecOnBookEvent, vous devez le synchroniser avec OnTick.

vous pouvez utiliser le temps de tic et prendre les données au moment du changement de verre,

timeOnBookEvent!=OnTick

 
Sergey Chalyshev:

LeOnBookEvent ne fonctionnera pas, vous devez vous synchroniser avec le OnTick.

Vous pouvez utiliser le temps de tic et obtenir les données au moment du changement de verre,

timeOnBookEvent!=OnTick

Non, Sergei !

Votre OnTick pour le symbole sélectionné pourrait même ne pas arriver, alors que OnBookEvent() sera déclenché à tout changement de

lunettes de tous les symboles sélectionnés.

 
prostotrader:

Non, Serge !

OnTick sur le symbole sélectionné peut ne pas venir, mais OnBookEvent() sera déclenché à tout changement de

lunettes de tous les symboles sélectionnés.

OnBookEvent() sera déclenché, mais l'heure du changement de coupe n'est fixée nulle part.

Seule l'heure d'arrivée du tick est fixe, c'est-à-dire le changement de l'offre, du last, du ask.

Ainsi, le taux du marché a changé, mais l'heure d'arrivée du dernier tick est la même qu'auparavant.

Raison: