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

 
prostotrader:

Look at the code carefully!

TimeTradeServer() is taken only to determine the day and that's it (this check is made "just in case")!

TimeTradeServer() may be omitted altogether!

I've looked at it. I agree, I've written it incorrectly, but the function, in my opinion, still does not solve the problem. To be honest, I'm not quite sure why it's needed. It seems that you:

1. Get the number of milliseconds from a tick;

2. You break the tick into its components;

3. Then you reassemble the tick again!? This is where it's not clear to me what this is for? You will always get the same value that was originally passed to the function. Or maybe I'm missing something?

And then you compare the time of the tick with the previous one;


We do need to know the server's time, don't we? Without server time, we cannot determine if the thread of one character is lagging behind the threads of other characters.

That is, your code does not bind to the server time and does not compare the server time to the thread time, which we need to do. To understand not the lag of the stack from the ticks of a single symbol (as I originally thought when getting into this discussion), but the delay of data transfer over a set of symbols from the server to the terminal.

 
Alexey Kozitsyn:

The check seems to need to be done via TimeGMTOffset. I'll sketch an example later.

Just funny, you are an experienced person (not a beginner).

You don't need any time at all, except the time of incoming ticks!

Remember the time (at initialization) of the last tick, and then all comparisons go with this time!

 
Alexey Kozitsyn:

I've had a look. I agree, I wrote somewhat incorrectly, but the function, in my opinion, still doesn't solve the task at hand. To be honest, I'm not quite sure why it's needed. It looks like you are:

3. Then reassemble the tick again!? This is where it's not clear to me what it's for? You will always get the same value that was originally passed to the function. Or am I missing something?


This code is "pulled" from my Expert Advisor, where I check if the tick is current and if it's within

trading sessions

Added by

"Breakdown" of the tick is needed to determine the exact (milliseconds) time (no date), since in the session settings of my EA

I only set the time

input string          TimeStMon    = "10:00:00";               //Время начала утренней сессии
input string          TimeStDay    = "14:05:00";               //Время начала дневной сессии
input string          TimeStEvn    = "19:05:00";               //Время начала вечерней сессии
 
prostotrader:

It's just ridiculous, you're an experienced person (not a novice).

You don't need any time at all, except for the time of incoming ticks!

Remember the time (at initialisation) of the last tick, and then all comparisons go with this time!

I'll write my example later, I'll get into the question in more detail. I don't exclude that maybe I'm wrong (as well as pivomoe) and you are right.

 
prostotrader:

This code is 'pulled' from my EA where I check the relevance of the tick and the time that the tick is within

trading sessions

Added by

"Breakdown" of the tick is needed to determine the exact time (without date), since in the session settings of my EA

I only set the time

Exactly, my fault, missed it.

 
Alexey Kozitsyn:

Exactly, my fault, I didn't see it that way.

It's just that TC wasn't initially clear on what he wanted to get (or maybe it was misunderstood).

Here, run it and check:

//+------------------------------------------------------------------+
//|                                                         Time.mq5 |
//|                                                   Copyright 2019 |
//|                                                                  |
//+------------------------------------------------------------------+
enum FRESH_TICK
{
  UNKNOWN_TICK,
  NEW_TICK,
  CUR_TICK,
  OLD_TICK
};
//
MqlTick stored_ticks[];
bool is_book;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
  int result = CopyTicks(Symbol(), stored_ticks, COPY_TICKS_ALL, 0, 1);
  if(result > 0)
  {
    is_book = MarketBookAdd(Symbol());
    if(is_book == false) return(INIT_FAILED);
  } else return(INIT_FAILED);
  return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
  if(is_book == true) MarketBookRelease(Symbol()); 
}
//+------------------------------------------------------------------+
// Expert Book event function                                        |
//+------------------------------------------------------------------+  
void OnBookEvent(const string &symbol)
{
  if(symbol == Symbol())
  {
    MqlTick a_ticks[];
    int result = CopyTicks(symbol, a_ticks, COPY_TICKS_ALL, 0, 1);
    if(result > 0)
    {
      FRESH_TICK tick_state = CheckTickTime(a_ticks[0]);
      switch(tick_state)
      {
       case UNKNOWN_TICK: Print(EnumToString(UNKNOWN_TICK), " - Тик не определен."); //Тик не определен
       break;
       case NEW_TICK: Print(EnumToString(NEW_TICK), " - Новый тик");     //Торговое время, можно отсылать ордера;
       break;
       case CUR_TICK: Print(EnumToString(CUR_TICK), " - Текущий тик");    //По усмотрению разработчика;
       break;
       case OLD_TICK: Print(EnumToString(OLD_TICK), " - Старый тик");     //По усмотрению разработчика;
       break;
      }
    }  
  }
}
//+------------------------------------------------------------------+
//| Expert Check Market Time function                                |
//+------------------------------------------------------------------+
FRESH_TICK CheckTickTime(MqlTick &a_tick)
{
  if(a_tick.time_msc > stored_ticks[0].time_msc)
  {
    stored_ticks[0] = a_tick;
    return(NEW_TICK);
  }
  else
  {
    if(stored_ticks[0].time_msc == a_tick.time_msc)
    {
      if((stored_ticks[0].ask == a_tick.ask) && (stored_ticks[0].bid == a_tick.bid) &&
         (stored_ticks[0].flags == a_tick.flags) && (stored_ticks[0].last == a_tick.last) &&
         (stored_ticks[0].time == a_tick.time) && (stored_ticks[0].volume == a_tick.volume) &&
         (stored_ticks[0].volume_real == a_tick.volume_real))
        {
          return(CUR_TICK);
        }
        else return(OLD_TICK);
        
    }
    else return(OLD_TICK);
  }
  return(UNKNOWN_TICK);
} 
      
 
prostotrader:

It's just that the TC wasn't sure what he wanted to get in the first place.

Here, run it and check it out:

Michael, there are no questions to the arrival of the new tick/check on the old tick. There are no questions to your code either. The question is different. You need to check this situation:

14:53:10.277    ProverkaAktyalnostiTikov (RTS-3.19,H1)   Получен НОВЫЙ тик по символу                     GAZR-3.19 time_msc= 2019.03.20 14:53:11.638
14:53:10.277    ProverkaAktyalnostiTikov (RTS-3.19,H1)   ХОТЯ до этого был получeн тик                     RTS-3.19 time_msc  2019.03.20 14:53:13.695
 
Alexey Kozitsyn:

Michael, there are no questions to the arrival of the new tick/check on the old tick. Neither is there any question about your code. The question is different. I need to check the following situation:

I tweaked the code (see above) the (OLD_TICK) appeared.

And knowing that the new package may contain an "old" tick, the developer must use it at his discretion.

 
prostotrader:

I tweaked the code (see above) and (OLD_TICK) appeared.

It doesn't matter... streams of DIFFERENT characters.

 
Alexey Kozitsyn:

It doesn't matter... streams of DIFFERENT characters.

Then I don't understand WHAT I NEED???? at all

If the current time is the SERVER - you need to forget about it until they broadcast it!
or use what is TimeTradeServer()