OnTester() not writing the output to file.

 

Here is the code the I am trying to write during Optimization.

int file;
void OnTesterInit()
{
   file = FileOpen("testingFile.csv",FILE_WRITE|FILE_CSV|FILE_READ);
   if(file == INVALID_HANDLE)
   {
      Print("File Not Opened: ", GetLastError());
   }
   else
   {
     FileWrite(file,"rsi value");
     Print("I am in OnTesterInit()");
   }
   
}

void OnTesterDeinit()
{
      
   FileClose(file);
   Print("I am in OnTesterDEinit()");

}
void OnTesterPass()
{
   Print("I am in OnTesterPass()");
  
      
      

}
double OnTester()
{
   FileWrite(file,rsi_period,amount);
   
 Print("I am in OnTester()");
  
   
   return(amount);
}

I am using MQL5. I could not see anything apart from the string header that I have written in the OnTesterInit(). Kindly, suggest me what mistake  I am doing.

 
jafferwilson:

Here is the code the I am trying to write during Optimization.

I am using MQL5. I could not see anything apart from the string header that I have written in the OnTesterInit(). Kindly, suggest me what mistake  I am doing.

When you use OnTesterInit(), OnTesterDeinit(), and OnTesterPass():

OnTester() runs on a different thread. It doesn't have access to the file handle that these three will share.

What you can do to ensure OnTester() is firing: open a different file (using different file handle), write to it, and close from within OnTester() itself.

 
Anthony Garot:

When you use OnTesterInit(), OnTesterDeinit(), and OnTesterPass():

OnTester() runs on a different thread. It doesn't have access to the file handle that these three will share.

What you can do to ensure OnTester() is firing: open a different file (using different file handle), write to it, and close from within OnTester() itself.

Thank you for your enlightening sir. Please can you guide me in writing the correct file writer during optimization. Inshort, I didn't understood the examples already available, hence, can you guide me with a small snippet of code which will help. I will be grateful.