Download MetaTrader 5
To add comments, please log in or register
Examine the Top MetaTrader 5 signals. Choose the best one and subscribe to it!
Route206
211
Route206 2015.11.19 11:33 

I have my EA protected for a crash by means of a file (crash.bin).

While running the EA it writes the crash.bin file every 30s, and it holds important data for when having to recover. If the EA is removed on purpose then the crash.bin file is deleted as part of the OnDeInit() routine, if MT4 crashes however, the OnInit() checks the existence of the crash.bin upon startup and when it exists, it picks it up, reads it and starts recovering. To test it, i crash MT4 intentionally using TaskManager (taskmgr.exe -->MetaTrader-->End task) and then restarting MT4.

All worked flawlessly until... build 910 (12nov15)!!  Now, when crashing MT4 using procedure mentioned above, MT4 somehow manages to delete the crash.bin file.... That is completely new. And upon restarting MT4 after such 'crash', it starts anew assuming all is well (as if the EA was brought down correctly). So no recovery mode and now all is starting to screw up. I'm sure that when i cut the power, the behavior will be again different, but not all crashes are power cuts. 

any thoughts or suggestions how i can circumvent this issue?

void OnInit()
 {
  if(!FileIsExist("crash.bin"))
     {
      <Normal Routines>
     }
   else
     {
      int bla1=FileOpen("crash.bin",FILE_READ|FILE_BIN);
      if(bla1!=INVALID_HANDLE)
        {
         FileReadArray(bla1,crash);
         FileClose(bla1);
         <Crash Routines>
        }
      else
        {
         <fileopen issue, ExpertRemove()>
        }
     }
//----

void OnDeinit(const int reason)
 {
   if(FileDelete("crash.bin"))
      Alert("file crash.bin deleted");
   <other stuff>
 }
//---

void OnTimer()
  {
   int bla1=FileOpen("crash.bin",FILE_WRITE|FILE_BIN);
   if(bla1!=INVALID_HANDLE)
     {
      if(FileWriteArray(bla1,crash_data)==0)
        {
         Alert("Error writing file",GetLastError());
        }
      FileClose(bla1);
     }
  }
Carl Schreiber
5954
Carl Schreiber 2015.11.19 16:26  

I experienced something similar!

Last Sunday I performed the Windows update and the requested restart killed beside others appl. the running mt4 and the editor.

After the restart of the pc at least two of my indicator source files were empty, completely white, but opened in the editor - really strange.

Fortunately I have saved everything and I could get back the code!

Gooly

Route206
211
Route206 2015.11.20 14:55  

Not quite the problem i'm having, but annoying none the less.

Anybody any recent experience with Crashing EAs and how to recover? 

ThreadHandle
105
ThreadHandle 2015.11.20 16:06  
Maybe your unlucky enough to catch the text stream during the close corrupting the file? Dont know if it would delete it via some other windows procedure? Like if stream != EOF delete file. Though writing to a file is usually rather fast. My only other guess is that maybe metatrader reverts its most recent stack history or such to auto-correct the crash (as if in native mode the code that caused it to crash was meta trader based and its clearing its cache) type of scenario? I dont know.
Route206
211
Route206 2015.11.23 13:46  
thanks - i have it happening all the time, so crashing while writing is possible, but not all the time i'd say. As for the rest, could be true also, then again i'm looking for some more definitive answers and/or someone experiencing the same problems.
/
To add comments, please log in or register