Share Writing Into a File

 

I have this project in which I need to execute two trades instantly among two different brokers. I use the native MQL4 function such as FileOpen and FileWrite to communicate the orders between brokers.

What I had an issue with is that some orders will not write to the file if it was previously opened without OrderClose() being called.

This is causing a lot of frustration to me for a month now. Can someone advise me on the best practices for share writing within mql4 environment. 

This is my code for writing:


   int handle;

   //This is for writing

   handle = FileOpen("filename.txt", 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);

      FileCloandle);

      Print("File created.");         

   }else{

      Print("Failed to create file" + GetLastError());   

   }


This is for reading:


   string text = NULL;

   int handle = FileOpen("filename.txt", FILE_READ|FILE_TXT|FILE_COMMON|FILE_SHARE_READ|FILE_SHARE_WRITE);

   if(handle != INVALID_HANDLE){

      text = FileReadString(handle, 0);

   }   

   FileClose(handle);
 

Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
          General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
Next time, post in the correct place. The moderators will likely move this thread there soon.