Download MetaTrader 5

Function to override SymbolInfoTick to add correct millisecond count to MqlTick struct?

To add comments, please log in or register
nicholishen
1538
nicholishen  

Another one I cannot find info on... Anyone have a function to add the millisecond count to the tick struct? I made one that uses to pc clock instead of broker time, but this is obviously not accurate (broker time diff/network latency)... Any ideas?



here's what I have so far...

#property strict
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   srand(GetTickCount());
   while(!IsStopped())
   {
      MqlTick tick;
      if(MsSymbolInfoTick(Symbol(),tick))
         Print(tick.time,".",tick.time_msc%1000);
      Sleep(rand()%2000);
   }
  
   
  }
//+------------------------------------------------------------------+

bool MsSymbolInfoTick(const string symbol,MqlTick &tick)
{
   static uint    m_ms_start =0;
   static long    m_msc_base =0;
   if(m_ms_start==0)
   {
      m_ms_start = (uint(GetMicrosecondCount()/1000));
      m_msc_base = ((long)TimeCurrent()*1000);
   }
   if(!SymbolInfoTick(symbol,tick))
      return false;
   tick.time_msc = m_msc_base + (uint(GetMicrosecondCount()/1000) - m_ms_start);
   tick.time = datetime(tick.time_msc/1000); 
   return true;
}


 

Ex Ovo Omnia
3418
Ex Ovo Omnia  
nicholishen:

Another one I cannot find info on... Anyone have a function to add the millisecond count to the tick struct? I made one that uses to pc clock instead of broker time, but this is obviously not accurate (broker time diff/network latency)... Any ideas?



here's what I have so far...


 


Depends on what you want to achieve. From my experience, the ticks may occasionally arrive even in the swapped order (the tick with the lower second arrives after the one with the higher second). If the only purpose is to have a unique time comparison among ticks, I would add the M1 volume to the time fragment instead of the milliseconds.

nicholishen
1538
nicholishen  
Ex Ovo Omnia:

Depends on what you want to achieve. From my experience, the ticks may occasionally arrive even in the swapped order (the tick with the lower second arrives after the one with the higher second). If the only purpose is to have a unique time comparison among ticks, I would add the M1 volume to the time fragment instead of the milliseconds.


I want to collect tick data from my new broker (their feed is crazy fast) during news events for analysis. I need to have the ms time of the tick... It's not absolutely necessary to have the correct broker time, but what is important is that the ms intervals are as exacts as possible to how the ticks are coming into the terminal. That's why after testing the function I posted above, I came to the conclusion that I need to reassign the tick.time value as a derivative of the new millisecond-count - instead of appending the tick.time with the ms...

Ex Ovo Omnia
3418
Ex Ovo Omnia  
nicholishen:

I want to collect tick data from my new broker (their feed is crazy fast) during news events for analysis. I need to have the ms time of the tick... It's not absolutely necessary to have the correct broker time, but what is important is that the ms intervals are as exacts as possible to how the ticks are coming into the terminal. That's why after testing the function I posted above, I came to the conclusion that I need to reassign the tick.time value as a derivative of the new millisecond-count - instead of appending the tick.time with the ms...


Oops, I did not even notice that the MqlTick structure changed in MT4.  Anyway, you may extend structures in Mql, if this is what you ask.

struct PcMqlTick:MqlTick {
   int pcMicros;
};
nicholishen
1538
nicholishen  
Ex Ovo Omnia:

Oops, I did not even notice that the MqlTick structure changed in MT4.  Anyway, you may extend structures in Mql, if this is what you ask.


Right on, but actually the (long)time_msc param is exactly what I need... in MQL5 it has the millisecond count, but in MQL4 the param is there but the data is not sent from the broker server. :( 

I'm currently using the (MicroSecondCount/1000) to get more accurate ms resolution than GetTickCount since it has a ~16ms variance. 

Petr Nosek
373
Petr Nosek  
nicholishen:

It's not absolutely necessary to have the correct broker time, but what is important is that the ms intervals are as exacts as possible to how the ticks are coming into the terminal.

   ulong __dt;
   GetSystemTimeAsFileTime(__dt);
   __dt/=10000;
   int __ms=int(__dt%1000);

If system time is enough for you, you can use GetSystemTimeAsFileTime(ulong &SystemTimeAsFileTime) from kernel32.dll . It returns the system time in 100 nsec units in a ulong. You can combine this time with broker time.

To add comments, please log in or register