Adding additional information to an existing file created by FileWrite()

 

Morning all

I have a FileWrite() function which works perfectly, however, I am wanting to add attentional information in new columns appended to the end of an existing spreadsheet, created by the FileWrite() function.

Is there a way in which to achieve this?

All the best, 

Pip Pip!

if(/*EA Opens order*/){

	int file_handle = FileOpen(.....);

		FileSeek(<file_handle>, 0, SEEK_END);        
		
			FileWrite(..);

}

if(/*EA Closes Order via OrderSelect() Function*/){

        FileOpen(//Opens File Above); 

		FileSeek(<file handle>, 0, SEEK_END);  

                	FileWrite(....) //Write information to existing file by adding columns to existing file.

}
Using spreadsheets to build trading strategies
Using spreadsheets to build trading strategies
  • www.mql5.com
The article describes the basic principles and methods that allow you to analyze any strategy using spreadsheets (Excel, Calc, Google). The obtained results are compared with MetaTrader 5 tester.
 
TheHonestPrussian: Is there a way in which to achieve this?
  1. Perhaps you should read the manual. FileSeek does not take a file name.
       How To Ask Questions The Smart Way. (2004)
          How To Interpret Answers.
             RTFM and STFW: How To Tell You've Seriously Screwed Up.

  2. Append to the file.
              Write to File Syntax - MQL4 programming forum #4 (2019)

 

To add text to a specific row, you might have to read the entire file, find the line, append it and then rewrite the entire file.

Something like this?

string line="";
int lineno=0;
string txt="";

int file0=FileOpen("test0.txt",FILE_READ|FILE_TXT);
 while(!FileIsEnding(file0)){
  line=FileReadString(file0);
  if(lineno==2)
   line=StringConcatenate(line," extra info");
  
  txt=StringConcatenate(txt,line,"\n");
  lineno++;
 }
 FileClose(file0);
 
 file0=FileOpen("test0.txt",FILE_WRITE|FILE_TXT);
 FileWrite(file0,txt);
 FileClose(file0);