"sequential" and "accurate" tick reading

 
Folks,

I am developing a trade system that aims to generate customized symbols based on the selected symbols.

For data processing, the analysis is not done on candles, but on the basis of ticks. Therefore, "sequential" and "accurate" reading is very necessary.

For this task there are the copyticks functions that obtain the necessary data from the tick cache, I made a Service that obtains the data of a selected asset on the market watch and uses the copyticks function. The data is being obtained correctly.

However, we are dealing with data that is trafficked over the network, and connection instabilities can occur.

When there is no instability, the tick data is obtained correctly.
When I simulate a network disconnection for example and activate it again, the terminal tries to recognize the disconnection.
When the terminal reconnects, the terminal fetches the information from the candles and processes the ticks again.

However, this is not the case with tick data. I understand that the ticks that were lost during the connection are not available on the terminal using the copyticks function.

But, I would expect to see the ticks when the CopyTicksRange function is triggered and the data is not based on ticks. According to the function's documentation, it interacts with the ticks database to obtain the data, if there is a hole, for example due to a disconnection or network instability, the data is requested from the server and reported to the system. The function even takes a long time to return the data when there are holes in the information due to the fact of having to search for the missing information (ticks) on the server.

However it is not what happens, is there any way to force the search for tick data on the server?

Attached I am putting a code that I am using to validate the sequential reading of ticks.

Upon detecting a failure, it tries to use the copyticksrange function to obtain a set of reliable ticks, however the same is blocked because the history is not updated.

Any help would be greatly appreciated.
Files:
 
Please provide a source code that compiles if you want help.
 
sorry,

the translator played the file he had attached, follows the code:


#property service
#property copyright "Carlos Alberto"
#property link      "https://www.mql5.com"
#property version   "1.00"

MqlTick bufferconfere[600000];
input string ativo = "WIN$D";

void OnStart() {

   MqlRates candleAtual;
   bool candleAtualFechado = false;

   MqlRates rates[];
   CopyRates( ativo,PERIOD_M1,0,1,rates);
   candleAtual = rates[0];

   while(!IsStopped()) {


      bool connectado = TerminalInfoInteger(TERMINAL_CONNECTED);

      if (!connectado){
         Print("não conectado");
         Sleep(3000);
         continue;
      }

      // verifica se o candle atual fechou
      CopyRates( ativo,PERIOD_M1,0,1,rates);
      if (rates[0].time != candleAtual.time) {
         candleAtualFechado=true;
      }


      // obtem novamente o candle atual
      CopyRates(ativo,PERIOD_M1,candleAtual.time,1,rates);
      candleAtual = rates[0];

      long inicioConferencia = candleAtual.time *1000;
      int copiados = CopyTicks(ativo,bufferconfere,COPY_TICKS_TRADE,inicioConferencia,60000);

      int ticksConferencia = 0;
      for (int i =0; i<copiados; i++)
         if (TimeToString(bufferconfere[i].time,TIME_DATE|TIME_MINUTES) == TimeToString(candleAtual.time,TIME_DATE|TIME_MINUTES))
            ticksConferencia++;


      int ticksCandle = candleAtual.tick_volume;
      int ticksHist=0;

      if (candleAtual.tick_volume != ticksConferencia) {
         Print("copia");
         long fimConferencia = ((candleAtual.time +60) *1000)-1;
         long forcaInicio = (candleAtual.time)*1000;
         
         ticksHist = CopyTicksRange(ativo,bufferconfere,COPY_TICKS_TRADE,forcaInicio,fimConferencia);
         int total = 0;
         for (int i =0; i<ticksHist; i++)
         if (TimeToString(bufferconfere[i].time,TIME_DATE|TIME_MINUTES) == TimeToString(candleAtual.time,TIME_DATE|TIME_MINUTES))
            total++;
         ticksHist = total;
         
      } else {
         ticksHist = ticksConferencia;
         
         }

      


      Print("candle:",candleAtual.tick_volume," conferencia:",ticksConferencia,", historico:",ticksHist," inicio:",candleAtual.time," error:",GetLastError()," sync:",SymbolIsSynchronized(ativo));
      Sleep(1000);

      if (ticksCandle==ticksConferencia && candleAtualFechado) {
         candleAtual.time+=60;
      }
   }
}
Descubra novos recursos para o MetaTrader 5 com a comunidade e os serviços MQL5
Descubra novos recursos para o MetaTrader 5 com a comunidade e os serviços MQL5
  • 2021.04.11
  • www.mql5.com
MQL5: linguagem de estratégias de negociação inseridas no Terminal do Cliente MetaTrader 5. A linguagem permite escrever seus próprios sistemas automáticos de negócios, indicadores técnicos, scripts e bibliotecas de funções
 
here are my impressions:

I know that mt5 caches the assets that are listed on the marketwatch.

in other versions of my delta chart generator I did not generate the data in real time. it had a 5 second leg, however i would like to process the data in realtime.

for that I am using copyticks, when doing this within an Expert Advisor, I used the ontick function, but there were ticks that were lost, and I understand that this is because any processing can cause incoming ticks to be lost.

In order to avoid this I use the ontimer function, and the problem has been solved.

however, when a network failure occurs, such as the selection of a new server or a real failure, the ticks will surely be lost.

we can see this when we compare the total ticks of the candle, with the total copied by the copyticks function. we see a difference.

Then I use the copyticksRange function, with the start and end date of the current candle, the idea is to re-synchronize the data with the broker. However it did not work. I believe it is because for really recent data the copyticksrange function also uses the market watch cache.

What I would like is a way to bypass the cache and search for the ticks on the broker's server again, in order to renew the tick database.

It would be great if it had a function that didn't use the tick cache but was on the broker's server to get the data. so that in the event of failures, we could recover by forcing data synchronization.

Note: The missing data from the ticks are synchronized at the end, however this may take a random amount of time, or when I restart the terminal and request the copyticksrange function it works. But having to restart the terminal is very bad ....

Anyway if there is any alternative, I'm all ears.