Errors, bugs, questions - page 2297

 
Nikolai Semko:

Thank you, but I didn't see any answers to my questions there.
I don't understand why destructor is not called whenA *a= new A;

https://www.mql5.com/ru/docs/basis/variables/object_live

All the objects created by the expression pointer_object=newClass_name must be destroyed by the delete(pointer_object) operator afterwards. If, for some reason, this variable was not destroyedby the delete operator, the message about it will appear in the "Experts" journal. It is possible to declare several variables and assign them all to the same object pointer.

Документация по MQL5: Основы языка / Переменные / Создание и уничтожение объектов
Документация по MQL5: Основы языка / Переменные / Создание и уничтожение объектов
  • www.mql5.com
После загрузки на исполнение mql5-программы каждой переменной выделяется память в соответствие с типом переменной. Переменные делятся на два типа по уровню доступа - глобальные переменные и локальные переменные, и по классам памяти: входные параметры mql5-программы, статические и автоматические. Каждая переменная при необходимости...
 

I ask MQL to check OnTimer() function.

For some reason it does not work in strategy tester for MT4 (no errors, just nothing inside this function is executed), while online it is OK.

For MT5 the function works both in the tester and online.

Thank you!

 
A lot of time is spent on Incorrect-Init
Core 1  pass 114 tested with error "incorrect input parameters" in 0:00:00.218

In OnInit only two numbers are compared, and it takes more time for an Incorrect pass than a full pass! How come?


Let's run this Expert Advisor on full optimization

input int Range = 0; // задать Оптимизацию 1 .. 10000

int OnInit() { return(INIT_PARAMETERS_INCORRECT); }


We get the result of working with 8 Agents

Tester  optimization finished, total passes 10000
Statistics      optimization done in 2 minutes 24 seconds


Here's our Expert Advisor now

input int Range = 0; // задать Оптимизацию 1 .. 10000

void OnInit() {}
Tester  optimization finished, total passes 10000
Statistics      optimization done in 0 minutes 31 seconds


At last, like this one

input int Range = 0; // задать Оптимизацию 1 .. 10000

void OnInit() { ExpertRemove(); }
Tester  optimization finished, total passes 10000
Statistics      optimization done in 2 minutes 19 seconds


Two outputs

  1. Incorrect-Init and ExpertRemove are the same in terms of speed.
  2. An empty run is ~5 times faster than an exit from OnInit.


On the second point, there's clearly some sort of error. It is more beneficial in terms of time to perform an empty run, rather than popping out of OnInit. Please correct it because the advantages of Incorrect-Init and ExpertRemove will be almost completely lost.

 

The favourites tab with EAs/indicators/scripts and accounts is only remembered after exiting the terminal. Because of this, an abnormal exit (power out) resets this tab. Is it possible to save it when changing it?

Sometimes there is a clear understanding that it would be very handy if folders could be added to the favourites.

 
A100:
Then try it like this:

Result:

1:POINTER_AUTOMATIC
1:POINTER_DYNAMIC
2:POINTER_DYNAMIC
2:POINTER_AUTOMATIC

Thank you! Quite a solution.

But it's probably better that the compiler doesn't swear:

class B  { public:
                     B(void *b) {d=b;}
                    ~B() { delete d; }
   void             *d; };

Is this a bug or what?
When you create an instance of a class via new , it doesn't call the destructor.

Is this the only solution to create a special class for calling the destructor? Or can we do without it?

 
Andrey Barinov:

Create with new and delete with delete

The question is to put delete in a destructor, but when creating an instance of a class via new (A *a=newA ;) the destructor is not called.

 
aleger:

Is it possible, and if yes, how, to derive in any ZigZag indicator the corresponding values of price extremums High and Low,

ensuring their stable binding and close proximity to the formed tops and bottoms?

See example fromOBJ_TEXT

 

Thank you.
That's exactly what it says here.

Все объекты, созданные выражением указатель_объекта=new Имя_Класса, обязательно должны быть впоследствии уничтожены оператором delete(указатель_объекта). 
Если по каким то причинам такая переменная по окончании работы программы не была уничтожена оператором delete, то об этом будет выведено сообщение в журнал "Эксперты". 
Можно объявить несколько переменных и всем им присвоить указатель одного объекта.
Если динамически создаваемый объект имеет конструктор, то этот конструктор будет вызван в момент выполнения оператора new. Если объект имеет деструктор, 
то деструктор будет вызван в момент выполнения оператора delete.

So it's not a bug, it's a feature which results in a vicious circle.
If I want to automate the process of deleting a dynamic object, the destructor is called only at delete, so it is useless to put delete into the destructor itself.
But automation can be implemented through another instance of another class, as @A100 suggestedhere.

 
aleger:

Thanks for the tip. I'm already exhausted from reading and trying and trying and reading. I'd like to see a working example of the ZigZag...

Like on my avatar with a zigzag, but with a RIGHT binding of upper extrema, because the binding of lower extrema is OK!

The way of binding with k=(WindowPriceMax()-WindowPriceMin())/30 does not work when the window size changes much, I wish something else...


In theOBJ_TEXT example both top and bottom bind. Follow the link, run the example ...

 
Nikolai Semko:

So it's not a bug, but a feature, resulting in a vicious circle.

You have already been told earlier that the way to solve the control of allocated unmanageable resources is to use smart pointers. The full analogy with C++.
Perhaps the problem is that the solution wasn't presented on a silver platter, sorry.


Everyone can type "shared_ptr" into site search and follow the first result, it's not hard, I strongly recommend to try it.