Download MetaTrader 5
To add comments, please log in or register
Sell your applications via the Market. It is secure!
ayoublaser
99
ayoublaser 2015.06.17 22:10 

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 "

Alain Verleyen
Moderator
28563
Alain Verleyen 2015.06.18 07:07  
FileReadArray is intended to be used with BIN file, not CSV. Please read the documentation.
whroeder1
13613
whroeder1 2015.06.18 12:08  
Demos Stogios
184
Demos Stogios 2015.06.18 17:12  

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 

whroeder1
13613
whroeder1 2015.06.18 17:47  
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?
ayoublaser
99
ayoublaser 2015.06.18 19:06  
i want just write (time,ask,bid) and read last (time,ask,bid) like arbitrage ea
/
To add comments, please log in or register