Problems looping through text file.

 

 Hello ...

I am trying to generate bars with data from another program.

First step is to read a text file located in \files\ES3.txt, with the content below.

The file reads fine, indicated by the comment "Success", however, when I try to loop through the lines it appears the code created an infinite loop. Is there anything I am doing wrong here?

When I get each line, I want to parse out the values to create bars.

Thanks for any suggestion. 

 

ResetLastError();
   int n=0;
   string line="Empty";
   int file_handle=FileOpen("ES3.txt",FILE_SHARE_READ|FILE_TXT);
   if(file_handle!=INVALID_HANDLE){
      Comment("Success !");
      while(!FileIsEnding(file_handle)){
         line=FileReadString(file_handle);
          n++;
      }
      FileClose(file_handle);
     }
   else Comment("Failed to open file",GetLastError());
   Comment(n);
   FileClose(file_handle);
Files:
ES3.txt  14 kb
 

Here is your fault. 

int file_handle=FileOpen("ES3.txt",FILE_READ|FILE_TXT|FILE_ANSI);

https://www.mql5.com/en/docs/constants/io_constants/codepageusage

https://www.mql5.com/en/docs/constants/io_constants/fileflags 

 

int n=0;
   string line="Empty";  
   ResetLastError();
   int file_handle=FileOpen("ES3.txt",FILE_READ|FILE_TXT|FILE_ANSI);
   if(file_handle!=INVALID_HANDLE){
     
      Comment("Success !");
      while(!FileIsEnding(file_handle)){
         line=FileReadString(file_handle);
         n++;
      }
      FileClose(file_handle);
     }
   else Comment("Failed to open file",GetLastError());
  
   Comment(n);
   FileClose(file_handle);
Documentation on MQL5: Standard Constants, Enumerations and Structures / Input/Output Constants / Use of a Codepage
Documentation on MQL5: Standard Constants, Enumerations and Structures / Input/Output Constants / Use of a Codepage
  • www.mql5.com
Standard Constants, Enumerations and Structures / Input/Output Constants / Use of a Codepage - Documentation on MQL5
Reason: