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

 
-Aleks-:

Do you have one entry corresponding to one bar or not?

Yes, it will be one bar of the histogram on PERIOD_D1 on the bar on the twenty-ninth of March.

29.03.2017. 574391

 

The bar graph is set correctly if the date is written like this

int shift=iBarShift(Symbol(),PERIOD_D1,"29.03.2017");
Range_Buffer[shift]= str_b1;

but it is not set if I write it like this

str_dat1= StringSubstr(str,0,10);//

int shift=iBarShift(Symbol(),PERIOD_D1,str_dat1);

Range_Buffer[shift]= str_b1;

The date(str_dat1) is printed correctly.

What isthe reason?



 
mila.com:

Removed the while loop, I get the first line like this

Please tell me what is wrong.

We have to check what we get in the str_dat1 variable

Actually, the iBarShift should pass a date of datetime type, not a string. Maybe it accepts a clean string as a date, while it won't accept a variable.

It's better to convert received string into datetime type.


ps And a completely crazy idea to test it by writing

int shift=iBarShift(Symbol(),PERIOD_D1, (string)str_dat1);

But this is purely counting on mql4 optionality.

 
mila.com:

The bar graph is set correctly if the date is written like this

but it is not set if I write it like this

The date(str_dat1) is printed correctly.

What isthe reason?




The reason is that the iBarShift() function must pass the datetime variable type, while you pass a String type.

datetime  str_dat1=StringToTime(StringSubstr(str,0,10));// это дата
double str_b1=StringToDouble(StringSubstr(str,12,6)); // это значение

int shift=iBarShift(Symbol(),PERIOD_D1,str_dat1);

Range_Buffer[shift]=str_b1;

...

 
Alexey Viktorov:
It's better to convert received line to datetime type.

Thank you, puts up a bar graph.

I have a question how to build a histogram on all lines of the file.

I found in help, that the jump to the next line is FileSeek()

But I don't know how to skip to the next line.

 
mila.com:

Thank you, puts up a bar graph.

I have a question how to build a histogram on all lines of the file.

I found in help, that the jump to the next line is FileSeek()

But I don't know how to skip to the next line.

So far puts only one column


Help )

If you open the file before the loop and do not close it until the end, with each iteration of the loop the next line will be read. And you can close the file after the loop ends.

FileSeek() moves a pointer not to the next line but by the specified number of bytes from the beginning, from the end of the file, or from the current pointer position.

To move it correctly, you need to know how many bytes one line takes up in the written file.

 
mila.com:

Thank you, puts up a bar graph.

I have a question how to build a histogram on all lines of the file.

I found in help, that the jump to the next line is FileSeek()

But I don't know how to skip to the next line.

So far puts only one column


Help )

I gave you a link to an article that describes it all, with examples. Didn't seem to read it...
 
Sergey Gritsay:


The reason is that the iBarShift() function needs to pass the datetime variable type, while you pass the string type, try this

...

Thanks, I will do so.

 
Alexey Viktorov:

If you open the file before the loop and do not close it, the next line will be read with each iteration of the loop. And you can close the file after the end of the loop.


It works, thank you.

 
Artyom Trishkin:
I gave you a link to an article that describes it all with examples. Didn't seem to read it...

I read it, but I would never have guessed to open the file before the loop )

Probably didn't read it carefully )
Reason: