error 5004 and totale data=0

 

hi

i want to read the last line when i use FILEREADARRAY and FILEISLINEENDING it get a error 5004 open file and can't read data it just write totale data=0

this is the code:

//+------------------------------------------------------------------+
//|                                                      receved.mq4 |
//|                        Copyright 2015, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+

//--- input parameters
input string InpFileName="b";
input string InpDirectoryName="b";
//+------------------------------------------------------------------+
//| Structure for storing price data                                 |
//+------------------------------------------------------------------+
struct prices
  {
   datetime          date; // date
   double            bid;  // bid price
   double            ask;  // ask price
  };
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- structure array
   prices arr[];
//--- file path
   string path=InpDirectoryName+"//"+InpFileName;
//--- open the file
   ResetLastError();
   int file_handle=FileOpen(path,FILE_READ|FILE_CSV|FILE_ANSI,"\t");
   if(file_handle!=INVALID_HANDLE)
   if(FileIsLineEnding(file_handle))     ///// this is file is line ending
   
     {
      //--- read all data from the file to the array
      FileReadArray(file_handle,arr);
      //--- receive the array size
      int size=ArraySize(arr);
      //--- print data from the array
      for(int i=0;i<size;i++)
         Print("Date = ",arr[i].date," Bid = ",arr[i].bid," Ask = ",arr[i].ask);
      Print("Total data = ",size);
      //--- close the file
     
     FileClose(file_handle);
     Comment( arr[i].bid + " bid " + Bid + " Bid");
     }
   else
 
      Print("File open failed, error ",GetLastError());
  
}

so can you correct the error please ,or give me in outher expert to read " date , bid , ask "

 
FileReadArray is intended to be used with BIN file, not CSV. Please read the documentation.
 
 

hello,

OP, I see you have changed your original post from FILE_BIN to FILE_CSV, without a mention in your post for doing this. I believe  could be better to mark such critical changes, for everybody to be able to follow your topics. On to the topic and following on to your problems, please hang on to the following page regarding on how to properly use the function FileIsLineEnding()

https://www.mql5.com/en/forum/295 

best regards 

 
Demos: OP, I see you have changed your original post from FILE_BIN to FILE_CSV, without a mention in your post for doing this.
OP, did you also change the file writer?
 
i want just write (time,ask,bid) and read last (time,ask,bid) like arbitrage ea
Reason: