5001 | Too many opened files |

- docs.mql4.com
Uncompiled, untested code. Simply typed out.
void Writer(string body, string filename, bool ShouldBeEmptied){ int handle; string filepath = "/USDJPY/" + filename + ".txt"; while(true) { if(ShouldBeEmptied) { handle = FileOpen(filepath, FILE_WRITE|FILE_SHARE_READ|FILE_COMMON); if( handle != INVALID_HANDLE ) FileClose(handle); else Alert("Failed to empty the file" + GetLastError() + filename); } //This is for writing handle = FileOpen(filepath, FILE_READ|FILE_WRITE|FILE_TXT|FILE_COMMON|FILE_SHARE_READ|FILE_SHARE_WRITE); if( handle != INVALID_HANDLE ) { FileSeek(handle, 0, SEEK_END); FileWrite(handle, body); FileClose(handle); break; } else Alert("Failed to create file" + GetLastError()); } }
However, I still consider your code logic flawed. The code above is just to show that you were still processing the file even when the handle was invalid.
However, I still consider your code logic flawed. The code above is just to show that you were still processing the file even when the handle was invalid.
Thank you Fer,
I tested your code and unfortunately the same error still pops-up. However, I did a small modification which eventually fixed the issue.
I removed the alert method from the code; hence, the code will fail silently. It seems the constant calling for the Alert() method creates a bit of lag in the processing which prevents the FileClose() method from being called.
Now the issue is resolved.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello everyone, I've been struggling with the error for some time now, and I can't seem to make it work.
I'd appreciate if someone can help.
This is my code:
Obviously, it is writing function where at first clears the file and then writes to it.
The reason I'm putting it in while loop is to make sure it writes to the file since other EAs could be writing to the file in the same time.