Take a double from .txt file

 

Hello, I would like to know if there must be a change in a line in this code (https://www.mql5.com/en/forum/117683 ).  I would like to change the integer number to double, and how can I call a number from that file later in my EA, if I do not know its position, and I would like that number to be close to one I want.And this block should be on init or where should i place it?


eg: Numbers on .txt: (0.5 1.9 3.6 20.5)

      Number I want: 3.5

And I would like after 3.5 to be followed by 3.6 from my txt. Is it possible?

int handle, space,i,pos[];
string str,word;
handle=FileOpen("test.txt",FILE_READ);//try to open file
if(handle==-1)return(0);// if not exist
if(FileSize(handle)==0){FileClose(handle); return(0); } //if empty
while(!FileIsEnding(handle))//read file to the end by paragraph. if you have only one string, omit it
   {
   str=FileReadString(handle);//read one paragraph to the string variable
   if(str!="")//if string not empty
      {
      space=0;
      for(i=0;i<StringLen(str);i++)
         {
         if(StringGetChar(str,i)==32)// look for spaces (32) only
            {
            space++;//yes, we found one more space
            ArrayResize(pos,space);//increase array
            pos[space-1]=i;//write the number of space position to array
            }
         }//now we have array with numbers of positions of all spaces
      for(i=0;i<=space;i++)//start to read elements of string
         {
         if(i==0) word=StringSubstr(str,0,pos[0]);//the first element of string (in your case it is 100)
         else word=StringSubstr(str,pos[i-1]+1,pos[i]-pos[i-1]-1);//the rest of elements
         //analize your word. I mean you can calculate (StrToInteger or StrToDouble), print or collect to another array
          }
       }
   }
FileClose(handle); //close file



 

and after i am using

double var=StrToDouble(word);

but still ... something there is wrong

 
darchii: but still ... something there is wrong
  1. There are no mind readers here. "is wrong" is meaningless.
  2. Add Print statements dumping the values of your variables and track it down.
 
  1. I didn't ask you what the problem is. If you knew that you wouldn't be posting. I asked you to describe it. "Is wrong" doesn't describe anything.
  2. Unmatched data error is irrelevant - your EA is not yet running. Use this
  3. What you thought is irrelevant. Add the print statements and find out what it's doing and why.
 
WHRoeder:
  1. I didn't ask you what the problem is. If you knew that you wouldn't be posting. I asked you to describe it. "Is wrong" doesn't describe anything.
  2. Unmatched data error is irrelevant - your EA is not yet running. Use this
  3. What you thought is irrelevant. Add the print statements and find out what it's doing and why.

I solve it partially ... because while I run this block with a print(var) it will print all the value from my .csv ... but now i have to see if it will work in my EA.