Tiki em tempo real - página 15

 
Yuriy Zaytsev:

Mas eu olho para o tronco, e o tronco mostra o mesmo tick com uma diferença de 4 segundos.

p.s.

Odeio a frase "não pode ser", já me acostumei à idéia de que tudo pode acontecer.

A propósito, talvez esteja longe do assunto, mas uma vez sobre a afirmação de que a terra é redonda também disse algo como isto - "não pode ser".

Em geral, estou sempre em dúvida até que eu verifique e, de preferência, outra pessoa verifique algumas vezes.


Você tem certeza de que não estraga o código que gera o registro e processa os dados? É uma diferença de 4 segundos.

As passagens já estão no terminal, ou seja, já foram enviadas através da rede.

Colocar o código no domínio público

if(SymbolInfoTick(Symbol(), s_tick) == true)
  {
    Print("SymbolInfoTick: ",GetTickDescription(s_tick));
  }

E veja por si mesmo.

 
prostotrader:

Os tiques já estão no terminal, ou seja, já foram transmitidos através da rede.

Colocar nele o código de acesso aberto

E veja por si mesmo.

Obrigado, vou tentar, tenho acompanhado o tema por muito tempo, estou mais interessado como pesquisador.

este código demorou 4 segundos ?

//+------------------------------------------------------------------+
//|                                                   Ticks_test.mq5 |
//|                                      Copyright 2019 prostotrader |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019 prostotrader"
#property link      "https://www.mql5.com"
#property version   "1.00"
//---
bool is_book;
MqlTick ticks[], s_tick;
ulong last_time, mem_cnt, tot_cnt;
bool is_first;
int t_cnt, result;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
  tot_cnt = 0;
  is_book = MarketBookAdd(Symbol());
  result = CopyTicks(Symbol(), ticks, COPY_TICKS_ALL, 0, 1);
  if(result > 0)
  {
    last_time = ulong(ticks[0].time_msc); //запоминаем время последнего известного тика
    is_first = true;
  }
  else
  {
    is_first = false;
    Alert("No start time!");
    return(INIT_FAILED);
  } 
  ArraySetAsSeries(ticks, true);  
  return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+ 
//| возвращает строковое описание тика                               | 
//+------------------------------------------------------------------+ 
string GetTickDescription(MqlTick &tick) 
  { 
   string res = string(tick.time) + "." +  string(tick.time_msc%1000); 
// 
   bool buy_tick = ((tick.flags&TICK_FLAG_BUY)==TICK_FLAG_BUY); 
   bool sell_tick = ((tick.flags&TICK_FLAG_SELL)==TICK_FLAG_SELL); 
   bool ask_tick = ((tick.flags&TICK_FLAG_ASK)==TICK_FLAG_ASK); 
   bool bid_tick = ((tick.flags&TICK_FLAG_BID)==TICK_FLAG_BID); 
   bool last_tick = ((tick.flags&TICK_FLAG_LAST)==TICK_FLAG_LAST); 
   bool volume_tick = ((tick.flags&TICK_FLAG_VOLUME)==TICK_FLAG_VOLUME); 
// 
   if((buy_tick== true) || (sell_tick == true)) 
   { 
     res = res + (buy_tick?StringFormat(" Buy Tick: Last=%G Volume=%d ",tick.last,tick.volume):""); 
     res = res + (sell_tick?StringFormat(" Sell Tick: Last=%G Volume=%d ",tick.last,tick.volume):""); 
     res = res + (ask_tick?StringFormat(" Ask=%G ",tick.ask):""); 
     res = res + (bid_tick?StringFormat(" Bid=%G ",tick.bid):""); 
   } 
   else 
   { 
     res = res + (ask_tick?StringFormat(" Ask=%G ",tick.ask):""); 
     res = res + (bid_tick?StringFormat(" Bid=%G ",tick.bid):""); 
     res = res + (last_tick?StringFormat(" Last=%G ",tick.last):""); 
     res = res + (volume_tick?StringFormat(" Volume=%d ",tick.volume):""); 
   } 
   return res; 
  } 
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
  if(is_book == true) MarketBookRelease(Symbol());
}
//+------------------------------------------------------------------+
//| BookEvent function                                               |
//+------------------------------------------------------------------+
void OnBookEvent(const string &symbol)
{
  if(symbol != Symbol()) return;
  tot_cnt++;
  if(SymbolInfoTick(Symbol(), s_tick) == true)
  {
    Print("SymbolInfoTick: ",GetTickDescription(s_tick));
  }
  if(is_first == true)
  {
    result = CopyTicks(Symbol(), ticks, COPY_TICKS_ALL, last_time, 0); //копируем все вновь пришедшие тики от последнего известного времени
    if(result > 0)
    {
      t_cnt = 0;
      for(int i= 0; i<result; i++)
      {
        if(ticks[i].time_msc == ticks[0].time_msc) t_cnt++;             //Считаем кол-во тиков с одинаковым временем
        Print(__FUNCTION__, ": ",GetTickDescription(ticks[i]));
      }
    //  l_tick = ticks[0];
      is_first = false;
      last_time = ulong(ticks[0].time_msc);                             //Запоминаем время последнего тика
    } 
  }
  else
  {
    if(SymbolInfoTick(Symbol(), s_tick) == true)
    {
      Print("SymbolInfoTick: ",GetTickDescription(s_tick));
    }
    result = CopyTicks(Symbol(), ticks, COPY_TICKS_ALL, last_time, 0); //забираем тики из последнего (посчитанного пакета тикив и считываем тики из нового пакета)
    if(result > 0)
    {
     // l_tick = ticks[0];
      if(result > t_cnt)
      {
        mem_cnt = t_cnt;
        t_cnt = 0;
        for(int i= 0; i<(result - int(mem_cnt)); i++)
        {
          if(ticks[i].time_msc == ticks[0].time_msc) t_cnt++;           //Считаем кол-во тиков с одинаковым временем
          Print(__FUNCTION__, ": ",GetTickDescription(ticks[i]));
        } 
        if(last_time == ulong(ticks[0].time_msc))
        {
          t_cnt += int(mem_cnt);
        }
        else last_time = ulong(ticks[0].time_msc);
      }
      else
      {
        Print(__FUNCTION__, ": Pending order!");                          //Изменения стакана (добавлен/удален отложенный ордер)
      }
    }
    else
    {
      Print(__FUNCTION__, ": Pending order!");                          //Изменения стакана (добавлен/удален отложенный ордер)
    }
  }
}
//+------------------------------------------------------------------+
 

Não parece ser este aqui.

não veja OnTick no código

 

Aparentemente, este era o código em questão

//+------------------------------------------------------------------+
//|                                                   Ticks_test.mq5 |
//|                                      Copyright 2019 prostotrader |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019 prostotrader"
#property link      "https://www.mql5.com"
#property version   "1.00"
//---
bool is_book;
MqlTick ticks[];
ulong last_time, mem_cnt, tot_cnt;
bool is_first;
int t_cnt, result;
enum ENUM_BOOK_OR_TICK
{
        USE_BOOK,       // Use OnBookEvent
        USE_TICK        // Use OnTick
};

input ENUM_BOOK_OR_TICK Mode = USE_BOOK;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
  tot_cnt = 0;
  if(Mode == USE_BOOK) is_book = MarketBookAdd(Symbol());
  result = CopyTicks(Symbol(), ticks, COPY_TICKS_ALL, 0, 1);
  if(result > 0)
  {
    last_time = ulong(ticks[0].time_msc); //запоминаем время последнего известного тика
    is_first = true;
  }
  else
  {
    is_first = false;
    Alert("No start time!");
    return(INIT_FAILED);
  } 
  ArraySetAsSeries(ticks, true);  
  return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+ 
//| возвращает строковое описание тика                               | 
//+------------------------------------------------------------------+ 
string GetTickDescription(MqlTick &tick) 
  { 
   string res = string(tick.time) + "." +  string(tick.time_msc%1000); 
// 
   bool buy_tick = ((tick.flags&TICK_FLAG_BUY)==TICK_FLAG_BUY); 
   bool sell_tick = ((tick.flags&TICK_FLAG_SELL)==TICK_FLAG_SELL); 
   bool ask_tick = ((tick.flags&TICK_FLAG_ASK)==TICK_FLAG_ASK); 
   bool bid_tick = ((tick.flags&TICK_FLAG_BID)==TICK_FLAG_BID); 
   bool last_tick = ((tick.flags&TICK_FLAG_LAST)==TICK_FLAG_LAST); 
   bool volume_tick = ((tick.flags&TICK_FLAG_VOLUME)==TICK_FLAG_VOLUME); 
// 
   if((buy_tick== true) || (sell_tick == true)) 
   { 
     res = res + (buy_tick?StringFormat(" Buy Tick: Last=%G Volume=%d ",tick.last,tick.volume):""); 
     res = res + (sell_tick?StringFormat(" Sell Tick: Last=%G Volume=%d ",tick.last,tick.volume):""); 
     res = res + (ask_tick?StringFormat(" Ask=%G ",tick.ask):""); 
     res = res + (bid_tick?StringFormat(" Bid=%G ",tick.bid):""); 
   } 
   else 
   { 
     res = res + (ask_tick?StringFormat(" Ask=%G ",tick.ask):""); 
     res = res + (bid_tick?StringFormat(" Bid=%G ",tick.bid):""); 
     res = res + (last_tick?StringFormat(" Last=%G ",tick.last):""); 
     res = res + (volume_tick?StringFormat(" Volume=%d ",tick.volume):""); 
   } 
   return res; 
  } 
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
  if(Mode == USE_BOOK)
  {
    Print("USE_BOOK ticks received: ", tot_cnt);
    if(is_book == true) MarketBookRelease(Symbol());
  }
  else
  {
    Print("USE_TICK ticks received: ", tot_cnt);
  }  
}
//+------------------------------------------------------------------+
//| BookEvent function                                               |
//+------------------------------------------------------------------+
void OnBookEvent(const string &symbol)
{
  if ( Mode != USE_BOOK || symbol != Symbol() ) return;
  tot_cnt++;
  if(is_first == true)
  {
    result = CopyTicks(Symbol(), ticks, COPY_TICKS_ALL, last_time, 0); //копируем все вновь пришедшие тики от последнего известного времени
    if(result > 0)
    {
      t_cnt = 0;
      for(int i= 0; i<result; i++)
      {
        if(ticks[i].time_msc == ticks[0].time_msc) t_cnt++;             //Считаем кол-во тиков с одинаковым временем
        Print(__FUNCTION__, ": ",GetTickDescription(ticks[i]));
      }
      is_first = false;
      last_time = ulong(ticks[0].time_msc);                             //Запоминаем время последнего тика
    } 
  }
  else
  {
    result = CopyTicks(Symbol(), ticks, COPY_TICKS_ALL, last_time, 0); //забираем тики из последнего (посчитанного пакета тикив и считываем тики из нового пакета)
    if(result > 0)
    {
      if(result > t_cnt)
      {
        mem_cnt = t_cnt;
        t_cnt = 0;
        for(int i= 0; i<(result - int(mem_cnt)); i++)
        {
          if(ticks[i].time_msc == ticks[0].time_msc) t_cnt++;           //Считаем кол-во тиков с одинаковым временем
          Print(__FUNCTION__, ": ",GetTickDescription(ticks[i]));
        } 
        if(last_time == ulong(ticks[0].time_msc))
        {
          t_cnt += int(mem_cnt);
        }
        else last_time = ulong(ticks[0].time_msc);
      }
      else
      {
        Print(__FUNCTION__, ": Pending order!");                          //Изменения стакана (добавлен/удален отложенный ордер)
      }
    }
    else
    {
      Print(__FUNCTION__, ": Pending order!");                            //Изменения стакана (добавлен/удален отложенный ордер)
    }
  }
}
//+------------------------------------------------------------------+
//| OnTick function                                                  |
//+------------------------------------------------------------------+
void OnTick()
{
  if ( Mode != USE_TICK ) return;
  tot_cnt++;
  if(is_first == true)
  {
    result = CopyTicks(Symbol(), ticks, COPY_TICKS_ALL, last_time, 0); //копируем все вновь пришедшие тики от последнего известного времени
    if(result > 0)
    {
      t_cnt = 0;
      for(int i= 0; i<result; i++)
      {
        if(ticks[i].time_msc == ticks[0].time_msc) t_cnt++;             //Считаем кол-во тиков с одинаковым временем
        Print(__FUNCTION__, ": ",GetTickDescription(ticks[i]));
      }
      is_first = false;
      last_time = ulong(ticks[0].time_msc);                             //Запоминаем время последнего тика
    } 
  }
  else
  {
    result = CopyTicks(Symbol(), ticks, COPY_TICKS_ALL, last_time, 0); //забираем тики из последнего (посчитанного пакета тикив и считываем тики из нового пакета)
    if(result > 0)
    {
      if(result > t_cnt)
      {
        mem_cnt = t_cnt;
        t_cnt = 0;
        for(int i= 0; i<(result - int(mem_cnt)); i++)
        {
          if(ticks[i].time_msc == ticks[0].time_msc) t_cnt++;           //Считаем кол-во тиков с одинаковым временем
          Print(__FUNCTION__, ": ",GetTickDescription(ticks[i]));
        } 
        if(last_time == ulong(ticks[0].time_msc))
        {
          t_cnt += int(mem_cnt);
        }
        else last_time = ulong(ticks[0].time_msc);
      }
      else
      {
        Print(__FUNCTION__, ": Pending order!");                          //Изменения стакана (добавлен/удален отложенный ордер)
      }
    }
    else
    {
      Print(__FUNCTION__, ": Pending order!");                          //Изменения стакана (добавлен/удален отложенный ордер)
    }
  }
}
//+------------------------------------------------------------------+
 

