Имеется проблема обновления OHLC в CustomSymbol

 

Я пробовал следующий код:

#include  "Symbol.mqh"

string   sym_name_train          = "Train";

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnStart()
  {
   string arr[];
   MqlRates rate_train[];

   const SYMBOL sym_train(sym_name_train);
   sym_train.CloneProperties(Symbol());
   sym_train.SetProperty(SYMBOL_DIGITS, 7);
   
   int file = FileOpen("data.csv", FILE_SHARE_READ|FILE_READ|FILE_TXT|FILE_ANSI);
   if(file == INVALID_HANDLE)
     {
      Print(Symbol(), " : Cannot Open  File: ", GetLastError());
      FileClose(file);
      return;
     }
   int len_train = int(FileReadArray(file, arr));
   FileClose(file);

   string ohlc[];

   ArrayResize(rate_train, len_train - 1);

   for(int loop = 1; loop < len_train; loop++)
     {
      StringSplit(arr[loop], ',', ohlc);
      int index = loop - 1;

      rate_train[index].time         = (index == 0)? 0 : rate_train[index - 1].time + 60;             // the 0 index is for the Time.
      rate_train[index].open         = double(ohlc[1]);  // teh 1 is for the Open price
      rate_train[index].high         = double(ohlc[2]);  // teh 2 is for the High price
      rate_train[index].low          = double(ohlc[3]);  // teh 3 is for the Low price
      rate_train[index].close        = double(ohlc[4]);  // teh 4 is for the Close price
      rate_train[index].spread       = 0.0;
      rate_train[index].spread       = 0.0;
      rate_train[index].tick_volume  = 0.0;
      rate_train[index].real_volume  = 0.0;
     }

   if(CustomRatesUpdate(sym_name_train, rate_train) <= 0)
     {
      Print(Symbol(), " : Не удалось обновить: ", GetLastError());
      if(CustomRatesReplace(sym_name_train, 0, len_train - 1, rate_train) <= 0)
        {
         Print(Symbol(), " : Даже замена не удалась: ", GetLastError());
         return;
        }
     }
   else
      ArrayPrint(rate_train);
  }

Но всегда есть обновление, написанное на диаграмме.

Плюс название символа другое в окне спецификации. Смотрите изображение:

Даже я пытаюсь изменить имя в окне «Спецификация», но оно помечено красным цветом.

Я не понимаю, почему это происходит так, как никогда раньше.

Моя сборка:

Пожалуйста, дайте мне знать, что я могу сделать, чтобы решить эту проблему и обновить свой CustomSymbol.

Я прикрепил нужный файл.

Файлы:
Symbol.mqh  7 kb
 
Продублируйте, пожалуйста, свое сообщение на языке оригинала. В переводе невозможно ничего понять.
 
Ihor Herasko :
Продублируйте, пожалуйста, свое сообщение на языке оригинала. В переводе невозможно ничего понять.

Дайте мне знать, какую часть вы не получили.

 

Here is what I am trying to say.

I've tried the following code:

#include  "Symbol.mqh"

string   sym_name_train          = "Train";

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnStart()
  {
   string arr[];
   MqlRates rate_train[];

   const SYMBOL sym_train(sym_name_train);
   sym_train.CloneProperties(Symbol());
   sym_train.SetProperty(SYMBOL_DIGITS, 7);
   
   int file = FileOpen("data.csv", FILE_SHARE_READ|FILE_READ|FILE_TXT|FILE_ANSI);
   if(file == INVALID_HANDLE)
     {
      Print(Symbol(), " : Cannot Open  File: ", GetLastError());
      FileClose(file);
      return;
     }
   int len_train = int(FileReadArray(file, arr));
   FileClose(file);

   string ohlc[];

   ArrayResize(rate_train, len_train - 1);

   for(int loop = 1; loop < len_train; loop++)
     {
      StringSplit(arr[loop], ',', ohlc);
      int index = loop - 1;

      rate_train[index].time         = (index == 0)? 0 : rate_train[index - 1].time + 60;             // the 0 index is for the Time.
      rate_train[index].open         = double(ohlc[1]);  // teh 1 is for the Open price
      rate_train[index].high         = double(ohlc[2]);  // teh 2 is for the High price
      rate_train[index].low          = double(ohlc[3]);  // teh 3 is for the Low price
      rate_train[index].close        = double(ohlc[4]);  // teh 4 is for the Close price
      rate_train[index].spread       = 0.0;
      rate_train[index].spread       = 0.0;
      rate_train[index].tick_volume  = 0.0;
      rate_train[index].real_volume  = 0.0;
     }

   if(CustomRatesUpdate(sym_name_train, rate_train) <= 0)
     {
      Print(Symbol(), " : Train Rate Update failed: ", GetLastError());
      if(CustomRatesReplace(sym_name_train, 0, len_train - 1, rate_train) <= 0)
        {
         Print(Symbol(), " : Even the Replacement failed for Training: ", GetLastError());
         return;
        }
     }
   else
      ArrayPrint(rate_train);
  }

But I am getting the Waiting Update on the chart and no candles.

Plus the name of the symbol is different in the specification window. See image:

Even I try to change the name in the Specification window, but it is marked in red.

I don't understand why this is happening like never before.

My build:

Please let me know what I can do to fix this problem and update my CustomSymbol.

I have attached the required file.

 
jaffer wilson:

But I am getting the Waiting Update on the chart and no candles.

Вот теперь уже понятнее, хотя вполне может быть, что ситуация другая. Как я сейчас понял: после применения CustomRatesUpdate график все равно оказывается пустым. При этом сама функция CustomRatesUpdate не возвращает ошибок. Если так, то проверьте сам ценовой ряд, который передается в функцию. В нем могут быть свечи с повторяющимся временем. В моем случае это был попросту 0, т. е. функция расценивала такие бары как бары со временем 1970.01.01 00:00.

Также вполне возможны неправильные бары по цене. К примеру, цена открытия/закрытия выше High или ниже Low свечи.

 

Форум по трейдингу, автоматическим торговым системам и тестированию торговых стратегий

Библиотеки: Symbol

fxsaber, 2021.06.07 13:04

rates[count].tick_volume = 4; // Если OHLC-цены попарно не равны, то тиковый объем не может быть меньше четырех.
 

Большое спасибо за ваши ответы. @fxsaber Я изменил свой код, как вы предложили. Но все равно не обновите окно на графике. Пожалуйста помоги. Я приложил данные.

Код:

#include  "Symbol.mqh"

string   sym_name_train          = "Train";

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnStart()
  {
   string arr[];
   MqlRates rate_train[];

   const SYMBOL sym_train(sym_name_train);
   sym_train.CloneProperties(Symbol());
   sym_train.SetProperty(SYMBOL_DIGITS, 7);

   int file = FileOpen("data.csv", FILE_SHARE_READ|FILE_READ|FILE_TXT|FILE_ANSI);
   if(file == INVALID_HANDLE)
     {
      Print(Symbol(), " : Cannot Open  File: ", GetLastError());
      FileClose(file);
      return;
     }
   int len_train = int(FileReadArray(file, arr));
   FileClose(file);

   string ohlc[];

   ArrayResize(rate_train, len_train - 1);

   for(int loop = 1; loop < len_train; loop++)
     {
      StringSplit(arr[loop], ',', ohlc);
      int index = loop - 1;

      rate_train[index].time         = (index == 0)? 0 : rate_train[index - 1].time + 60;             // the 0 index is for the Time.
      rate_train[index].open         = double(ohlc[1]);  // teh 1 is for the Open price
      rate_train[index].high         = double(ohlc[2]);  // teh 2 is for the High price
      rate_train[index].low          = double(ohlc[3]);  // teh 3 is for the Low price
      rate_train[index].close        = double(ohlc[4]);  // teh 4 is for the Close price
      rate_train[index].spread       = 0.0;
      rate_train[index].spread       = 0.0;
      rate_train[index].tick_volume  = 4;
      rate_train[index].real_volume  = 0.0;
     }

   if(CustomRatesUpdate(sym_name_train, rate_train) <= 0)
     {
      Print(Symbol(), " : Train Rate Update failed: ", GetLastError());
      if(CustomRatesReplace(sym_name_train, 0, len_train - 1, rate_train) <= 0)
        {
         Print(Symbol(), " : Even the Replacement failed for Training: ", GetLastError());
         return;
        }
     }
   else
      ArrayPrint(rate_train);
  }

Выходной массив:

                     [time]  [open]  [high]   [low] [close] [tick_volume] [spread] [real_volume]
[    0] 1970.01.01 00:00:00 1.10760 1.10867 1.10758 1.10834             4        0             0
[    1] 1970.01.01 00:01:00 1.10834 1.10894 1.10806 1.10859             4        0             0
[    2] 1970.01.01 00:02:00 1.10855 1.10914 1.10809 1.10904             4        0             0
[    3] 1970.01.01 00:03:00 1.10904 1.10926 1.10851 1.10915             4        0             0
[    4] 1970.01.01 00:04:00 1.10916 1.10930 1.10779 1.10839             4        0             0
[    5] 1970.01.01 00:05:00 1.10838 1.10885 1.10799 1.10802             4        0             0
[    6] 1970.01.01 00:06:00 1.10800 1.10807 1.10627 1.10641             4        0             0
[    7] 1970.01.01 00:07:00 1.10641 1.10697 1.10629 1.10687             4        0             0
[    8] 1970.01.01 00:08:00 1.10688 1.10775 1.10686 1.10763             4        0             0
[    9] 1970.01.01 00:09:00 1.10763 1.10830 1.10763 1.10791             4        0             0

Изображений:


Файлы:
data.csv  1159 kb
 
Может ли кто-нибудь использовать мои данные и создать пример отображения диаграммы? Помогите мне в этом, пожалуйста.
 
jaffer wilson:

Большое спасибо за ваши ответы. @fxsaber Я изменил свой код, как вы предложили. Но все равно не обновите окно на графике. Пожалуйста помоги. Я приложил данные.

rate_train[index].time         = (index == 0)? D'1970.01.02' : rate_train[index - 1].time + 60;

Любое время 1-го января 1970-го года не может быть использовано. Думаю, это баг.

 
fxsaber :

Любое время 1-го января 1970-го года не может быть использовано. Думаю, это баг.

Я думаю это решение

Причина обращения: