Ontester printing and file writing.

 
I am trying to write test results to a file but cannot see error message and file is not created, the file gets created on my local machine but not on server and logs, alerts, etc do not show on either. I have full optimization logs checked.

double OnTester()
  {
   Print("test");
   Alert("test");
   Comment("test");
   MessageBox("test");

   int handle = FileOpen("DD",FILE_CSV|FILE_WRITE,'\t');
   if(handle != INVALID_HANDLE)
     {
      FileWrite(handle, "profit", TesterStatistics(STAT_PROFIT));
      return TesterStatistics(STAT_PROFIT);
     }
   else 
     {
      Print(GetLastError());
      Alert(GetLastError());
      Comment(GetLastError());
      MessageBox((string)GetLastError());
      return 0;
     }
  }
 
laclance:
I am trying to write test results to a file but cannot see error message and file is not created, the file gets created on my local machine but not on server and logs, alerts, etc do not show on either. I have full optimization logs checked.

You need a FileClose() statement - try this:

 FileWrite(handle, "profit", TesterStatistis(STAT_PROFIT));
 FileClose(handle);
 return TesterStatistics(STAT_PROFIT);
 
R4tna C #:


thank you sorry but i do have a FileClose() statement already but is there no way to see the error? Print, Alert, Commment and MessageBox do not work in the OnTester function.

 
laclance #:


thank you sorry but i do have a FileClose() statement already but is there no way to see the error? Print, Alert, Commment and MessageBox do not work in the OnTester function.

I don't use the OnTester function so cannot say - I suggest you write the code into a script (using OnTick or Onstart) and make it work in isolation, and then you can put it back into your main code base.

But equally why call the FileClose() in another place? Close the file immediately before the return()- re-open later if you need to. 

Reason: