Expert Advisor on Remove, Closing chart

 

I have written an expert advisor (admittedly first attempt) which uses a canvas as well as a cAppDialog to simulate the TradeView trade visualiser and it works great.

However, when removing the EA using the "Expert List" option on MT5, it also closes the chart to which the EA is bound.

I am clearly missing something basic in the logic and would appreciate guidance.

The code is pretty long but the Init and DeInit functions are as follows but do nothing special:

int OnInit()
  {
//--- Enabling events of mouse movements on the chart window
   ChartSetInteger(0, CHART_EVENT_MOUSE_MOVE, 1);
   buttons[0] = new CChartObjectButton;
   buttons[1] = new CChartObjectButton;
   buttons[0].Create(0, "goLong", 0, 10, 200, 90, 35);
   buttons[1].Create(0, "goShort", 0, 120, 200, 90, 35);
   buttons[0].BackColor(clrGreen);
   buttons[0].Color(clrWhite);
   buttons[1].BackColor(clrRed);
   buttons[1].Color(clrWhite);
   buttons[0].Description("Long");
   buttons[1].Description("Short");
   if(!ve.Visualize(vz)) //ve inherits cAppDialog and will only show when the canvas is double clicked
      return(INIT_FAILED);
//--- run application
   ve.Run();
   ve.Hide();
   EventSetTimer(1);
   ChartRedraw();
   return(INIT_SUCCEEDED);
  }

void OnDeinit(const int reason)
  {
   buttons[0].Delete();
   buttons[1].Delete();
   ve.Destroy(0);
   ChartRedraw();
  }

Documentation on MQL5: Standard Library / Graphic Objects / Control Objects / CChartObjectButton
Documentation on MQL5: Standard Library / Graphic Objects / Control Objects / CChartObjectButton
  • www.mql5.com
CChartObjectButton - Control Objects - Graphic Objects - Standard Library - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

I have edited your post. In future please use the CODE button when you insert code.

Code button in editor

MQL5.community - User Memo
MQL5.community - User Memo
  • www.mql5.com
You have just registered and most likely you have questions such as, "How do I insert a picture to my a message?" "How do I format my MQL5 source code?" "Where are my personal messages kept?" You may have many other questions. In this article, we have prepared some hands-on tips that will help you get accustomed in MQL5.community and take full advantage of its available features.
 
Fernando Carreiro #:

I have edited your post. In future please use the CODE button when you insert code.

Many thanks. Just as an update - not sure how it fixed the problem but I added a button to remove the Expert using the ExpertRemove() function and that did not close the chart, and oddly though, ever since then, removing the EA using MT5 Expert List dialog also does not remove the chart. I realise this does not help anyone but just an update on my process. As a guess, it may be that the debugger did not clean up some condition so it could be that there was no real problem to start with.