Download MetaTrader 5

File Write always write over first line

To add comments, please log in or register
davidmesguerra
28
davidmesguerra  
Hi, that's the thing, I've been writing a csv file but my expert always write on the first file line, there is part of my code:
void saveLog(int _index){
   string file_name=Symbol()+"-LOG\\["+Year()+"-"+Month()+"-"+Day()+"].csv";
   int file_handle=FileOpen(file_name,FILE_CSV|FILE_READ|FILE_WRITE,",");
   if(file_handle!=INVALID_HANDLE){
      FileWrite(
         file_handle,
         logdata_str[_index][0],
         logdata_str[_index][1],
         logdata_str[_index][5]
      );
      FileSeek(file_handle, 0, SEEK_END);
      FileClose(file_handle);
   }
   else{
      Print(GetLastError());
   }
}
I've been calling this method at the end of OnTick() function and it executes every time that _index increment in 1, but my csv file just have 1 row, no mather the _index value

Thanks for your help.
Keith Watford
Moderator
10536
Keith Watford  
Put the FileSeek() before FileWrite()
To add comments, please log in or register