Can i check if a file is already open?

 

Hello, can i check if a file is already open before i use FileOpen() function?

I need that because i think i get often error messages at moment when i have my EA on more then one charts and when from every chart the EA try to open and write into the same file.

 
What error message do you get? You can find error codes here.
 

I get the error message file does not exits.

you can try yourself, put the same ea on 2 charts and open the same file with ea then the error must come.

somethink that can see if the file is already open would be helpfull against this error.

 

Here.... You'll want to post the code you're having problems with for other people to help you instead of telling them to program and test what you're having problems with. Documentations.

void start(){
    int Handle=FileOpen(WindowExpertName()+".csv",FILE_CSV|FILE_READ|FILE_WRITE,',');
    if(Handle==(-1)){ int GLE=GetLastError(); Alert("Error_Opening_File="+GLE);}
    FileSeek(Handle,0,SEEK_END);
    FileWrite(Handle, Symbol(), Close[0], Open[0], High[0], Low[0], TimeToStr(TimeCurrent()));
    FileClose(Handle);
}
 
PlanandTrade:

I get the error message file does not exits.

you can try yourself, put the same ea on 2 charts and open the same file with ea then the error must come.

somethink that can see if the file is already open would be helpfull against this error.


Don't you think a solution could be that on one chart the EA is writing to the file

EA's on other charts have only to read the file ?? you only have to check if file exists in that case we read data

if file not exist we download.....

if you want to upload the file then do it on one chart only

 
deVries:


Don't you think a solution could be that on one chart the EA is writing to the file

EA's on other charts have only to read the file ?? you only have to check if file exists in that case we read data

if file not exist we download.....

if you want to upload the file then do it on one chart only


I think that idea from you can be usefull, thank you.
 

I recommend to you and all topic visitors to check the result of writing the code by these extra Flags:


Handle  =  FileOpen("FileName.txt",FILE_TXT|FILE_WRITE|FILE_READ|FILE_SHARE_READ|FILE_SHARE_WRITE);