Download MetaTrader 5
To add comments, please log in or register
Find out the latest MQL5.community news!
Otavio Konmin Clemente
259
Otavio Konmin Clemente 2016.09.17 01:46 

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);  
}
//+------------------------------------------------------------------+
Uwe Goetzke
1405
Uwe Goetzke 2016.09.17 11:11  

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

Otavio Konmin Clemente
259
Otavio Konmin Clemente 2016.09.17 12:27  
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

Alain Verleyen
Moderator
30298
Alain Verleyen 2016.09.17 12:55  
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

Otavio Konmin Clemente
259
Otavio Konmin Clemente 2016.09.17 15:28  
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.

/
To add comments, please log in or register