Should we run FileOpen() again after the file have changed by another EA?

 

Hi I want to use an EA on several charts (1 is master mode for writing to the file, others are slave mode for reading from the file)

 int OnInit()
  {
  if(InpMaster)
      Handle = FileOpen(InpFileName + ".csv", FILE_WRITE | FILE_SHARE_READ |FILE_CSV | FILE_COMMON, ",");
   else
      Handle = FileOpen(InpFileName + ".csv", FILE_READ | FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_CSV | FILE_COMMON, ",");
  }

After a new data writes by first master EA, other slave EAs can't read this new date.

OnTick()
  {
   FileReadString(Handle);
   Print(FileTell(Handle));
  }

This always print same number on slave EA.

Should I put FileOpen() in OnTick() for slave EA? Or problem is from somewhere else?

Thanks.

 
Farzad Sadeghishahrestanak:

Hi I want to use an EA on several charts (1 is master mode for writing to the file, others are slave mode for reading from the file)

After a new data writes by first master EA, other slave EAs can't read this new date.

This always print same number on slave EA.

Should I put FileOpen() in OnTick() for slave EA? Or problem is from somewhere else?

Thanks.

I think you may run into problems with this approach - leaving the file open for long periods could block other processes from accessing it.

Could be better to open, read then close. Alternatively you could take a copy of the file and allow read that to avoid blocking the writing process.

Depends how frequently you will write and for how long - you need to experiment

Reason: