Tick data from SymbolInfoTick and CopyTick is different is strategy tester

 

Hi,
I'm trying build a tick indicator and while debugging I run in to this problem. So I create a test code as below.

The code below get latest tick data from SymbolInfoTick and CopyTick then compare the time in msc if it is the same tick or not which it should always be the same since it is the latest tick?
When Run in strategy tester, in the first loop, the tick data's time msc is always different. However, it's seldomly show when test in realtime or attach to chart. So I got a little bit confusion about how tick data operate in realtime.

I know this is such a minor. But I have got some inconsistance errors when running in realtime and this might be the cause.

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[])
  {
//---

   ArraySetAsSeries(open,false);
   ArraySetAsSeries(high,false);
   ArraySetAsSeries(low,false);
   ArraySetAsSeries(close,false);
   ArraySetAsSeries(spread,false);
   ArraySetAsSeries(tick_volume,false);

   mode = COPY_TICKS_ALL;

   MqlTick current_tick;
   SymbolInfoTick(_Symbol,current_tick);
   //Print("Tick Time from 2.1:", current_tick.time_msc);
   long current_tick_time_msc=current_tick.time_msc;
  
   //Get last 10 tick to compare with Symbolinfo tick
   MqlTick test_tick[];
   CopyTicks(_Symbol,test_tick,mode,0,10); 
   if(test_tick[9].time_msc!=current_tick_time_msc){
      Print("Last tick compare-------from tick info:",current_tick_time_msc," from Copytick:",test_tick[9].time_msc);  
   }
   return(rates_total);
  }

Sorry for bad english

 

Did you find out what's going on? I'm having the same issue here.

If called upon each OnTick() event, shouldn't both pieces of code below return the same data?

Piece #1:

MqlTick tick1;
SymbolInfoTick(_Symbol, tick1);

Piece #2:

MqlTick tick2;
MqlTick last_ticks[];
CopyTicks(_Symbol, last_ticks, COPY_TICKS_ALL, 0, 1);
tick2 = last_ticks[0];

I mean... Shouldn't tick1 be equal to tick2?

 
TheOat:

Hi,
I'm trying build a tick indicator and while debugging I run in to this problem. So I create a test code as below.

The code below get latest tick data from SymbolInfoTick and CopyTick then compare the time in msc if it is the same tick or not which it should always be the same since it is the latest tick?
When Run in strategy tester, in the first loop, the tick data's time msc is always different. However, it's seldomly show when test in realtime or attach to chart. So I got a little bit confusion about how tick data operate in realtime.

I know this is such a minor. But I have got some inconsistance errors when running in realtime and this might be the cause.

Sorry for bad english

Alexandre Schmidt #:

Did you find out what's going on? I'm having the same issue here.

If called upon each OnTick() event, shouldn't both pieces of code below return the same data?

Piece #1:

Piece #2:

I mean... Shouldn't tick1 be equal to tick2?


Hello everyone, how's it going?

Do you have any news about your issue?

 

MqlTick is a structure.

If you do

MqlTick tick1; 

you can't expect "tick1" by itself to return something, you specify "tick1.ask" or "tick1.bid"