Gui/ CGraph on multiple charts not working (instances influencing each other)

 

Hello developers,

I am writing a simple EA with UI. Everything works well as long as I have that EA on one chart in the terminal. If I have it multipe times, the CGraph instances influnecing each other. 

Below I have a testcase: 

1) I load it on first chart with Input "TestcaseX". -> Everything is OK, e.g. Series are named "TestcaseX1", " TestcaseX2" ... 

2) I load it on second chart with Input "TestcaseY"

Now both instances show sometimes "TestcaseX", sometimes "TestcaseY". If I put one Window to FullScreen, the CGraph of the other window changes its size too.

What can be the reason? Is there any ID attribute etc I should set e.g. based on chart ID?

Thank you very much!

Christoph

#property copyright ""
#property link      ""
#property version   "1.00"

input string InpParameter = "Testcase";

#include <EasyAndFastGUI\WndEvents.mqh>
#include <EasyAndFastGUI\WndCreate.mqh>


class GUI : public CWndCreate {
private:
   CWindow           m_window;
   CGraph            m_graph1;
public:
   GUI();
   ~GUI();
   bool CreateGUI();
   void              OnInitEvent(void);
   void              OnDeinitEvent(const int reason);
   void              OnUpdate();
private:
   bool CreateGraph();
};

GUI::GUI() {}

GUI::~GUI() {}

bool GUI::CreateGUI(void) {

   if(!CWndCreate::CreateWindow(m_window,InpParameter,1,1,518,600,true,true,true,true))
      return(false);
   if(!CreateGraph())
      return(false);

   CWndEvents::CompletedGUI();
   return true;
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool GUI::CreateGraph() {
   m_graph1.MainPointer(m_window);
   m_graph1.AutoXResizeMode(true);
   m_graph1.AutoYResizeMode(true);
   m_graph1.AutoXResizeRightOffset(1);

   if(!m_graph1.CreateGraph(1,21))
      return(false);

   CGraphic *graph=m_graph1.GetGraphicPointer();

   graph.IndentLeft(-15);
   graph.IndentRight(-5);

   CAxis *x_axis=graph.XAxis();
   x_axis.AutoScale(false);
   x_axis.Min(0);
   x_axis.MinGrace(0.0);
   x_axis.MaxGrace(0.0);
   x_axis.MaxLabels(5);
   x_axis.NameSize(14);

   CAxis *y_axis=graph.YAxis();
   y_axis.AutoScale(true);
   y_axis.Min(0);
   y_axis.Max(10);
   y_axis.ValuesWidth(60);
   y_axis.Type(AXIS_TYPE_CUSTOM);

   OnUpdate();

   CWndContainer::AddToElementsArray(0,m_graph1);

   return true;
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void GUI::OnUpdate() {
//--- Exit if in the tester and not in the visualization mode
   if(::MQLInfoInteger(MQL_TESTER) && !::MQLInfoInteger(MQL_VISUAL_MODE))
      return;


   CWndEvents::ResetWindow();
   CColorGenerator m_generator;
   CGraphic *graph=m_graph1.GetGraphicPointer();
//--- Clear the graph
   int curves_total=graph.CurvesTotal();
   for(int i=curves_total-1; i>=0; i--)
      graph.CurveRemoveByIndex(i);

   // Dummy data
   double data[];

//--- Add the data
   for(int i=0; i<10; i++) {
      CCurve *curve=graph.CurveAdd(data,m_generator.Next(),CURVE_LINES,InpParameter + i);
   }

   CAxis *x_axis=graph.XAxis();
   x_axis.AutoScale(false);
   x_axis.Min(0);
   x_axis.Max(10);
   x_axis.MinGrace(0.0);
   x_axis.MaxGrace(0.1);
   x_axis.MaxLabels(5);
   x_axis.DefaultStep(1);
   x_axis.Name(InpParameter);
//--- Update the graph
   graph.CurvePlotAll();
   graph.Update();
}


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void GUI::OnInitEvent(void) {
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void GUI::OnDeinitEvent(const int reason) {
   CWndEvents::Destroy();
}



GUI *gui;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit() {

   gui = new GUI();
   if(!gui.CreateGUI()) {
      Print(__FUNCTION__, " > Failed to create graphical interface!");
      return(INIT_FAILED);
   }

   EventSetTimer(1);

   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason) {
   EventKillTimer();
   gui.OnDeinitEvent(reason);
   delete gui;
   gui = NULL;

}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick() {
//---

}
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer() {
//---

   gui.OnUpdate();
}
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam) {

   gui.ChartEvent(id, lparam, dparam, sparam);

}
//+------------------------------------------------------------------+