FileClose doesn't seem to close switch handle value to 0
FileClose doesn't seem to close switch handle value to 0
Alert(signals); // the value is always 1 indicating the file is WAS open while(loopcount<10) { if(signals>0) { Alert(signals,GetLastError()); // signal value always 1
Why would you expect your int to suddenly change?signals=FileOpen("signals.bin",FILE_BIN|FILE_READ|FILE_WRITE);
What are Function return values ? How do I use them ? - MQL4 forum Did the file open? You don't check. It failed if another thread has the file open.
Check, wait, and retry. Or use a mutex.
Thanks for your input! The file can be opened and as I was playing around I added the cycle break to the code. Now it seems it will write into the file first currency information but not the second one which gets an error of 4002 from somewhere (Array index is out of range.). Here's the code I tested.
if(isNewBar()) { int loopcount=1; int positsioonid=FileOpen("positsioonid.bin",FILE_BIN|FILE_READ); FileClose(positsioonid); //Alert(positsioonid); while(loopcount<10) { if(positsioonid>0) { Alert(positsioonid,GetLastError()); Sleep(1000); loopcount++; } else { Alert("positsioonid=0"); positsioonid=FileOpen("positsioonid.bin",FILE_BIN|FILE_READ|FILE_WRITE); FileSeek(positsioonid,0,SEEK_END); FileWriteDouble(positsioonid,sorting1,DOUBLE_VALUE); FileSeek(positsioonid,0,SEEK_END); FileWriteDouble(positsioonid,sorting2,DOUBLE_VALUE); FileClose(positsioonid); break; } break; } }
Hi all,
I have a working function that identifies whether the graph has a new bar or not in some time frame. After the new bar is made I want to write to the same file from several programs (currencies) with all using similar script (program). The problem is that when two different currency pairs try to write something to the file only one of them will add its info and the other one (probably because the file was opened by another currency) doesn't add its information. So i tried to make a workaround test where I would check whether the handle is 0 or 1 and based on that either wait or write the info to the file. Here's the script, I'm trying to make work. Thanks for all your ideas/input in advance!