CopyTicksRange () does not work correctly in MQL5. a - page 3

 
fxsaber #:

Units.

Probably so, but it is still a basic function and if the terminal itself uses it, at least to export data, it undermines the credibility of the terminal as well

 

Promised error examples in the attached file. Surprisingly, Err_SymbolInfoTick2() worked correctly for a while, but then started to return null date as well. There are explanatory comments in the code.

Log:

2021.09.19 06:01:24.674 ErrorCopyTicks (CustomBR,H1)    ---------Err_CopyTicksRange()------------
2021.09.19 06:01:24.754 ErrorCopyTicks (CustomBR,H1)    CopyTicksRange('@BR',Ticks,COPY_TICKS_ALL, 2021.01.29 23:57:00:000, 2021.01.31 23:59:00:000 );  received 109425 ticks
2021.09.19 06:01:24.754 ErrorCopyTicks (CustomBR,H1)    2021.01.29 00:02:14:782 - first tick, 2021.01.29 23:56:43:863 - last tick
2021.09.19 06:01:24.754 ErrorCopyTicks (CustomBR,H1)    ---------------------
2021.09.19 06:01:24.754 ErrorCopyTicks (CustomBR,H1)    ---------Err_CopyTicks()------------
2021.09.19 06:01:24.767 ErrorCopyTicks (CustomBR,H1)    CopyTicks('@BR',Ticks,COPY_TICKS_ALL, 2021.01.29 23:57:00:000, 100 );  received 100 ticks
2021.09.19 06:01:24.767 ErrorCopyTicks (CustomBR,H1)    2021.01.29 00:02:14:782 - first tick, 2021.01.29 10:00:12:292 - last tick
2021.09.19 06:01:24.767 ErrorCopyTicks (CustomBR,H1)    ---------------------
2021.09.19 06:01:24.767 ErrorCopyTicks (CustomBR,H1)    ---------Err_CopyTicks()------------
2021.09.19 06:01:24.906 ErrorCopyTicks (CustomBR,H1)    CopyTicks('@BR',Ticks,COPY_TICKS_ALL, 2021.01.29 23:57:00:000, 1000000 );  received 1000000 ticks
2021.09.19 06:01:24.906 ErrorCopyTicks (CustomBR,H1)    2021.01.29 00:02:14:782 - first tick, 2021.02.08 14:17:58:484 - last tick
2021.09.19 06:01:24.906 ErrorCopyTicks (CustomBR,H1)    ---------------------
2021.09.19 06:01:24.906 ErrorCopyTicks (CustomBR,H1)    ---------Err_SymbolInfoTick1('CustomBR')------------
2021.09.19 06:01:24.969 ErrorCopyTicks (CustomBR,H1)    CopyTicksRange('CustomBR',Ticks,COPY_TICKS_ALL, 2021.09.17 00:00:00:000, 2021.09.17 20:00:00:000 );  received 189530 ticks
2021.09.19 06:01:24.969 ErrorCopyTicks (CustomBR,H1)    2021.09.17 00:02:12:052 - first tick, 2021.09.17 19:59:59:782 - last tick
2021.09.19 06:01:25.029 ErrorCopyTicks (CustomBR,H1)    CustomTicksReplace('CustomBR',2021.09.17 00:00:00:000, 2021.09.17 20:00:00:000, Ticks, 189530  );  replaced 189530 ticks
2021.09.19 06:01:25.029 ErrorCopyTicks (CustomBR,H1)    ret=1, mt.time_msc=1970.01.01 00:00:00:000
2021.09.19 06:01:25.029 ErrorCopyTicks (CustomBR,H1)    ---------------------
2021.09.19 06:01:25.029 ErrorCopyTicks (CustomBR,H1)    ---------Err_SymbolInfoTick2('CustomBR')------------
2021.09.19 06:01:25.091 ErrorCopyTicks (CustomBR,H1)    CopyTicksRange('CustomBR',Ticks,COPY_TICKS_ALL, 2021.09.17 00:00:00:000, 2021.09.17 20:00:00:000 );  received 189530 ticks
2021.09.19 06:01:25.091 ErrorCopyTicks (CustomBR,H1)    2021.09.17 00:02:12:052 - first tick, 2021.09.17 19:59:59:782 - last tick
2021.09.19 06:01:25.153 ErrorCopyTicks (CustomBR,H1)    CustomTicksAdd('CustomBR',Ticks, 189530  );  added 189530 ticks
2021.09.19 06:01:25.153 ErrorCopyTicks (CustomBR,H1)    ret=1, mt.time_msc=1970.01.01 00:00:00:000
2021.09.19 06:01:25.153 ErrorCopyTicks (CustomBR,H1)    ---------------------


Fun for a snack: if you watch the ticks with the terminal tools, you can get more ticks than were recorded. (see picture ). And if the "before" date is reduced to 2021.09.18 then there are less of them recorded.

Files:
untitled.jpg  605 kb
 
yes, it doesn't matter if the array is static or dynamic
 
RusPro #:

Promised error examples

Unfortunately, there is no access to these characters to reproduce.

 
fxsaber #:

Unfortunately, no access to these symbols to reproduce.

it's the micex. ok, i'll try the forex.

 
RusPro #:

it's the MICEX. OK, I'll try the forex.

1. There is no "@BR" symbol on MICEX.

You seem to be using a custom symbol.

And there might be an error in creating it.

I use CopyTicks and CopyTicksRange functions a lot on original MICEX symbols - haven't noticed any errors.

2. The terminal doesn't store the whole tick history and the first function call may return ticks not for the whole requested period.

Added

Here is an example of an indicator, where I load ticks using the CopyTicksRange function

//+------------------------------------------------------------------+
//|                                                   Ticks_test.mq5 |
//|                                      Copyright 2021 prostotrader |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021 prostotrader"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_separate_window
#property indicator_plots   1
#property indicator_buffers 1

enum IND_STAGE
{
  LOAD_TICKS = 0,
  READ_TICKS = 1,
  FILL_DATA = 2
};
struct T_DATA
{
  datetime bar_time;
  int ticks_cnt;
  MqlTick pr_bar_ticks[];
};
struct MARKET_DATA
{
  int time_cnt;
  int cnt;
  IND_STAGE stage;
  T_DATA t_data[];
  MqlTick ticks[];
  int live_cnt;
  int a_cnt;
  datetime time_array[];
};
MARKET_DATA m_data;
datetime start_time, end_time;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   end_time = datetime(SymbolInfoInteger(Symbol(), SYMBOL_EXPIRATION_TIME));
   m_data.stage = LOAD_TICKS;
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator Load ticks function                             |
//+------------------------------------------------------------------+
bool LoadTicks(const datetime &a_times[])
{
  int bars = Bars(Symbol(),PERIOD_M1);
  datetime cur_time = TimeTradeServer();
  if(cur_time > end_time)
  {
    cur_time = end_time;
  }
  int result = CopyTime(Symbol(), PERIOD_M1, 0, bars, m_data.time_array);
  if(result > 0)
  {
    start_time = m_data.time_array[0];
    if(m_data.time_array[result - 1] == a_times[ArraySize(a_times) - 1])
    {
      m_data.time_cnt = result;
      result = CopyTicksRange(Symbol(), m_data.ticks, COPY_TICKS_INFO, ulong(start_time) * 1000, ulong(cur_time) * 1000);
      if(result > 0)
      {
        if(m_data.ticks[result-1].time >= m_data.time_array[m_data.time_cnt - 1]) 
        {
          m_data.cnt = result;
          return(true); 
        } else Print(__FUNCTION__, ": Не хватает тиков ", Symbol(), "!"); 
      } else Print(__FUNCTION__, ": Не получены тики по символу ", Symbol(), "!");
    } else Print(__FUNCTION__, ": Не хватает баров по символу ", Symbol(), "!");
  } else Print(__FUNCTION__, ": Не скопировано время баров по символу ", Symbol(), "!");
  return(false);
}  
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[] )
  {
  switch (m_data.stage)
  {
    case LOAD_TICKS:
      if(LoadTicks(time) == true)
      {
        Print("All ticks loaded.");
        m_data.stage = READ_TICKS;
        return(rates_total);
      }
      return(0);
    break;
    case READ_TICKS:
    break;
  }
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
And everything loads fine, but not always the first time.
 
prostotrader #:

1. There is no "@BR" symbol on MICEX

Here is an example of indicator, where I load ticks using CopyTicksRange function

And everything loads fine, but not always the first time.

This is a glue of oil futures. Broker BCS. It may be called differently at different brokers. But exactly the same problems will be on other symbols.

 
prostotrader #:

In your example it works, because calling conditions are different - start time is always equal to start of existing bar (i.e. ticks are known to exist) and you read all tick history of the last bar at once.

By the way, one of my crutches works similar to yours. I also get the times of existing bars at first, and then break them into maximal continuous segments and get the ticks. But another problem occurs - if there's not enough of receiving array for data, the rest resuming is a tambourine dance (about which I've talked above).

And working with dynamic arrays is much slower and you have to consider possible memory fragmentation.

 
prostotrader #:

2. The terminal does not store the entire tick history and the first call to the function may not return ticks for the entire period requested.

There is no problem if not the whole period is returned, the problem is when another period is returned instead of the requested one. Or, even worse, when it returns the requested one and some other ticks, not included into the range


I replaced the symbol in my example with "SILV-12.21" I got the same error, and what's interesting, SymbolInfoTick returned the right answer in the last test :) but how do I guess, when it's wrong and when it's wrong?


2021.09.19 15:27:55.089	ErrorCopyTicks (CustomBR,H1)	---------Err_CopyTicksRange()------------
2021.09.19 15:27:55.090	ErrorCopyTicks (CustomBR,H1)	CopyTicksRange('SILV-12.21',Ticks,COPY_TICKS_ALL, 2021.01.29 23:57:00:000, 2021.01.31 23:59:00:000 );  received 1758 ticks
2021.09.19 15:27:55.090	ErrorCopyTicks (CustomBR,H1)	2021.01.29 00:02:14:782 - first tick, 2021.01.29 23:49:01:540 - last tick
2021.09.19 15:27:55.090	ErrorCopyTicks (CustomBR,H1)	---------------------
2021.09.19 15:27:55.090	ErrorCopyTicks (CustomBR,H1)	---------Err_CopyTicks()------------
2021.09.19 15:27:55.091	ErrorCopyTicks (CustomBR,H1)	CopyTicks('SILV-12.21',Ticks,COPY_TICKS_ALL, 2021.01.29 23:57:00:000, 100 );  received 100 ticks
2021.09.19 15:27:55.091	ErrorCopyTicks (CustomBR,H1)	2021.01.29 00:02:14:782 - first tick, 2021.01.29 11:02:44:891 - last tick
2021.09.19 15:27:55.091	ErrorCopyTicks (CustomBR,H1)	---------------------
2021.09.19 15:27:55.091	ErrorCopyTicks (CustomBR,H1)	---------Err_CopyTicks()------------
2021.09.19 15:27:55.170	ErrorCopyTicks (CustomBR,H1)	CopyTicks('SILV-12.21',Ticks,COPY_TICKS_ALL, 2021.01.29 23:57:00:000, 1000000 );  received 763140 ticks
2021.09.19 15:27:55.170	ErrorCopyTicks (CustomBR,H1)	2021.01.29 00:02:14:782 - first tick, 2021.09.17 23:58:41:031 - last tick
2021.09.19 15:27:55.170	ErrorCopyTicks (CustomBR,H1)	---------------------
2021.09.19 15:27:55.170	ErrorCopyTicks (CustomBR,H1)	---------Err_SymbolInfoTick1('CustomBR')------------
2021.09.19 15:27:55.178	ErrorCopyTicks (CustomBR,H1)	CopyTicksRange('SILV-12.21',Ticks,COPY_TICKS_ALL, 2021.09.17 00:00:00:000, 2021.09.17 20:00:00:000 );  received 42793 ticks
2021.09.19 15:27:55.178	ErrorCopyTicks (CustomBR,H1)	2021.09.17 00:03:04:576 - first tick, 2021.09.17 19:59:32:398 - last tick
2021.09.19 15:27:55.190	ErrorCopyTicks (CustomBR,H1)	CustomTicksReplace('CustomBR',2021.09.17 00:00:00:000, 2021.09.17 20:00:00:000, Ticks, 42793  );  replaced 42793 ticks
2021.09.19 15:27:55.190	ErrorCopyTicks (CustomBR,H1)	ret=1, mt.time_msc=1970.01.01 00:00:00:000
2021.09.19 15:27:55.190	ErrorCopyTicks (CustomBR,H1)	---------------------
2021.09.19 15:27:55.190	ErrorCopyTicks (CustomBR,H1)	---------Err_SymbolInfoTick2('CustomBR')------------
2021.09.19 15:27:55.196	ErrorCopyTicks (CustomBR,H1)	CopyTicksRange('SILV-12.21',Ticks,COPY_TICKS_ALL, 2021.09.17 00:00:00:000, 2021.09.17 20:00:00:000 );  received 42793 ticks
2021.09.19 15:27:55.196	ErrorCopyTicks (CustomBR,H1)	2021.09.17 00:03:04:576 - first tick, 2021.09.17 19:59:32:398 - last tick
2021.09.19 15:27:55.210	ErrorCopyTicks (CustomBR,H1)	CustomTicksAdd('CustomBR',Ticks, 42793  );  added 42793 ticks
2021.09.19 15:27:55.210	ErrorCopyTicks (CustomBR,H1)	ret=1, mt.time_msc=2021.09.17 19:59:32:398
2021.09.19 15:27:55.210	ErrorCopyTicks (CustomBR,H1)	--------------------- 

 
fxsaber #:

К сожалению, нет доступа к этим символам, чтобы воспроизвести.


On forex, the same mistakes. Alpari broker, test account. EURUSD symbol


Custom symbol made on the basis of EURUSD, just left the name too


2021.09.19 15:36:52.417 tester (EURUSD,H1)      ---------Err_CopyTicksRange()------------
2021.09.19 15:36:52.432 tester (EURUSD,H1)      CopyTicksRange('EURUSD',Ticks,COPY_TICKS_ALL, 2021.01.29 23:57:00:000, 2021.01.31 23:59:00:000 );  received 102934 ticks
2021.09.19 15:36:52.432 tester (EURUSD,H1)      2021.01.29 00:00:00:139 - first tick, 2021.01.29 23:54:59:930 - last tick
2021.09.19 15:36:52.432 tester (EURUSD,H1)      ---------------------
2021.09.19 15:36:52.432 tester (EURUSD,H1)      ---------Err_CopyTicks()------------
2021.09.19 15:36:52.445 tester (EURUSD,H1)      CopyTicks('EURUSD',Ticks,COPY_TICKS_ALL, 2021.01.29 23:57:00:000, 100 );  received 100 ticks
2021.09.19 15:36:52.445 tester (EURUSD,H1)      2021.01.29 00:00:00:139 - first tick, 2021.01.29 00:12:52:513 - last tick
2021.09.19 15:36:52.445 tester (EURUSD,H1)      ---------------------
2021.09.19 15:36:52.445 tester (EURUSD,H1)      ---------Err_CopyTicks()------------
2021.09.19 15:36:52.577 tester (EURUSD,H1)      CopyTicks('EURUSD',Ticks,COPY_TICKS_ALL, 2021.01.29 23:57:00:000, 1000000 );  received 1000000 ticks
2021.09.19 15:36:52.577 tester (EURUSD,H1)      2021.01.29 00:00:00:139 - first tick, 2021.02.15 18:31:34:723 - last tick
2021.09.19 15:36:52.577 tester (EURUSD,H1)      ---------------------
2021.09.19 15:36:52.577 tester (EURUSD,H1)      ---------Err_SymbolInfoTick1('CustomBR')------------
2021.09.19 15:36:52.579 tester (EURUSD,H1)      CopyTicksRange('EURUSD',Ticks,COPY_TICKS_ALL, 2021.09.17 00:00:00:000, 2021.09.17 20:00:00:000 );  received 78831 ticks
2021.09.19 15:36:52.579 tester (EURUSD,H1)      2021.09.17 00:00:00:349 - first tick, 2021.09.17 19:59:59:088 - last tick
2021.09.19 15:36:52.645 tester (EURUSD,H1)      CustomTicksReplace('CustomBR',2021.09.17 00:00:00:000, 2021.09.17 20:00:00:000, Ticks, 78831  );  replaced 78831 ticks
2021.09.19 15:36:52.645 tester (EURUSD,H1)      ret=1, mt.time_msc=1970.01.01 00:00:00:000
2021.09.19 15:36:52.645 tester (EURUSD,H1)      ---------------------
2021.09.19 15:36:52.645 tester (EURUSD,H1)      ---------Err_SymbolInfoTick2('CustomBR')------------
2021.09.19 15:36:52.658 tester (EURUSD,H1)      CopyTicksRange('EURUSD',Ticks,COPY_TICKS_ALL, 2021.09.17 00:00:00:000, 2021.09.17 20:00:00:000 );  received 78831 ticks
2021.09.19 15:36:52.658 tester (EURUSD,H1)      2021.09.17 00:00:00:349 - first tick, 2021.09.17 19:59:59:088 - last tick
2021.09.19 15:36:52.686 tester (EURUSD,H1)      CustomTicksAdd('CustomBR',Ticks, 78831  );  added 78831 ticks
2021.09.19 15:36:52.686 tester (EURUSD,H1)      ret=1, mt.time_msc=2021.09.17 19:59:59:088