Acrescentei meu tempo ao código.

Lembro-me do tempo em que OnTick() foi acionado(t_time = GetMicrosecondCount();)

Então eu levo tempo, quando cada função é executada

   t_time = GetMicrosecondCount();
//  if(symbol != Symbol()) return;
  //tot_cnt++;
  if(SymbolInfoTick(Symbol(), s_tick) == true)
  {
    func_time = GetMicrosecondCount();
    Print("SymbolInfoTick: time = ", string(func_time - t_time), " mcs ", GetTickDescription(s_tick));
  }
  double a_ask, a_bid, a_last;
  if (SymbolInfoDouble(Symbol(), SYMBOL_ASK, a_ask) == true)
  {
    func_time = GetMicrosecondCount();
    Print("SymbolInfoDouble: time = ", string(func_time - t_time), " mcs ", "ask = ", a_ask);
  }
  if (SymbolInfoDouble(Symbol(), SYMBOL_BID, a_bid) == true)
  {
    func_time = GetMicrosecondCount();
    Print("SymbolInfoDouble: time = ", string(func_time - t_time), " mcs ", "bid = ", a_bid);
  }
  if (SymbolInfoDouble(Symbol(), SYMBOL_LAST, a_last) == true)
  {
    func_time = GetMicrosecondCount();
    Print("SymbolInfoDouble: time = ", string(func_time - t_time), " mcs ", "last = ", a_last);
  }
  if(is_first == true)
  {
    result = CopyTicks(Symbol(), ticks, COPY_TICKS_ALL, last_time, 0); //копируем все вновь пришедшие тики от последнего известного времени
    if(result > 0)
    {
      func_time = GetMicrosecondCount();
      t_cnt = 0;
      for(int i= 0; i<result; i++)
      {
        if(ticks[i].time_msc == ticks[0].time_msc) t_cnt++;             //Считаем кол-во тиков с одинаковым временем
        Print(__FUNCTION__, ": time = ", string(func_time - t_time), " mcs ", GetTickDescription(ticks[i]));

O resultado é

2020.02.04 13:09:13.101 Ticks_test (GOLD-3.20,M1)       SymbolInfoTick: time = 2 mcs 2020.02.04 13:09:10.720 Bid=1573.1 
2020.02.04 13:09:13.101 Ticks_test (GOLD-3.20,M1)       SymbolInfoDouble: time = 28 mcs ask = 1573.3
2020.02.04 13:09:13.101 Ticks_test (GOLD-3.20,M1)       SymbolInfoDouble: time = 33 mcs bid = 1573.1
2020.02.04 13:09:13.101 Ticks_test (GOLD-3.20,M1)       SymbolInfoDouble: time = 36 mcs last = 1573.4
2020.02.04 13:09:13.101 Ticks_test (GOLD-3.20,M1)       OnTick: time = 41 mcs 2020.02.04 13:09:10.720 Bid=1573.1 
2020.02.04 13:09:13.101 Ticks_test (GOLD-3.20,M1)       OnTick: time = 41 mcs 2020.02.04 13:09:00.328 Ask=1573.3 

Isto é, o tempo de funcionamento de cada função é inferior a 50 microssegundos!

De onde podem vir 4 segundos?

Acho que dois EAs estavam funcionando em um terminal e o terminal simplesmente não tem tempo para

Ela simplesmente não tem tempo para "fundir" todas as informações em um único registro, de modo que fixa a hora local conforme considera necessário.

 
prostotrader:

No comércio, pessoalmente, uso ordens assíncronas.

A questão é (se você negocia seriamente na Bolsa), você precisa de todas as mudanças no mercado de ações,

e quanto mais cedo este evento chegar - melhor.

Eu, por mim mesmo, não vejo alternativa ao OnBook

Em princípio, é possível aliviar a invocação direta de operações comerciais da OnBook. Tudo o que você precisa fazer no OnBook é formar uma bandeira para executar a operação e processar a própria bandeira em outro lugar. Ou seja, a própria operação deve ser iniciada em outro procedimento pela bandeira formada, que criará um evento, mas depois de sair do procedimento HeBook, e então o próprio código OnBook estará livre de operações pesadas. Entretanto, se as ordens forem abertas de forma assíncrona, e não houver um processamento insanamente grande das condições, é pouco provável que isso cause atrasos significativos.

 
prostotrader:

Acrescentei meu tempo ao código.

Lembro-me do tempo em que OnTick() foi acionado(t_time = GetMicrosecondCount();)

Então eu levo tempo, quando cada função é executada

O resultado é

Isto é, o tempo de funcionamento de cada função é inferior a 50 microssegundos!

De onde podem vir 4 segundos?

Acho que dois EAs estavam funcionando em um terminal e o terminal simplesmente não tem tempo para

O terminal simplesmente não tem tempo para "despejar" todas as informações em um único arquivo de registro e é por isso que ele define a hora local como achar necessário.

Acho que é verdade, um atraso tão grande não é realista.


1 - A FLUSH trabalhou quando a própria MQ o decidiu!

2 - Atraso técnico na gravação em disco devido ao trabalho intensivo no disco rígido


É possível que já exista uma fila de gravação em sua máquina local - o que é bem real, eu tive a experiência de vários terabytes de backup sendo despejados no disco

Só posso assumir o seguinte:

Tive vários terabytes de backup buscados no disco, por exemplo, se eu executava o Microsoft Office, atualizava meu Windows e gravavava filmes da Internet, ou se eu trabalhava com MS SQL na máquina local ao mesmo tempo,

fazer um par de backups, ter uma dúzia de 4 torrents e duas ou três dúzias de programas gravados intensamente em disco.

ou seja, se houve um trabalho intensivo com o disco - é possível e houve um atraso na gravação do registro em disco.

 
Yuriy Zaytsev:

Provavelmente é verdade, não é realista com um atraso tão grande.


1 - FLUSH funcionou quando a MQ decidiu isto por si só!

2 - Atraso técnico na gravação em disco causado por um trabalho intensivo no disco rígido.


É possível que alguma fila já esteja em sua máquina local para registro - o que é bem real, eu tive a experiência de vários terabytes de backup sendo despejados no disco

Só posso assumir o seguinte:

Tive vários terabytes de backup buscados no disco, por exemplo, se eu rodei o escritório Mac irosoft, atualizei meu Windows e gravei filmes da Internet, ou se eu trabalhei com MS SQL na máquina local ao mesmo tempo,

fazer um par de backups, ter uma dúzia de 4 torrents e duas ou três dúzias de programas gravados intensivamente em disco.

Se houvesse um trabalho intensivo com o disco - é possível que houvesse um atraso no registro em disco.

Dificilmente relacionado ao disco, a MT coloca o tempo já ao escrever o registro em seu cache. Foi o que eu pensei que o terminal em geral por 4 segundos pode estar relacionado à carga geral do sistema, mais provavelmente RAM e CPU.
 
prostotrader:

Acrescentei meu tempo ao código.

Lembro-me do tempo em que OnTick() foi acionado(t_time = GetMicrosecondCount();)

Então eu levo tempo, quando cada função é executada

O resultado é

Isto é, o tempo de funcionamento de cada função é inferior a 50 microssegundos!

De onde podem vir 4 segundos?

Acho que dois EAs estavam funcionando em um terminal e o terminal simplesmente não tem tempo para

"Por isso, ele estabelece a hora local como considerar necessário.

A propósito - para que você não fique preso no tempo de registro - você pode adicionar a hora local à matriz - que você forma no código - abaixo

Então haverá uma clara diferença no registro entre o momento em que o terminal reinicializa o registro em disco e o momento em que o OnBook's tick ou evento chegou localmente.

E isto será mais correto do ponto de vista da pesquisa.

//+------------------------------------------------------------------+ 
//| возвращает строковое описание тика                               | 
//+------------------------------------------------------------------+ 
string GetTickDescription(MqlTick &tick) 
  { 
   string res = string(tick.time) + "." +  string(tick.time_msc%1000); 
// 
   bool buy_tick = ((tick.flags&TICK_FLAG_BUY)==TICK_FLAG_BUY); 
   bool sell_tick = ((tick.flags&TICK_FLAG_SELL)==TICK_FLAG_SELL); 
   bool ask_tick = ((tick.flags&TICK_FLAG_ASK)==TICK_FLAG_ASK); 
   bool bid_tick = ((tick.flags&TICK_FLAG_BID)==TICK_FLAG_BID); 
   bool last_tick = ((tick.flags&TICK_FLAG_LAST)==TICK_FLAG_LAST); 
   bool volume_tick = ((tick.flags&TICK_FLAG_VOLUME)==TICK_FLAG_VOLUME); 
// 
   if((buy_tick== true) || (sell_tick == true)) 
   { 
     res = res + (buy_tick?StringFormat(" Buy Tick: Last=%G Volume=%d ",tick.last,tick.volume):""); 
     res = res + (sell_tick?StringFormat(" Sell Tick: Last=%G Volume=%d ",tick.last,tick.volume):""); 
     res = res + (ask_tick?StringFormat(" Ask=%G ",tick.ask):""); 
     res = res + (bid_tick?StringFormat(" Bid=%G ",tick.bid):""); 
   } 
   else 
   { 
     res = res + (ask_tick?StringFormat(" Ask=%G ",tick.ask):""); 
     res = res + (bid_tick?StringFormat(" Bid=%G ",tick.bid):""); 
     res = res + (last_tick?StringFormat(" Last=%G ",tick.last):""); 
     res = res + (volume_tick?StringFormat(" Volume=%d ",tick.volume):""); 
   } 
   return res; 
  } 
 
Aleksey Mavrin:
Dificilmente conectado com o disco, a MT define o tempo já ao gravar o log em seu cache. Foi o que eu pensei que o terminal em geral por 4 segundos pode estar relacionado com a carga geral do sistema, mais propriamente RAM e CPU.

VOCÊ TEM CERTEZA DISSO?


4 segundos ????, de jeito nenhum! Você realmente acha que o processador congelou por 4 segundos ou a memória foi liberada por 4 segundos? Você está brincando?

É mais provável que seja a fila de gravação no disco.

O disco é mais lento que a memória e o processador.

O comando flush() é um comando C, você provavelmente o conhece e é executado quando se sente confortável e pode ser atrasado com mais freqüência devido à inicialização em disco.

É assim que eles chamam quando você quer despejar os amortecedores no disco.