OnTester() not writing the output to file.

To add comments, please log in or register
jaffer wilson
914
jaffer wilson  

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.

Anthony Garot
1933
Anthony Garot  
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.

jaffer wilson
914
jaffer wilson  
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.

To add comments, please log in or register