EA execution lost in nirvana after other EA recompiled

 

Hello,

i have 2 EAs.

EA "a" is attached to start and has an endless loop in init() and start()

EA "b" is not attached to start.

 

No i recompile EA "b" and then EA "a" loop isn't called any longer. Last message in console is Initialized.

This is only the case, if the chart has no ticks. If the chart has tick, the loop is called in function start() and starts again. 

 

int count=0;
void loop()
{
    while(!IsStopped())
    {
        count = count + 1;        
        Print("loop # ",count);
        Sleep(2000);
    }
    Print("end loop");
}

int init()
  {
//----
   Print("init recompile");
   loop();
   Print("init recompile 2 : NOT CALLED when EA b is recompiled");
 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
{
    Print("deinit recompile");
    return(0);
}
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
{
    // called on tick even after recompiling b. But sometimes you need a background EA in a non ore rare ticking chart
    // which should do his work reliable
    loop();

    return(0);
}
//+-----------------------------------------------------------------

 

I don't understand: Why recompilation "b" takes affect at all to "a". "b" is NOT attached , "a" is.

Why is "a" init() function is not completed when "b" recompiled ? So it seems function execution is simply stopped. 

This is the problem. It is some kind of uncomplete reentry. 

Thank you for help. 

 
chinaski:

Hello,

i have 2 EAs.

EA "a" is attached to start and has an endless loop in init() and start()

EA "b" is not attached to start.

init() must return after a couple of seconds . . .

https://www.mql5.com/en/forum/133615 

https://www.mql5.com/en/forum/128803/page3#373597 

 

Hello Raptor,

thank you for reply. Your links contain some suggestions to solve this but it seems no method is really reliable.

Just have look onto this code please. Then apply it to a chart which has no ticks. Then recompile another EA...

 

 

int init()
  {
   Print("init called");
   return(0);
  }
int deinit()
{
    Print("deinit called");
}
int start()
{
    Print("start called");
    return(0);
}

 

What you then see in the expert console is only: initialized

so neither "init called", nor "start called".

EA lost in nirvana just because another one - which is not attached - got recompiled.

What initialized means, if not init() called nor proceeded with start()...?

(If the chart ticks, no problem )

 
chinaski:

Hello Raptor,

thank you for reply. Your links contain some suggestions to solve this but it seems not method is really reliable.

Just have look onto this code. Then apply it to chart which has no ticks. Then recompile another EA...


(If the chart ticks, no problem )

You need ticks to call start()

I don't recompile code located in my MT4 folder structure unless I want MT4 to see a newly added EA/Indicator/Script. 

 

chinaski: It is regular behaviour. probably a bug, but it behaves like you described since I could remember.

Once you have a loop in your EA, and then perform ANY compilation in the MQL editor, the EA with the loop quits and does not start again. I have no workaround for it, I just keep it in my mind.

 
Ovo:

chinaski: It is regular behaviour. probably a bug, but it behaves like you described since I could remember.

Once you have a loop in your EA, and then perform ANY compilation in the MQL editor, the EA with the loop quits and does not start again. I have no workaround for it, I just keep it in my mind.


Hello yes,

i consider this as a bug. As raptor pointed out with the links, you can posta window message at the end of init(), to force a call of start().

Allow me to repeat: All this would be no problem, if the chart ticks. But you can't rely on this. So i look for a solution which allows periodical checks and this as most save as possible.

So possible recompilation should not stop this periodical check.

 

In the meantime, i found workaround and will just describe briefly.

The PostMessage does the trick but not called from within init(). This can fail. It works only sometimes.

 

mt4_chart_message = RegisterWindowMessage("MetaTrader4_Internal_Message");
PostMessage(mt4_chart_message ,2,1);

 

So what i did: I wrote a DLL. In this DLL i start a thread - not a timer! . This thread periodically calls PostMessage with registered message above.

The dll function which starts the DLL thread, is called in init(). 

And this solved my problen. You can apply to ticking chart, non ticking chart and recompile this EA or other, since you do the loop in

function start() all is ok. The periodical call of start() is ensured this way. 

 

chinaski

I would post the system message from another chart using a simple indicator, nevertheless your solution is more reliable.

And we still have the effect, that the affected EA does not even correctly finish the current method. But we cannot do much about it.