Questions from Beginners MQL4 MT4 MetaTrader 4 - page 172

 

Hello.

Please advise how to do this correctly.

There is a global collection of objects:

CArrayObj array;

There is an additional class where a lot of calculations are done and this includes creating objects and adding them to the collection:

class CCheck : public CArrayObj
  {
  }
bool CCheck::SomeMethod(void)
  {
   CSample *sample_object=new CSample();
   array.Add(sample_object);
  }

This additional object of CCheck class I create regularly in a loop. But I can't destroy it, because I need CSample objects in the array collection. If I destroy CCheck, I also lose the sample_objects in the array.

I now shove these CCheck objects to another array of garbage objects, which I clear when I don't need the corresponding objects in the array anymore. But I get out of memory error because I have to keep lots of heavy CCheck objects in the array. But I don't need whole object. I just need created in it objects of CSample. Could you please tell me how to do it right, so I can save only CSample object and delete CCheck one. I can't figure it out.

The code is like this:

CArrayObj array;
CArrayObj gargage_array;

void OnTick()
  {
   for(int i=0;i<total;i++)
     {
      CCheck *check_obj=new CCheck();
      check_obj.Check();
      garbage_array.Add(check_obj);
     }
   if(..)
     {
      array.Clear();
      garbage_array.Clear();
     }
  }

class CCheck : public CArrayObj
  {
   public:
   void         Check(void);
   protected:
   bool         SomeMethod(void);
  };
void CCheck::Check(void)
  {
   ...
   SomeMethod();
  }
bool CCheck::SomeMethod(void)
  {
   CSample *sample_object=new CSample();
   array.Add(sample_object);
  }

class CSample : public CObject
  {
  };
 

The solution has been on a forum somewhere, but I can't find the answer.

Who has found an "antidote" against this:

Standard panel

The code is standard:

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {   
//--- create application dialog
      if(!ExtDialog.Create(0,"For Example ",0,40,40,760,400))
      //return(INIT_FAILED);
      return(false);            // исключительно для того, чтобы продемонстрировать наложение "панелей"
//---
//--- run application
   ExtDialog.Run();
//--- succeed
//-----
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy dialog
   ExtDialog.Destroy(reason);
//---
  }
//+------------------------------------------------------------------+
//| Expert chart event function                                      |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,         // event ID  
                  const long& lparam,   // event parameter of the long type
                  const double& dparam, // event parameter of the double type
                  const string& sparam) // event parameter of the string type
  {
   ExtDialog.ChartEvent(id,lparam,dparam,sparam);
   ChartRedraw();
  }

The essence: Expert Advisor crashes when switching from one timeframe to another. In mt5 there is no such a problem.

Is there a solution? Or it is better to forget about the Panels in mt4 :)

 
Vjacheslav Lapaev:

The solution was somewhere already on the forum, but I can't find the answer.

Who found "antidote" against this:


The code is standard:

The essence: Expert Advisor crashes when I switch from one timeframe to another. In mt5 there is no such a problem.

Is there a solution? Or it is better to forget about the Panels in mt4 :)

Maybe someone could use it. Bottom line, there was an Expert, saved it as an Indicator, everything works. I mean the code for the Panel.

 

Good afternoon!

I thought it was possible to just print an array, but I can't remember and can't find how to do it. How?

 
Nauris Zukas:

Good afternoon!

I thought it was possible to just print an array, but I can't remember and can't find how to do it. How?

ArrayPrint
 
Vladislav Andruschenko:
ArrayPrint

Ah, it was in MQL5, thanks clearly!

 

I don't understand what you need to do to fix it:

4030 is "chart not responding".

Yesterday it worked :( The only difference is that MT5 is being optimised in parallel (also uses timer), but there are free resources. The chart with this Expert Advisor is "clean" at all, nothing is attached to it.

 
Igor Zakharov:

The only difference is that MT5 is optimised in parallel (it also uses timer), but there are free resources. The chart with this Expert Advisor is "clean", nothing is attached to it.

I have stopped optimization in 5 and it works. Shouldn't there be any connection?

 
Here was my question about Unicode. Why was it rubbed out?
 
secret:
My question about Unicode was here. Why was it deleted?

Let me give you a little background:

A little less expression in questions and they won't get deleted. It's simple: asking a question isn't about taking out your negativity on others. You're in a community.
Respect the place where you ask your questions and expect to get an answer, not a moderator's reaction.

Reason: