Difference between OnDeinit() and deinit() ?

 

Hello all 

I am working on an EA and I noticed when I am using OnDeinit() in my EA , it causes the EA to shutdown by timeout upon manual removal of the EA from chart and sometimes it automatically restarts the Mt4 terminal
whereas when I am using the deinit() function in the same EA everything works fine.

why both of these functions have somewhat different behavior.

I know both these functions are called when the EA is deInitialized , and OnDeinit() is supposed to be the newer format but why does the EA behaves abnormally for OnDeinit() and not for the deinit() ?

can somebody please shed some light on this matter ?

PS: I dont have any code inside the deinitialization code block in both cases :

void deinit(const int reason)
  {
        // this code block works normally 
  }


void OnDeinit(const int reason)
  {
        // this code block freezes the MT4 until EA shuts down by timeout OR the MT4 gets automatically restarted. 
  }
 
ST_ Rhodes:

Hello all 

I am working on an EA and I noticed when I am using OnDeinit() in my EA , it causes the EA to shutdown by timeout upon manual removal of the EA from chart and sometimes it automatically restarts the Mt4 terminal
whereas when I am using the deinit() function in the same EA everything works fine.

why both of these functions have somewhat different behavior.

I know both these functions are called when the EA is deInitialized , and OnDeinit() is supposed to be the newer format but why does the EA behaves abnormally for OnDeinit() and not for the deinit() ?

can somebody please shed some light on this matter ?

PS: I dont have any code inside the deinitialization code block in both cases :

You should use OnDeinit it replaced deinit a long time ago.

make sure you have the latest version of MT4 and recompile.

 
ST_ Rhodes: I am working on an EA and I noticed when I am using OnDeinit() in my EA , it causes the EA to shutdown by timeout upon manual removal of the EA from chart and sometimes it automatically restarts the Mt4 terminal whereas when I am using the deinit() function in the same EA everything works fine.


why both of these functions have somewhat different behavior.

I know both these functions are called when the EA is deInitialized , and OnDeinit() is supposed to be the newer format but why does the EA behaves abnormally for OnDeinit() and not for the deinit() ?

can somebody please shed some light on this matter ?

PS: I dont have any code inside the deinitialization code block in both cases :

"deinit" is the old style code of MQL4 of yester-year and could be considered almost decrepit, while OnDeinit is the modern style MQL4+ code which makes it more compatible with MQL5.

However, your "freezing" is probably because your code (in the other sections) is probably not following the correct functionality of a more modern and stricter MQL4+ and is thus blocking the de-initialisation procedure.

 

You should stop using the old event handlers (init, start, deinit) and IndicatorCounted() and start using new event handlers (OnInit, OnTick/OnCalculate, OnDeinit).
          Event Handling Functions - MQL4 Reference
          How to do your lookbacks correctly - MQL4 programming forum #9-14 & #19 (2016)