A minute and a half difference between local time and fresh tick time. What to do. - page 4

 

I've discovered the following: sometimes the OnTick event handles ticks in the wrong timing order (rare but not uncommon). First there is a later tick, and then an earlier one. Therefore, I have made it a rule in my Expert Advisors to count ticks and indicators (which I need). And I simply discard "bad ticks".

PS: I noticed this due to the "strange" behaviour of my robots (sometimes it happens). You look at the chart and "on your logic" - there's no opening rule, but the EA has opened. You start poking around and looking for it. I find "such strange ticks". If you remove them, the Expert Advisor starts working "correctly", i.e. according to my logic.

 
Alexey Kozitsyn:

Please provide a piece of code that catches delays. Right here, through the code insert button.

//+----------------------------------------------------------------------------+
//|  Проверяем не установлили ли новые рекорды.                                |
//+----------------------------------------------------------------------------+
void PitaemsayObnovitRekordi(CInformaziaOPoslednemTike &InformaziaOPoslednemTike[], int NomerSimolaS_NovimTikom )
  {   
//---  1. Определяем время и символ(ипользуется только для вывода информации)  самого свещего тика по всем символам.
//---  2. Вычисляем разность. Время самого свежего тика по всем символам МИНУС время последнего тика по проверяемому символу.
//---  3. Обновляем глобальные строки для функции Comment.
//---  4. Обновляем глобальные строки для функции Comment если установлен рекорд.
   static long RekordRaznosti=        -1;
  
   static long SymmaRaznostei=       0;
   static long KolichestvoPolychenixNovixTikov= 0;
     
//---  1. Определяем время и символ(ипользуется только для вывода информации)  самого свещего тика по всем символам.
   long VremaySamogoSvegegoTikaPoVsemSimvolam= 0; 
   int IndeksSimvolaS_SamimSvegimTikom= 0;   
   for(int i=0; i<KolichestvoSimvolov; i++)     
   if( InformaziaOPoslednemTike[i].LastTick.time_msc > VremaySamogoSvegegoTikaPoVsemSimvolam ) {VremaySamogoSvegegoTikaPoVsemSimvolam= InformaziaOPoslednemTike[i].LastTick.time_msc;IndeksSimvolaS_SamimSvegimTikom=i;}
   
//---  2. Вычисляем разность. Время самого свежего тика по всем символам МИНУС время последнего тика по проверяемому символу.
   long Rasnost= VremaySamogoSvegegoTikaPoVsemSimvolam - InformaziaOPoslednemTike[NomerSimolaS_NovimTikom].LastTick.time_msc;
//---    
   SymmaRaznostei+= Rasnost;
   KolichestvoPolychenixNovixTikov++;
   
//---  3. Обновляем глобальные строки для функции Comment. 
   StringConcatenate(GStrokaDlayComment[2]," Самый свежий тик ",InformaziaOPoslednemTike[IndeksSimvolaS_SamimSvegimTikom].Simvol," time_msc ",PrintMilesekond(InformaziaOPoslednemTike[IndeksSimvolaS_SamimSvegimTikom].LastTick.time_msc));
   if( ((VremaySamogoSvegegoTikaPoVsemSimvolam-StartTimeMsc)/1000) != 0 )
     {StringConcatenate(GStrokaDlayComment[3]," Средняя разность ",SymmaRaznostei/KolichestvoPolychenixNovixTikov," милесекунд. Количество полученных новых тиков ",KolichestvoPolychenixNovixTikov," Количество новых тиков в секунду ",KolichestvoPolychenixNovixTikov/((VremaySamogoSvegegoTikaPoVsemSimvolam-StartTimeMsc)/1000) );}
     
//---  4. Обновляем глобальные строки для функции Comment если установлен рекорд.    
   if( RekordRaznosti < Rasnost ) 
     {
      RekordRaznosti= Rasnost;
      GStrokaDlayComment[4]="--------------------------------------------------------------------------------";      
      StringConcatenate(GStrokaDlayComment[5],"РЕКОРДная  Разница между временем последенго тика по ВСЕМ символам Минус только, что полученный новый тик по символу ",RekordRaznosti," милесекундa.");
      StringConcatenate(GStrokaDlayComment[6]," Получен НОВЫЙ тик по символу                     ",InformaziaOPoslednemTike[NomerSimolaS_NovimTikom].Simvol," time_msc= ",PrintMilesekond(InformaziaOPoslednemTike[NomerSimolaS_NovimTikom].LastTick.time_msc));      
      StringConcatenate(GStrokaDlayComment[7]," ХОТЯ до этого был получeн тик                        ",InformaziaOPoslednemTike[IndeksSimvolaS_SamimSvegimTikom].Simvol," time_msc ",PrintMilesekond(InformaziaOPoslednemTike[IndeksSimvolaS_SamimSvegimTikom].LastTick.time_msc));
      StringConcatenate(GStrokaDlayComment[8]," Локальное время получения нового тика по символу.                                   ",PrintMilesekond(InformaziaOPoslednemTike[NomerSimolaS_NovimTikom].PoslednieVremayRaboti));
      StringConcatenate(GStrokaDlayComment[9]," Предпоследние Локальное время попытки получить новый тик по символу    ",PrintMilesekond(InformaziaOPoslednemTike[NomerSimolaS_NovimTikom].PredPoslednieVremayRaboti));
      
      GStrokaDlayComment[10]="--------------------------------------------------------------------------------";
      
      for( int i=2; i<12; i++ )
      Print(GStrokaDlayComment[i]);      
     }
  }  

