Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 174

 
mila.com:

Hello.

Please help me to display data from a file as a histogram.

In the file "file.txt" a date corresponds to a number, like this:

29.03.2017. 574391

30.03.2017. 741308

31.03.2017. 614367

I get data from file and print it out, like this:


Histogram by bar size to make it look like an indicator )

So you put the data in the graphical buffer, not on the printout. Determine the date from which the histogram is to be drawn and put the data there.
 
-Aleks-:

So, you put the data in the graphic buffer, not on the print. Determine the date from which you want the histogram to be plotted and put the data there.

That's the difficulty.

I printed it out to make it clear that I am getting the data from the file in general.

I can't figure out how to assign them to the relevant dates.

 
mila.com:

That's the difficulty.

I printed it out to make it clear that I am getting the data from the file in general.

I can't figure out how to assign them to the relevant dates.

Take the date from the file, find the bar number from the date and draw into it...
 
Alexey Viktorov:
Take the date from the file, find the bar number from the date and draw into it...

How exactly do you do this?

Show me please.

 
mila.com:

How exactly do you do this?

Please show me.

Use string functions. In particular

string  StringSubstr(
   string  string_value,     // строка
   int     start_pos,        // с какой позиции начать
   int     length=0          // длина извлекаемой строки
   );

pull 10 characters from the zero position and convert the string to a date.

But if there is no bar open time in the string, histograms will not be on every bar if we run it on a chart other than D1.

Строковые функции - Справочник MQL4
Строковые функции - Справочник MQL4
  • docs.mql4.com
Строковые функции - Справочник MQL4
 

Please help me to write a function for calculating the number of bars starting from the bar where the order was opened.

For example: If we have an open order on bar 5, the function should return 5.

 
Bek001:

My friends, please help me to write a function to calculate the number of bars starting from the bar where the order was opened.

For example: If we have an open order on bar 5, the function should return 5.

int shift=iBarShift(NULL,PERIOD_СURRENT,OrderOpenTime());
 
Alexey Viktorov:

Use string functions. In particular

pull 10 characters from the zero position and convert the string to a date.

But if there is no bar open time in the string, the histogram will not be on every bar if I run it on a chart other than D1.

Thank you, I'm pulling the date and the value separately.

Now how do I fill the buffer with this?

 for(int i=0; i<limit;i++){

string InpFileName="file.txt";
 ResetLastError(); 
  int file_handle=FileOpen(InpFileName,FILE_TXT|FILE_READ);
   
   if(file_handle!=INVALID_HANDLE) 
     { 
      PrintFormat("Файл %s открыт для чтения",InpFileName); 
      PrintFormat("Путь к файлу: %s\\Files\\",TerminalInfoString(TERMINAL_DATA_PATH)); 
      //--- вспомогательные переменные 
      int    str_size; 
      string str,str_b1,str_dat1; 
      //--- прочитаем данные из файла 
      while(!FileIsEnding(file_handle)) 
        { 
         //--- узнаем сколько символов использовано для записи времени 
         str_size=FileReadInteger(file_handle,INT_VALUE); 
         //--- прочитаем строку 
         str=FileReadString(file_handle,str_size); 
         str_dat1= StringSubstr(str,0,10);
         str_b1= StringSubstr(str,12,6);
         //--- распечатаем строку 
         PrintFormat(str_dat1); 
         PrintFormat(str_b1);
        } 
      //--- закроем файл 
      FileClose(file_handle); 
      PrintFormat("Данные прочитаны, файл %s закрыт",InpFileName); 
     } 
   else 
      PrintFormat("Не удалось открыть файл %s, Код ошибки = %d",InpFileName,GetLastError()); 
    //}
   
      Range_Buffer[i]=//???
      }
 
mila.com:

Thank you, I'm pulling the date and the value separately.

Now how do I fill the buffer with this?

Range_Buffer[i]=значение//???

It has to be in a loop. The while loop in the for loop is a waste of time. We have to read one line, pull the date and the value and work with them. Find the number of bar by time and put the value there. And only after that move on to the next entry.

 
mila.com:

That's the difficulty.

I printed it out to make it clear that I am getting the data from the file in general.

I can't figure out how to assign them to the relevant dates.

Does one record correspond to one bar or not?