EA - OnInit() not called after switching account

 

Hello everyone,

I'm still a bit of a beginner in the world of MQL5.

I have an mt5 desktop with two accounts set up (one for each forex pair I want to trade).

I've coded an expert advisor to execute my trades more easily. When I change the symbol or timframe, everything works perfectly as long as I stay in the same account : call of the void OnDeinit(const int reason) followed by the OnInit() function.

However, when I change account, I notice that only the OnDeinit(const int reason) function is called. The EA appears in the Expert List, but the  OnInit() function is not called. So my panel and other objects aren't displayed on the graph (they are deleted by the OnDeinit() function).

Is there any way of dealing with this? Or do I have to manually reset the EA on the chart each time I change account?

Thanks in advance for your help !

The code used in the functions :

int OnInit() {
//---
   printf("MyTradePosition => OnInit()");
   ChartSetInteger(ChartID(), CHART_EVENT_MOUSE_MOVE, true);

   if(!myControlsDialogTrade.Create(0,"Trade Position Manager",0,300,300,700,700))
      return(INIT_FAILED);
   
//--- run application
   myControlsDialogTrade.Run();
   
//---
   return(INIT_SUCCEEDED);
}


//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason) {
//---
   printf("MyTradePosition => OnDeInit() : " + reason);
   ChartSetInteger(ChartID(), CHART_EVENT_MOUSE_MOVE, false);
   myControlsDialogTrade.Destroy(reason);
  
}
 
Your topic has been moved to the section: Expert Advisors and Automated Trading — Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 
carrozzini:

Hello everyone,

I'm still a bit of a beginner in the world of MQL5.

I have an mt5 desktop with two accounts set up (one for each forex pair I want to trade).

I've coded an expert advisor to execute my trades more easily. When I change the symbol or timframe, everything works perfectly as long as I stay in the same account : call of the void OnDeinit(const int reason) followed by the OnInit() function.

However, when I change account, I notice that only the OnDeinit(const int reason) function is called. The EA appears in the Expert List, but the  OnInit() function is not called. So my panel and other objects aren't displayed on the graph (they are deleted by the OnDeinit() function).

Is there any way of dealing with this? Or do I have to manually reset the EA on the chart each time I change account?

Thanks in advance for your help !

The code used in the functions :

Can't be reproduced. Tested on build 3802 and 3930.

Show your log.