backtesting file write

 

Dear All,

  I tried to write a log file in backtesting. The log file function records the account balance.  When I placed the file write function at void OnTick(), I got the same value in the log file. However, during the backtesting, the account balance were changed in many times.  The log file should have many different values.

 Does anyone know where is the root cause?  

  here is my code.  Thank you very much.

void OnTick()

  {

   ExtExpert.OnTick();

   double balance=AccountInfoDouble(ACCOUNT_BALANCE);

   int file_handle=FileOpen("Data"+"//"+"myEA_LogFile.csv",FILE_READ|FILE_WRITE|FILE_CSV|FILE_ANSI); 

   if(file_handle==INVALID_HANDLE)

      Print("Error opening rep-file: "+"myEA_LogFile.csv");

   bool flag=FileSeek(file_handle,0,SEEK_END);

   Print("FileSeek: ", flag);

   uint res=FileWriteString( file_handle, DoubleToString(balance)+" from void OnTimer()\r\n");

   Print("FileWrite: ", res);

   FileFlush( file_handle );

   FileClose(file_handle); 


  } 
Reason: