CopyTicksRange () no funciona correctamente en MQL5. a - página 3

 
fxsaber #:

Unidades.

Probablemente sí, pero no deja de ser una función básica y si el propio terminal la utiliza, al menos para exportar datos, resta credibilidad al terminal también

 

Ejemplos de errores prometidos en el archivo adjunto. Sorprendentemente, Err_SymbolInfoTick2() funcionó correctamente durante un tiempo, pero luego empezó a devolver también una fecha nula. Hay comentarios explicativos en el código.

Registro:

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)    ---------------------


Diversión para un aperitivo: si observas los ticks con las herramientas del terminal, puedes obtener más ticks de los que se registraron. (ver foto ). Y si la fecha de "antes" se reduce a 2021.09.18, entonces se registran menos.

Archivos adjuntos:
untitled.jpg  605 kb
 
sí, no importa si la matriz es estática o dinámica
 
RusPro #:

Ejemplos de errores prometidos

Por desgracia, no hay acceso a estos personajes para reproducirlos.

 
fxsaber #:

Por desgracia, no hay acceso a estos símbolos para reproducirlos.

es el micex. ok, probaré el forex.

 
RusPro #:

es el MICEX. Vale, probaré el forex.

1. No existe el símbolo "@BR" en MICEX.

Parece que estás utilizando un símbolo personalizado.

Y puede haber un error al crearlo.

Yo uso mucho las funciones CopyTicks y CopyTicksRange en los símbolos originales de MICEX - no he notado ningún error.

2. El terminal no almacena todo el historial de ticks y la primera llamada a la función puede devolver ticks que no corresponden a todo el periodo solicitado.

Añadido

Aquí hay un ejemplo de un indicador, donde cargo los ticks usando la función CopyTicksRange

//+------------------------------------------------------------------+
//|                                                   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);
  }
//+------------------------------------------------------------------+
Y todo se carga bien, pero no siempre a la primera.
 
prostotrader #:

1. No existe el símbolo "@BR" en MICEX

Aquí hay un ejemplo de indicador, donde cargo los ticks usando la función CopyTicksRange

Y todo se carga bien, pero no siempre a la primera.

Esta es una cola de los futuros del petróleo. Broker BCS. Puede llamarse de forma diferente en los distintos corredores. Pero exactamente los mismos problemas habrá en otros símbolos.

 
prostotrader #:

En tu ejemplo funciona, porque las condiciones de llamada son diferentes - la hora de inicio es siempre igual al inicio de la barra existente (es decir, se sabe que existen ticks) y se lee todo el historial de ticks de la última barra a la vez.

Por cierto, una de mis muletas funciona de forma similar a la tuya. También obtengo los tiempos de las barras existentes al principio, y luego las divido en segmentos continuos máximos y obtengo los ticks. Pero se presenta otro problema - si no hay suficiente matriz de recepción para los datos, la reanudación del resto es un baile de pandereta (del que he hablado más arriba).

Además, trabajar con matrices dinámicas es mucho más lento y hay que tener en cuenta la posible fragmentación de la memoria.

 
prostotrader #:

2. El terminal no almacena todo el historial de ticks y es posible que la primera llamada a la función no devuelva los ticks de todo el periodo solicitado.

No hay problema si no se devuelve todo el periodo, el problema es cuando se devuelve otro periodo en lugar del solicitado. O, peor aún, cuando devuelve el solicitado y algunos otros ticks, no incluidos en el rango


He sustituido el símbolo en mi ejemplo por "SILV-12.21" Tengo el mismo error, y lo que es interesante, SymbolInfoTick devolvió la respuesta correcta en la última prueba :) pero ¿cómo puedo adivinar, cuando se equivoca y cuando se equivoca?


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 #:

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


En forex, los mismos errores. Broker Alpari, cuenta de prueba. Símbolo del EURUSD


Símbolo personalizado hecho sobre la base de EURUSD, sólo dejó el nombre también


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