[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 470

 
iliaalyoshin >>:


Разные приёмы? Какие, например?

if (NormalizeDouble(a, 4)==NormalizeDouble(b, 4)) { ... }

 
sergeev >>:

if (NormalizeDouble(a, 4)==NormalizeDouble(b, 4)) { ... }


I tried that too, and just in case, instead of Digits I wrote 4, then 5, then 6... Doesn't work!
 


Thank you! Indeed, the article is very informative. But I didn't find the bool CompareDoubles function in MetaEditor...
 


Or perhaps I don't quite understand, or rather don't understand what a library is at all?
 
iliaalyoshin писал(а) >>


Or perhaps I don't quite understand, or rather don't understand what a library is at all?


A function for comparing real numbers
//+------------------------------------------------------------------+
//| correct comparison of 2 doubles                                  |
//+------------------------------------------------------------------+
bool CompareDoubles(double number1,double number2)
  {
   if(NormalizeDouble(number1-number2,8)==0) return(true);
   else return(false);
  }
 
Comrade pros, help me out.
Could you please tell me what to do here?

I want to read numbers from a file into the corresponding arrays.

The numbers in the file are as follows: 1.2121;1.2323;1.3434;1.4545

I prepare the following arrays for them: double s1[], s2[], r1[], r2[]

at the stage of initialization I read as follows

k=0;
//----------------------------------------------

Handle=FileOpen(File_Name,FILE_CSV|FILE_READ,";");// Открытие файла
if(Handle<0) // Неудача при открытии файла
{
if(GetLastError()==4103) // Если файла не существует,..
Alert("Нет файла с именем ",File_Name);//.. извещаем трейдера
else // При любой другой ошибке..
Alert("Ошибка при открытии файла ",File_Name);//..такое сообщ
PlaySound("Bzrrr.wav"); // Звуковое сопровождение
return;
}
while(FileIsEnding(Handle)==false) // До тех пор, пока файловый ..
{ // ..указатель не в конце файла
//--------------------------------------------------------- 5 --
S_1 =StrToDouble(FileReadString(Handle));//
R_1 =StrToDouble(FileReadString(Handle));
S_2 =StrToDouble(FileReadString(Handle));
R_2 =StrToDouble(FileReadString(Handle));
s1[k]=S1; s2[k]=S_2; r1[k]=R_1; r2[k]=R_2;
k=k+1;
if(FileIsEnding(Handle)==true) // Файловый указатель в конце
break; // Выход из чтения и рисования
//--------------------------------------------------------- 6 --
}
FileClose( Handle ); // Закрываем файл
PlaySound("bulk.wav"); // Звуковое сопровождение

but, unfortunately, the arrays are not filled in...

Advise how to be here....
 

Посоветуйте, как тут быть....

First, in csv files, elements are separated by "," not ";"
Second, you must fill arrays with the first element of each file line, because you first retrieve the entire line with FileReadString, then convert it to a single real number, and the next FileRead command already works on the next line of the file.

You can arrange reading in the following way:

for(;;) {
str=FileReadString(Handle);
s1[k] =StrToDouble(StringSubstr(str,0,6));
s2[k] =StrToDouble(StringSubstr(str,7,6));
r1[k] =StrToDouble(StringSubstr(str,14,6));
r2[k] =StrToDouble(StringSubstr(str,21,6));
k++;
if(FileIsEnding(Handle)) break;
}


It should work... but not sure :)

 
Axmed писал(а) >>

Firstly, in csv files the elements are separated by "," not ";".
Secondly, arrays must be filled with the first element of each file string, because you first retrieve the entire string with FileReadString command, then convert the entire string to a single real number, and the next command FileRead already works with the next line of the file.

You can organise reading this way:

for(;;) {
str=FileReadString(Handle);
s1[k] =StrToDouble(StringSubstr(str,0,6));
s2[k] =StrToDouble(StringSubstr(str,7,6));
r1[k] =StrToDouble(StringSubstr(str,14,6));
r2[k] =StrToDouble(StringSubstr(str,21,6));
k++;
if(FileIsEnding(Handle)) break;
}


Should work... but not sure :)


The default delimiter is ";", although you can use any delimiter.
 
Axmed писал(а) >>

You're writing something wrong...

 
Vinin писал(а) >>


The default delimiter is ";", though you can use any.


CSV - Comma Separated Values. The "," is the default delimiter. Separating with ";" is much less common, and I'm not sure it's supported at all in MQL4.

You're writing something wrong...

What exactly don't you like about what I write...?

Reason: