Analyse each tick in real time

 

Hello, I 'm trying to analyse each tick in real time. I'm using Copytick, but I'm having trouble to know which ticks are new. I'm copying the ticks for 2 arrays and comparing them. But it's not working. Any suggestions? Is there an easier way?

Olá, Eu estou tentando analisar cada tick em tempo real. Eu estou usando Copytick, mas eu estou tendo problema para saber quais ticks são novos. Eu estou copiando os ticks para 2 arrays e comparando elas. Mas não está funcionando. Alguma sugestão? Existe uma maneira mais fácil? 

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
CopyTicks(_Symbol,arrayTickVelho, COPY_TICKS_TRADE, 0, 1000);   
//---
ArraySetAsSeries(arrayTickNovo,true);            
ArraySetAsSeries(arrayTickVelho,true);            
//---
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
//---
ArrayFree(arrayTickNovo);  
int tickCopiado = CopyTicks(_Symbol,arrayTickNovo, COPY_TICKS_TRADE, 0, 1000);
//--- 
for(int tickDiferente=1; tickDiferente<=tickCopiado; tickDiferente++)
   {
   if(ArrayCompare(arrayTickVelho, arrayTickNovo, 0, tickDiferente, 1000 - tickDiferente) == 0)
     {
     for(int tickCopiar=0; tickCopiar<tickDiferente; tickCopiar++) 
         {TickCopiar(tickCopiar);} // Function for analyse each tick  
     break;
     }
   }  
//--- 
ArrayFree(arrayTickVelho);  
ArrayCopy(arrayTickVelho, arrayTickNovo,0, 0, 1000);  
}
//+------------------------------------------------------------------+
 

Without testing it... (some remarks)

You should first do an ArrayCopy and than ArrayFree...

You cannot use ArrayCompare with MqlTick as this is a struct  and so a complex type.

COPY_TICKS_TRADE might not work for currencies...

Arrays start with index 0...

Regards Uwe

 
Uwe Goetzke :

Without testing it... (some remarks)

You should first do an ArrayCopy and than ArrayFree...

You cannot use ArrayCompare with MqlTick as this is a struct  and so a complex type.

COPY_TICKS_TRADE might not work for currencies...

Arrays start with index 0...

Regards Uwe

Thanks Uwe,

I didn't know that ArrayCompare does not work with MQLTICK.

This EA is for Bovespa, so I think that I can use COPY_TICKS_TRADE.

I know that the arrays begins with 0. But sometimes I receive more than 1 tick, so I need to know if I already analyzed it or it is new. Any suggestions? 

Regards Otavio

 
Otavio Konmin Clemente:

Thanks Uwe,

I didn't know that ArrayCompare does not work with MQLTICK.

This EA is for Bovespa, so I think that I can use COPY_TICKS_TRADE.

I know that the arrays begins with 0. But sometimes I receive more than 1 tick, so I need to know if I already analyzed it or it is new. Any suggestions? 

Regards Otavio

There is no  problem using ArrayCompare() with MqlTick which is a simple structure (not a complex one). Though I am not sure ArrayCompare() is useful here.

If you want the new ticks just request them by time from the last one you already have.

ulong            from=0,                // date starting from which ticks are requested

 
Alain Verleyen :

There is no  problem using ArrayCompare() with MqlTick which is a simple structure (not a complex one). Though I am not sure ArrayCompare() is useful here.

If you want the new ticks just request them by time from the last one you already have.

Thank you, this way is better. I'll try.

 

Hi @Otavio Konmin Clemente,

What is your objective?

Are you trying to‌ calculate the volume executated? Book agression?

Anyway, I sugest you to use‌CopyTicks(). This function get the ticks directly in an array in the right sequency. So, you don't have to worry about which one is new or not, just use its values and times.

I also sugest‌ some reading:

https://www.mql5.com/pt/forum/165484

https://www.mql5.com/pt/forum/90503

https://www.mql5.com/en/articles/1793 (https://www.mql5.com/pt/articles/1793)

Otavio Konmin Clemente
Otavio Konmin Clemente
  • www.mql5.com
Trader's profile
Reason: