OnDeinit logging during optimization

 

It looks like  during optimization the tester agent does only call OnDeinit when the OnInit fails. If it passes, OnDeinit will not be called.

I have no idea why.


Sample EA to reproduce:

input int InpStart=1;
input int InpStop=2;

int OnInit()
  {
   Print("OnInit   Start: ",InpStart," Stop: ",InpStop);
   if(InpStop<=InpStart)
    {
      Print("Stop<=Start, fail");
      return INIT_FAILED;
    }
   return INIT_SUCCEEDED;
  }

void OnDeinit(const int reason)
  {
   Print("OnDeinit Start: ",InpStart," Stop: ",InpStop);
  }

void OnTick()
  {
  }


An optimization run with Start=(1,2) Stop=(1,2,3) yields this print output:

OnInit   Start: 1 Stop: 1
Stop<=Start, fail
OnDeinit Start: 1 Stop: 1

OnInit   Start: 1 Stop: 2

OnInit   Start: 1 Stop: 3

OnInit   Start: 2 Stop: 1
Stop<=Start, fail
OnDeinit Start: 2 Stop: 1

OnInit   Start: 2 Stop: 2
Stop<=Start, fail
OnDeinit Start: 2 Stop: 2

OnInit   Start: 2 Stop: 3


MQL5 documentation says about Deinit event:

"Before global variables are deinitialized and the program (Expert Advisor or custom indicator) is unloaded, the client terminal sends the Deinit event to the program. Deinit is also generated when the client terminal is closed, when a chart is closed, right before the security and/or timeframe is changed, at a successful program re-compilation, when input parameters are changed, and when account is changed."

"Deinit event is generated for EAs and indicators in the following cases:

  • before a re-initialization due to the change of a symbol or a chart period the mql5 program is attached to;
  • before a re-initialization due to the change of the inputs;
  • before unloading an mql5 program."

It's fairly obvious that the input parameters change on every pass, so why do I get a Deinit in only 3 of 6 passes?

 

I noticed the OnDeinit will be called, it's just the Print output that goes into the waste bin. Strange enough this happens only when OnInit passes, and when I add OnTester the Print output from OnDeinit is absent in any case.

Sorry if this was disturbing to any one. I'll leave it here for comments.

 
lippmaje:

I noticed the OnDeinit will be called, it's just the Print output that goes into the waste bin. Strange enough this happens only when OnInit passes, and when I add OnTester the Print output from OnDeinit is absent in any case.

Sorry if this was disturbing to any one. I'll leave it here for comments.

I was disturbed :-D

I knew the print was disabled during an optimization, so I was surprised you got some output when OnInit failed. Interesting to know.

 
Alain Verleyen:

I was disturbed :-D

I knew the print was disabled during an optimization, so I was surprised you got some output when OnInit failed. Interesting to know.

ok, sorry... I had some deallocation going wrong and was misled by this ouput.

2190 logs OnDeinit output (but only on fail), some prior builds do not log OnDeinit output at all - during optimization. Normal tests log everything.

 
lippmaje:

ok, sorry... I had some deallocation going wrong and was misled by this ouput.

2190 logs OnDeinit output (but only on fail), some prior builds do not log OnDeinit output at all - during optimization. Normal tests log everything.

No need to be sorry, it was useful :-) We learnt something.