EA on multiple charts trying to open the same file simultaneously

 

Hello

I have a 28 charts loaded with the same EA, and AutoTrading off.  The EA, on init, opens a file, populates an array from the contents, and close the filehandle.

If I click AutoTrade on, all the EAs jump into action at the same time.  They all try and access the file at the same time.  I know Windows does not allow different programs to open a file resource if another already is, but these are all operating under the same program (I think MT4 is 32 bit and single threaded) so how should I go about avoiding the problems which I'm getting where some of the arrays don't get the contents of the file applied.  I'm thinking of enlarging the function so that it knows which symbol it is on and delays the read by a number of seconds so that I can setup a 28 chart strategy without problems.

 
strontiumDog:

Hello

I have a 28 charts loaded with the same EA, and AutoTrading off.  The EA, on init, opens a file, populates an array from the contents, and close the filehandle.

If I click AutoTrade on, all the EAs jump into action at the same time.  They all try and access the file at the same time.  I know Windows does not allow different programs to open a file resource if another already is, but these are all operating under the same program (I think MT4 is 32 bit and single threaded) so how should I go about avoiding the problems which I'm getting where some of the arrays don't get the contents of the file applied.  I'm thinking of enlarging the function so that it knows which symbol it is on and delays the read by a number of seconds so that I can setup a 28 chart strategy without problems.


Not true, you can access a file with multiple programs if the file is open in sharing_mode.

 
angevoyageur: Not true, you can access a file with multiple programs if the file is open in sharing_mode.
  1. Open read only/shared
  2. Use a mutex
Reason: