Continuous Logging

 
I've setup verbose logging on my EA for troubleshooting purposes. I'd like to track each iteration in the same file but when I do FileClose and reopen the file on the next iteration it clears the file. How do I write new lines in the same file, preferably text?
 
mixtermind:
I've setup verbose logging on my EA for troubleshooting purposes. I'd like to track each iteration in the same file but when I do FileClose and reopen the file on the next iteration it clears the file. How do I write new lines in the same file, preferably text?

https://docs.mql4.com/files/FileOpen:

'If FILE_WRITE does not combine with FILE_READ, a zero-length file will be opened. If even the file containd some data, they will be deleted. If there is a need to add data to an existing file, it must be opened using combination of FILE_READ | FILE_WRITE.'


You'll need to move the file pointer to the end of file with FileSeek() before appending the new data.

 
Irtron:

https://docs.mql4.com/files/FileOpen:

'If FILE_WRITE does not combine with FILE_READ, a zero-length file will be opened. If even the file containd some data, they will be deleted. If there is a need to add data to an existing file, it must be opened using combination of FILE_READ | FILE_WRITE.'


You'll need to move the file pointer to the end of file with FileSeek() before appending the new data.

This is what I have right now, I'm getting a FileWrite Error:


string textfile=StringConcatenate(Symbol(),"_logging.txt");
int logging=FileOpen(textfile,FILE_READ || FILE_WRITE);
if(count<0)
{
if(logging>0)
{
FileSeek(logging, 0, SEEK_END);
FileWrite(logging,"No open orders for pair..");
FileClose(logging);
}
else
{
Print("File issue");
}
}
else
{
if(logging>0)
{
FileSeek(logging, 0, SEEK_END);
FileWrite(logging,"Order in progress..");
FileClose(logging);
}
else
{
Print("File issue");
}
}

 

I figured it out. As usual just a slight type:


int logging=FileOpen(textfile,FILE_READ || FILE_WRITE);


needed to be


int logging=FileOpen(textfile,FILE_READ|FILE_WRITE);

Reason: