Tiki in real time - page 10

 
prostotrader:

Investor : FfiR87ty (read only password)

More account number

 
prostotrader:

What do you mean you haven't seen it?

What are these?

These are ticks with the same prices that somehow got into the magazine (they shouldn't have). Why did they get in - I'll check on Discover.

There are no skips.

 
Andrey Khatimlianskii:

There's only one fan, and that's you.

I work with technical information.

The task of analysing the glass in this thread was not the task at all. Ticks without price changes are not needed by the terms of the task.

I see, consider that you have won (just silly to go on for the obviousness of the situation), but not at all convincing!

Again, everyone chooses what to do and how to do it!

Good luck!

 
Andrey Khatimlianskii:

You also need an account number.

Practice


 
prostotrader:

You, I don't think on purpose, take only one tick

Thus, you miss everything before that time (0, i.e. the current time)!

In my implementation, ALL ticks are taken into account.

Your code is not suitable for this kind of testing!

You, among other things, are inattentive:

        if ( last_tick_time <= 0 )
        {
                if ( CopyTicks( _Symbol, cur_ticks, COPY_TICKS_ALL, 0, 1 ) > 0 )
...
        }
        if ( last_tick_time > 0 )
        {
                int new_ticks = CopyTicks( _Symbol, cur_ticks, COPY_TICKS_ALL, last_tick_time, 0 );

Without it, the EA would always get one tick at each event handler, which is not the case.

 
prostotrader:

I see, consider that you win (just silly to go on for the obviousness of the situation), but not convincing at all!

Again, everyone chooses what to do and how to do it!

Good luck!

Genius!

You came in, did not understand the problem, waved your FORTS-flag, misled about the event handlers, and in response to being proved wrong, wished you luck and got away.

And most importantly, you still do not understand where you are wrong.


Good luck to you too!

 
prostotrader:

Practice

Thanks, connected.

The results are similar, OnBOOK is often delayed compared to OnTick.


And in what situation OnTick can be significantly better (even ON FORTS! including, for you!), I'll show you when you admit you were wrong.

 

By the way, there was an excellent article by Vasiliy Sokolov on the correct collection of ticks. It deals in detail with the synchronisation process (which I don't have, which sometimes causes identical ticks to be printed):

Но функция CopyTiks не позволяет запрашивать N последних тиков. Вместо этого она предоставляет все тики, пришедшие с указанного момента времени. Это усложняет задачу. Мы должны выполнить запрос, получить массив тиков и сравнить его с массивом тиков, полученным на предыдущем обновлении. При этом мы выясним, какие из вновь пришедших тиков не входили в "прошлую поставку", то есть являются новыми. Но сравнивать тики между собой напрямую невозможно, просто потому что видимых различий между ними может вообще не быть. Например, обратимся к нижеприведенной таблице сделок:

Fig. 5. Table of all transactions with an example of identical transactions.

We immediately see two groups of absolutely identical ticks. They are marked with red frames and have the same time, volume, direction and price. Thus, we see that it is impossible to compare individual ticks with each other.

But it is possible to comparea group of ticks. If two groups of ticks are equal to each other, we can conclude that these and following ticks were already analysed during the previous price update.

Пишем скальперский стакан цен на основе графической библиотеки CGraphic
Пишем скальперский стакан цен на основе графической библиотеки CGraphic
  • www.mql5.com
Именно с этой, улучшенной и дополненной версией мы и начнем работать, чтобы постепенно превратить ее в скальперский стакан цен. Краткий обзор графической библиотеки CPanel Созданию пользовательских интерфейсов в MQL5 посвящено много статей. Среди них особенно выделяется серия Анатолия Кажарского "Графические интерфейсы", после которой сложно...
 
I have written a test Expert Advisor.
int OnInit()
{
  return(!MarketBookAdd(_Symbol)); // Подписались на стакан.
}

void OnDeinit( const int )
{
  MarketBookRelease(_Symbol); // Отписались от стакана.
}

// Получает BestBands
bool GetBidAsk( double &PriceBid, double &PriceAsk, const MqlBookInfo &MarketDepth[] )
{  
  PriceAsk = 0;
  
  const int Size = ArraySize(MarketDepth);
  int Pos = 0;
  
  while ((Pos < Size) && (MarketDepth[Pos].type == BOOK_TYPE_SELL))
  {
    PriceAsk = MarketDepth[Pos].price;
    
    Pos++;
  }
    
  PriceBid = (Pos < Size) ? MarketDepth[Pos].price : 0;
  
  return(true);
}

// Получает последний известный тик.
bool GetLastTick( const string &Symb, MqlTick &Tick )
{
  static MqlTick Ticks[1];
  
  const bool Res = SymbolInfoTick(Symb, Tick) && (CopyTicks(Symb, Ticks, COPY_TICKS_INFO, 0, 1) == 1);
  
  if (Res && (Ticks[0].time_msc > Tick.time_msc))
    Tick = Ticks[0];
  
  return(Res);
}

// Получает тики через стакан и стандартным методом.
bool GetLastTicks( const string &Symb, MqlTick &Tick, MqlTick &TickBook )
{
  MqlBookInfo MarketDepth[];

  return(MarketBookGet(Symb, MarketDepth) && GetLastTick(Symb, Tick) && GetBidAsk(TickBook.bid, TickBook.ask, MarketDepth));
}

// Сравнивает тики.
bool IsDiff( const MqlTick &Tick1, const MqlTick &Tick2 )
{
  return((Tick1.bid != Tick2.bid) || (Tick1.ask != Tick2.ask));
}

#define  TOSTRING(A) (FuncName + " " + #A + ": " + (string)A.bid + "/" + (string)A.ask + "\n")

// Распечатываем тики, полученные разными способами.
void TestFunc( const string FuncName )
{
  static MqlTick Tick = {0};
  static MqlTick Book = {0};

  if (GetLastTicks(_Symbol, Tick, Book))
    Print((IsDiff(Tick, Book) ? "* " : NULL) + TOSTRING(Tick) + TOSTRING(Book)); // Если тики отличаются, добавляем '*'.
}

void OnTick()
{
  TestFunc(__FUNCTION__); // Распечатываем тики, полученные разными способами.
}

void OnBookEvent( const string &Symb )
{  
  if (Symb == _Symbol)
    TestFunc(__FUNCTION__); // Распечатываем тики, полученные разными способами.
}


The result is bad: in OnTick/OnBookEvent, the ticks received by different methods very often don't coincide right inside one On-function. In this case it is impossible to determine in which function which method of getting the tick is relevant and which is not. Terrible vagueness.


It seems to happen when the glass itself is obsolete.

 

Try this:

//+------------------------------------------------------------------+
//|                                                   Ticks_test.mq5 |
//|                                      Copyright 2019 prostotrader |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019 prostotrader"
#property link      "https://www.mql5.com"
#property version   "1.00"
//---
bool is_book;
MqlTick ticks[];
ulong last_time, mem_cnt;
bool is_first;
int t_cnt, result;
enum ENUM_BOOK_OR_TICK
{
        USE_BOOK,       // Use OnBookEvent
        USE_TICK        // Use OnTick
};

input ENUM_BOOK_OR_TICK Mode = USE_BOOK;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
  is_book = MarketBookAdd(Symbol());
  result = CopyTicks(Symbol(), ticks, COPY_TICKS_ALL, 0, 1);
  if(result > 0)
  {
    last_time = ulong(ticks[0].time_msc);
    is_first = true;
  }
  else
  {
    is_first = false;
    Alert("No start time!");
    return(INIT_FAILED);
  }   
  return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+ 
//| возвращает строковое описание тика                               | 
//+------------------------------------------------------------------+ 
string GetTickDescription(MqlTick &tick) 
  { 
   string res = string(tick.time) + "." +  string(tick.time_msc%1000); 
// 
   bool buy_tick = ((tick.flags&TICK_FLAG_BUY)==TICK_FLAG_BUY); 
   bool sell_tick = ((tick.flags&TICK_FLAG_SELL)==TICK_FLAG_SELL); 
   bool ask_tick = ((tick.flags&TICK_FLAG_ASK)==TICK_FLAG_ASK); 
   bool bid_tick = ((tick.flags&TICK_FLAG_BID)==TICK_FLAG_BID); 
   bool last_tick = ((tick.flags&TICK_FLAG_LAST)==TICK_FLAG_LAST); 
   bool volume_tick = ((tick.flags&TICK_FLAG_VOLUME)==TICK_FLAG_VOLUME); 
// 
   if((buy_tick== true) || (sell_tick == true)) 
   { 
     res = res + (buy_tick?StringFormat(" Buy Tick: Last=%G Volume=%d ",tick.last,tick.volume):""); 
     res = res + (sell_tick?StringFormat(" Sell Tick: Last=%G Volume=%d ",tick.last,tick.volume):""); 
     res = res + (ask_tick?StringFormat(" Ask=%G ",tick.ask):""); 
     res = res + (bid_tick?StringFormat(" Bid=%G ",tick.ask):""); 
   } 
   else 
   { 
     res = res + (ask_tick?StringFormat(" Ask=%G ",tick.ask):""); 
     res = res + (bid_tick?StringFormat(" Bid=%G ",tick.ask):""); 
     res = res + (last_tick?StringFormat(" Last=%G ",tick.last):""); 
     res = res + (volume_tick?StringFormat(" Volume=%d ",tick.volume):""); 
   } 
   return res; 
  } 
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
  if(is_book == true) MarketBookRelease(Symbol());
}
//+------------------------------------------------------------------+
//| BookEvent function                                               |
//+------------------------------------------------------------------+
//void OnTick()
void OnBookEvent(const string &symbol)
{
  if ( Mode != USE_BOOK || symbol != Symbol() ) return;
  if(Symbol() == symbol)
  {
    if(is_first == true)
    {
      result = CopyTicks(Symbol(), ticks, COPY_TICKS_ALL, last_time, 0);
      if(result > 0)
      {
      //  Print("First packet of ticks:");
        t_cnt = 0;
        for(int i= 0; i<result; i++)
        {
          if(ticks[i].time_msc == ticks[0].time_msc) t_cnt++;
          Print(__FUNCTION__, ": ",GetTickDescription(ticks[i]));
        }
        is_first = false;
        last_time = ulong(ticks[0].time_msc);
      } 
    }
    else
    {
      result = CopyTicks(Symbol(), ticks, COPY_TICKS_ALL, last_time, 0);
      if(result > 0)
      {
        if(result > t_cnt)
        {
          mem_cnt = t_cnt;
          t_cnt = 0;
          for(int i= 0; i<(result - int(mem_cnt)); i++)
          {
            if(ticks[i].time_msc == ticks[0].time_msc) t_cnt++;
            Print(__FUNCTION__, ": ",GetTickDescription(ticks[i]));
          } 
          if(last_time == ulong(ticks[0].time_msc))
          {
            t_cnt += int(mem_cnt);
          }
          else last_time = ulong(ticks[0].time_msc + 1);
        }
        else
        {
          t_cnt = 0;
          last_time++;
        }
      }
      else
      {
        t_cnt = 0;
        last_time++;
        Print(__FUNCTION__, ": Pending order!");
      }
    }
  }
}

void OnTick()
{
   if ( Mode != USE_TICK ) return;
   if(is_first == true)
    {
      result = CopyTicks(Symbol(), ticks, COPY_TICKS_ALL, last_time, 0);
      if(result > 0)
      {
    //    Print("First packet of ticks:");
        t_cnt = 0;
        for(int i= 0; i<result; i++)
        {
          if(ticks[i].time_msc == ticks[0].time_msc) t_cnt++;
          Print(__FUNCTION__, ": ", GetTickDescription(ticks[i]));
        }
        is_first = false;
        last_time = ulong(ticks[0].time_msc);
      } 
    }
    else
    {
      result = CopyTicks(Symbol(), ticks, COPY_TICKS_ALL, last_time, 0);
      if(result > 0)
      {
        if(result > t_cnt)
        {
          mem_cnt = t_cnt;
          t_cnt = 0;
          for(int i= 0; i<(result - int(mem_cnt)); i++)
          {
            if(ticks[i].time_msc == ticks[0].time_msc) t_cnt++;
            Print(__FUNCTION__, ": ", GetTickDescription(ticks[i]));
          } 
          if(last_time == ulong(ticks[0].time_msc))
          {
            t_cnt += int(mem_cnt);
          }
          else last_time = ulong(ticks[0].time_msc + 1);
        }
        else
        {
          t_cnt = 0;
          last_time++;
        }
      }
      else
      {
        t_cnt = 0;
        last_time++;
        Print(__FUNCTION__, ": Pending order!");
      }
    }
  
}
//+------------------------------------------------------------------+

Even without anyGetTickCount64() you can see how the functions work

2020.01.31 17:01:56.363 Ticks_test (GOLD-3.20,H1)       OnTick: 2020.01.31 17:01:47.889 Ask=1585.4 
2020.01.31 17:01:57.294 Ticks_test (GOLD-3.20,H1)       OnBookEvent: 2020.01.31 17:01:50.159 Bid=1585.4 
2020.01.31 17:01:57.637 Ticks_test (GOLD-3.20,H1)       OnTick: 2020.01.31 17:01:47.889 Ask=1585.4 
2020.01.31 17:01:57.637 Ticks_test (GOLD-3.20,H1)       OnBookEvent: 2020.01.31 17:01:50.159 Bid=1585.4 
2020.01.31 17:01:57.690 Ticks_test (GOLD-3.20,H1)       OnTick: 2020.01.31 17:01:47.889 Ask=1585.4 
2020.01.31 17:01:57.690 Ticks_test (GOLD-3.20,H1)       OnBookEvent: 2020.01.31 17:01:50.159 Bid=1585.4 
2020.01.31 17:01:57.730 Ticks_test (GOLD-3.20,H1)       OnTick: 2020.01.31 17:01:47.889 Ask=1585.4 
2020.01.31 17:01:57.730 Ticks_test (GOLD-3.20,H1)       OnBookEvent: 2020.01.31 17:01:50.159 Bid=1585.4 
2020.01.31 17:01:58.293 Ticks_test (GOLD-3.20,H1)       OnTick: 2020.01.31 17:01:47.889 Ask=1585.4 
2020.01.31 17:01:58.294 Ticks_test (GOLD-3.20,H1)       OnBookEvent: 2020.01.31 17:01:50.159 Bid=1585.4 
2020.01.31 17:01:58.519 Ticks_test (GOLD-3.20,H1)       OnTick: 2020.01.31 17:01:47.889 Ask=1585.4 
2020.01.31 17:01:58.519 Ticks_test (GOLD-3.20,H1)       OnBookEvent: 2020.01.31 17:01:51.444 Bid=1585.4 
2020.01.31 17:01:58.519 Ticks_test (GOLD-3.20,H1)       OnBookEvent: 2020.01.31 17:01:51.444 Bid=1585.4 
2020.01.31 17:01:58.519 Ticks_test (GOLD-3.20,H1)       OnBookEvent: 2020.01.31 17:01:51.536 Bid=1585.4 
2020.01.31 17:01:58.519 Ticks_test (GOLD-3.20,H1)       OnBookEvent: 2020.01.31 17:01:52.107 Ask=1585.5 
2020.01.31 17:01:58.519 Ticks_test (GOLD-3.20,H1)       OnBookEvent: 2020.01.31 17:01:52.326 Ask=1585.4 
2020.01.31 17:01:59.674 Ticks_test (GOLD-3.20,H1)       OnBookEvent: 2020.01.31 17:01:51.536 Bid=1585.4 
2020.01.31 17:01:59.861 Ticks_test (GOLD-3.20,H1)       OnBookEvent: 2020.01.31 17:01:52.107 Ask=1585.5 
2020.01.31 17:02:00.530 Ticks_test (GOLD-3.20,H1)       OnBookEvent: 2020.01.31 17:01:52.326 Ask=1585.4 
2020.01.31 17:02:01.189 Ticks_test (GOLD-3.20,H1)       OnTick: 2020.01.31 17:01:47.889 Ask=1585.4 
2020.01.31 17:02:01.216 Ticks_test (GOLD-3.20,H1)       OnBookEvent: 2020.01.31 17:01:55.7 Ask=1585.5 
2020.01.31 17:02:01.492 Ticks_test (GOLD-3.20,H1)       OnBookEvent: Pending order!
2020.01.31 17:02:01.707 Ticks_test (GOLD-3.20,H1)       OnTick: 2020.01.31 17:01:47.889 Ask=1585.4 
2020.01.31 17:02:01.707 Ticks_test (GOLD-3.20,H1)       OnBookEvent: 2020.01.31 17:01:55.530 Ask=1585.4 
2020.01.31 17:02:01.967 Ticks_test (GOLD-3.20,H1)       OnBookEvent: Pending order!
2020.01.31 17:02:01.989 Ticks_test (GOLD-3.20,H1)       OnTick: 2020.01.31 17:01:47.889 Ask=1585.4 
2020.01.31 17:02:01.989 Ticks_test (GOLD-3.20,H1)       OnBookEvent: 2020.01.31 17:01:55.790 Bid=1585.4 
2020.01.31 17:02:02.287 Ticks_test (GOLD-3.20,H1)       OnBookEvent: Pending order!
2020.01.31 17:02:02.641 Ticks_test (GOLD-3.20,H1)       OnTick: 2020.01.31 17:01:47.889 Ask=1585.4 
2020.01.31 17:02:02.641 Ticks_test (GOLD-3.20,H1)       OnBookEvent: 2020.01.31 17:01:56.104 Ask=1585.5 
2020.01.31 17:02:02.888 Ticks_test (GOLD-3.20,H1)       OnTick: 2020.01.31 17:01:47.889 Ask=1585.4 
2020.01.31 17:02:03.050 Ticks_test (GOLD-3.20,H1)       OnTick: 2020.01.31 17:01:47.889 Ask=1585.4 
2020.01.31 17:02:03.050 Ticks_test (GOLD-3.20,H1)       OnBookEvent: 2020.01.31 17:01:56.691 Ask=1585.6 
2020.01.31 17:02:03.050 Ticks_test (GOLD-3.20,H1)       OnBookEvent: 2020.01.31 17:01:56.869 Bid=1585.6 
2020.01.31 17:02:03.376 Ticks_test (GOLD-3.20,H1)       OnBookEvent: 2020.01.31 17:01:56.869 Bid=1585.6 
2020.01.31 17:02:03.468 Ticks_test (GOLD-3.20,H1)       OnTick: 2020.01.31 17:01:47.889 Ask=1585.4 
2020.01.31 17:02:03.708 Ticks_test (GOLD-3.20,H1)       OnTick: 2020.01.31 17:01:47.889 Ask=1585.4 
2020.01.31 17:02:03.708 Ticks_test (GOLD-3.20,H1)       OnBookEvent: 2020.01.31 17:01:57.286 Ask=1585.5  Bid=1585.5 
2020.01.31 17:02:03.708 Ticks_test (GOLD-3.20,H1)       OnBookEvent: 2020.01.31 17:01:57.440 Ask=1585.6  Bid=1585.6 
2020.01.31 17:02:04.860 Ticks_test (GOLD-3.20,H1)       OnTick: 2020.01.31 17:01:47.889 Ask=1585.4 
2020.01.31 17:02:04.860 Ticks_test (GOLD-3.20,H1)       OnBookEvent: 2020.01.31 17:01:57.440 Ask=1585.6  Bid=1585.6 
Files:
20200131.log  28 kb