The EA itself catching the delays.

 
pivomoe:

The EA itself is catching delays.

Immediately catchy: you want to understand if the terminal is lagging with the issuing of ticks, right? So why do you take the time for all symbols, and not for a particular symbol? Why can't you write it in a simpler way:

#property indicator_plots 0
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//--- Получаем время последней котировки по символу
   const datetime lastTime=(datetime)SymbolInfoInteger(_Symbol,SYMBOL_TIME);
//--- Приемник данных о последнем тике
   MqlTick tick;
//--- Получение последнего тика
   if(SymbolInfoTick(_Symbol,tick))
     {
      //--- Проводим ГРУБОЕ сравнение времени последней котировки и последнего тика
      int lag=int(lastTime-tick.time);
      //---
      Print(__FILE__,": Время прихода: последней котировки = "+TimeToString(lastTime,TIME_SECONDS)+", последнего тика = "+TimeToString(tick.time,TIME_SECONDS)+". Задержка = ",lag," сек.");
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
I honestly don't understand what timeSymbolInfoInteger(_Symbol,SYMBOL_TIME) returns? What is the time of the last quote?
Alexey Kozitsyn:

You want to understand if the terminal lags with the ticks, right

? A delay of a minute and a half in receiving ticks is not acceptable.

 
pivomoe:
To be honest, I do not understand what timeSymbolInfoInteger(_Symbol,SYMBOL_TIME) returns? What's the time of last quote?

Yes, it is. Delays of a minute and a half in receiving ticks are not acceptable.

This is the arrival time of the last quotation for the current (in my example) symbol. You can see the same time here:

And SymbolInfoInteger() returns the property of the specified symbol.

 
What is a quote ? I just looked at this function yesterday in the documentation and on the forum. What it returns is not at all clear.
 
pivomoe:
What is a quote ? I just looked at this function yesterday both in the documentation and on the forum. What it returns is not at all clear.

A new quotation is a new price change. I.e. a change in bid and/or ask.

 
Alexey Kozitsyn:

A new quotation is a new price change. I.e. change in bid and/or ask.

In the market overview there are also columns "Volume" "Last trade" There is a suspicion that this function simply returns the .time of the last tick.

 
pivomoe:

In the market overview there are also columns "Volume" "Last trade" I suspect that this function simply returns the .time of the last tick.

Did you know that there are different ticks? That ticks are divided into trading/information ticks?

 
Alexey Kozitsyn:

Did you know that there are different types of ticks? That ticks are divided into trading/information ticks?

I know. What's your point?