Market closed - page 5

 

Dear developers!

I REQUIRE YOU to read this message attentively.

I think I've figured out the reason why the time discrepancy appears!!!

Today:

Terminal

23:49:58.148    Trades  'xxxxx': buy limit 2.00 UCHF-3.18 at 0.9310
23:49:58.154    Trades  'xxxxx': accepted buy limit 2.00 UCHF-3.18 at 0.9310
23:49:58.156    Trades  'xxxxx': buy limit 2.00 UCHF-3.18 at 0.9310 placed for execution in 8.040 ms

Expert

2017.09.21 23:49:58.182 trader (UCHF-3.18,H1)     StopTrading: Время сервера = 23:50:00; Статус ордера = BUY_ORDER; Билет = 77833993  Buy ордер отклонён.
2017.09.21 23:49:58.182 trader (UCHF-3.18,H1)     Alert: Эксперт остановлен. Инструмент UCHF-3.18
2017.09.21 23:49:58.182 trader (UCHF-3.18,H1)     OnTradeTransaction: Buy ордер отклонён брокером(биржей). Билет = 77833993 Причина: 0 0

Time check mechanism.

When the Depth of Market changes for a symbol(I work with the Depth of Market only)

//+------------------------------------------------------------------+
// Expert Book event function                                        |
//+------------------------------------------------------------------+  
void OnBookEvent(const string &symbol)
{
  if(symbol == Symbol()))
  {
    if(CheckMarketTime(symbol)
    {
      //Выставление ордеров и т.д.
    }
  }     
}

TheCheckMarketTime function is called

//+------------------------------------------------------------------+
//| Expert Check Market Time function                                |
//+------------------------------------------------------------------+
bool CheckMarketTime(const string a_symbol)
{
  if(SymbolInfoTick(a_symbol, cur_tick))
  {
    sv_time.year = 0;
    TimeToStruct(cur_tick.time, sv_time);
    if(sv_time.year > 0)
    {
      if((sv_time.day_of_week == int(FirstDay)) ||
         (sv_time.day_of_week == int(SecondDay))) return(false);
      tts_time.year = 0;
      TimeTradeServer(tts_time);
      if(tts_time.year > 0)
      {   
        if((tts_time.day_of_week == sv_time.day_of_week) &&
           (tts_time.hour == sv_time.hour) &&
           (tts_time.min == sv_time.min))
        {
          ulong cur_time = sv_time.hour * 3600 + sv_time.min * 60 + sv_time.sec;
          if(((cur_time >= time_st_mon) && (cur_time < 50370)) ||
             ((cur_time >= time_st_day) && (cur_time < 67470)) ||
             ((cur_time >= time_st_evn) && (cur_time < 85770)))
          {
            return(true);
          }
        }
      }
    }
  }
  return(false);
}

After getting the data on the latest tick for the symbol

if(SymbolInfoTick(a_symbol, cur_tick))

I check for the timeframe, but(VERY IMPORTANT) !!!!

MqlTick (IMMEDIATELY) does not contain the latest timeframe, if

in the Depth of Market has changed ONLY the volume of the same price.

I am making this assumption because there is no

TICK_FLAG_ASK_VOLUMEand TICK_FLAG_BID_VOLUME flags

The OnBookEvent function worked (volume of such and such price has changed), but

MqlTick did not register time of this change.

Please add these flags to MqlTick, respectively with updated time.

Added

For some reason I can't make a record in the CD

 
prostotrader:

MqlTick (RIGHT HERE) does not record the latest time if

in the price cup ONLY the volume of the same price has changed.

Absolutely correct. And this is correct behaviour. MqlTick takes data from the same source from which the tick history is filled. There shouldn't be duplicates in tick history, because the tick history in MT5 doesn't store volume even on bestbands.

It's been raised for a long time that there is no direct way to know the time to which the tick history corresponds. Find out in another way.

 
fxsaber:

Absolutely right. And this is the correct behaviour. MqlTick takes data from the same source from which the tick history is filled. There should not be duplicates in tick history, because the tick history in MT5 does not store volume even on bestbands.

It's been raised for a long time that there is no direct way to know the time to which the tick history corresponds. Find out in another way.


Would you be so kind as to suggest which one?

Added

If I got a notification that something had changed in the takan, then

why not add a field for convenience ("little blood")

datetime book_change; ?

Or even simpler, add the following field to MqlBookInfo

datetime book_change;

Especially as this time is translated by exchange.

 
prostotrader:

Would you be so kind as to tell me which one?

// Время последнего тика символа
long GetSymbolTime( const string Symb )
{
  MqlTick Tick;
  
  return(SymbolInfoTick(Symb, Tick) ? Tick.time_msc : 0);
}

// Время последнего тика Обзора рынка
long GetMarketWatchTime( void )
{
  long Res = 0;
  
  for (int i = SymbolsTotal(true) - 1; i >= 0; i--)
  {
    const long TmpTime = GetSymbolTime(SymbolName(i, true));
    
    if (TmpTime > Res)
      Res = TmpTime;
  }
  
  return(Res);
}

// Текущее время на торговом сервере без учета пинга
long GetCurrenTime( void )
{
  static ulong StartTime = GetMicrosecondCount();
  static long PrevTime = 0;
  
  const long TmpTime = GetMarketWatchTime();
  
  if (TmpTime > PrevTime)
  {
    PrevTime = TmpTime;
    
    StartTime = GetMicrosecondCount();
  }
  
  return(PrevTime + (long)((GetMicrosecondCount() - StartTime) / 1000));
}

void OnInit()
{
  MarketBookAdd(_Symbol);
}

void OnDeinit( const int )
{
  MarketBookRelease(_Symbol);
}

string TimeToString( const long Value )
{
  return((string)(datetime)(Value / 1000) + "." + (string)IntegerToString(Value % 1000, 3, '0'));
}

void OnBookEvent( const string& )
{
  Comment(TimeToString(GetCurrenTime()));
}
 
fxsaber:

Don't be ridiculous... :)

 
prostotrader:

If I have been notified that something has changed in takan, then

why not add a field for convenient ("little money")

datetime book_change; ?

Or simply, add MqlBookInfo structure with the

datetime book_change;

Especially, that this time is translated by the exchanger.

Only not datetime, but long - milliseconds. And

Forum on trading, automated trading systems and strategy testing

Market closed

fxsaber, 2017.09.22 09:17

The issue has been raised for a long time that there is no direct way to know the time to which the betting window corresponds.

With similar suggestions.

 

Maybe after the OnBookEvent is triggered

request CopyTicks on this character?

I'll give it a try...

 
prostotrader:

Maybe after the OnBookEvent is triggered

request CopyTicks on this character?

Wouldn't help, of course. The only option now is to find out the timing of the tumbler led.

 
fxsaber:

It won't help, of course. The only option now is to find out the timing of the glass led.


It's interesting :)

#property copyright "Copyright 2017 prostotrader"
#property link      "https://www.mql5.com"
#property version   "1.00"
//
MqlTick a_ticks[], b_ticks;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   if(!MarketBookAdd(Symbol()))
   {
     Print("Book not added!");
     return(INIT_FAILED);
   }
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
    MarketBookRelease(Symbol());   
  }
//+------------------------------------------------------------------+
//| BookEvent function                                               |
//+------------------------------------------------------------------+
void OnBookEvent(const string &symbol)
  {
    if(symbol == Symbol())
    {
      int res = CopyTicks(symbol, a_ticks, COPY_TICKS_ALL, 0, 1);
      if(res > 0)
      {
        if(SymbolInfoTick(symbol, b_ticks))
        {
          Print("CopyTicks time = ", TimeToString(a_ticks[0].time, TIME_SECONDS), "; SymbolInfoTick = ", TimeToString(b_ticks.time, TIME_SECONDS));
        }
      }
    }
  }

Result

2017.09.22 11:18:36.029 Test_time (RTS-12.17,M1)        CopyTicks time = 11:18:27; SymbolInfoTick = 11:18:35
2017.09.22 11:18:36.933 Test_time (RTS-12.17,M1)        CopyTicks time = 11:18:27; SymbolInfoTick = 11:18:35
2017.09.22 11:18:37.577 Test_time (RTS-12.17,M1)        CopyTicks time = 11:18:27; SymbolInfoTick = 11:18:37
2017.09.22 11:18:38.257 Test_time (RTS-12.17,M1)        CopyTicks time = 11:18:27; SymbolInfoTick = 11:18:37
2017.09.22 11:18:38.317 Test_time (RTS-12.17,M1)        CopyTicks time = 11:18:38; SymbolInfoTick = 11:18:38
2017.09.22 11:18:38.511 Test_time (RTS-12.17,M1)        CopyTicks time = 11:18:38; SymbolInfoTick = 11:18:38
2017.09.22 11:18:38.871 Test_time (RTS-12.17,M1)        CopyTicks time = 11:18:38; SymbolInfoTick = 11:18:38
2017.09.22 11:18:39.071 Test_time (RTS-12.17,M1)        CopyTicks time = 11:18:38; SymbolInfoTick = 11:18:38
2017.09.22 11:18:39.545 Test_time (RTS-12.17,M1)        CopyTicks time = 11:18:38; SymbolInfoTick = 11:18:38
2017.09.22 11:18:39.655 Test_time (RTS-12.17,M1)        CopyTicks time = 11:18:38; SymbolInfoTick = 11:18:39

???????

I don't even know what to say....

 
prostotrader:

I don't even know what to say....

void OnInit()
{
  MarketBookAdd(_Symbol);
}

void OnDeinit( const int )
{
  MarketBookRelease(_Symbol);
}

string GetTickFlag( uint tickflag )
{
  string flag = "";

#define  TICKFLAG_MACRO(A) flag += ((bool)(tickflag & TICK_FLAG_##A)) ? " TICK_FLAG_" + #A : "";
  TICKFLAG_MACRO(BID)
  TICKFLAG_MACRO(ASK)
  TICKFLAG_MACRO(LAST)
  TICKFLAG_MACRO(VOLUME)
  TICKFLAG_MACRO(BUY)
  TICKFLAG_MACRO(SELL)
#undef  TICKFLAG_MACRO

  if (flag == "")
    flag = " FLAG_UNKNOWN (" + (string)tickflag + ")";
     
  return(flag);
}

#define  TOSTRING(A) " " + #A + " = " + (string)Tick.A

string TickToString( const MqlTick &Tick )
{
  return(TOSTRING(time) + "." + (string)IntegerToString(Tick.time_msc % 1000, 3, '0') +
         TOSTRING(bid) + TOSTRING(ask) + TOSTRING(last)+ TOSTRING(volume) + GetTickFlag(Tick.flags));
}

void OnBookEvent( const string &Symb )
{
  if (Symb == _Symbol)
  {
    MqlTick Tick1, Tick2[];
    
    if (SymbolInfoTick(_Symbol, Tick1) && (CopyTicks(_Symbol, Tick2, COPY_TICKS_ALL, 0, 1) > 0))
      Print("\nMqlTick: " + TickToString(Tick1) + "\nCopyTick: " + TickToString(Tick2[0]));
  }
}

you will see that the timing will only be different in these situations

Test3 (RTS-12.17,M1)    MqlTick:  time = 2017.09.22 11:21:50.668 bid = 112000.0 ask = 112010.0 last = 112000.0 volume = 5 FLAG_UNKNOWN (0)
Test3 (RTS-12.17,M1)    CopyTick:  time = 2017.09.22 11:21:50.572 bid = 112000.0 ask = 112010.0 last = 112000.0 volume = 5 TICK_FLAG_LAST TICK_FLAG_VOLUME TICK_FLAG_SELL


It has been discussed several times that MqlTick does not return a tick as is. That there are two tick streams - quote and transaction. And that in CopyTicks they are merged sometimes retroactively, because the streams are unsynchronized. And that times of MqlTick and CopyTicks may not coincide.

Reason: