Init() and DeInit() execution sequence - page 20

 
Комбинатор:

When you change thef.

If the indicators have trash in their buffers from the old timeframe, it may affect the timers as well.

It is more beautiful

Forum on trading, automated trading systems and strategy testing

New version of MetaTrader 4 build 1065

Sergey Klimov, 2017.04.14 16:34

When switching between accounts, the _Digits variable in the indicator does not change.

 
fxsaber:
It's prettier.
With all the different digits, it seems to be going all over the place, I stopped crossing such accounts in the same terminal about 5 years ago.
 
fxsaber:
It's prettier.

This is for those who talk about proper consistency in MT4.

Watch and understand that not everything is so pretty in MT4.

 
fxsaber:
The queue is unambiguous.


Well, where is it unambiguous?

Try this primitive example. You will understand the "uniqueness" when switching the TF.

In this example, an object with coordinates of current time and price is created in OnInit. In OnCalculate this object moves together with the price.

In OnDeinit it is simply (logically) deleted.

When we switch the TF, the object appears and then disappears.
Why does this happen?
Because sometimes OnDeinit of the old TF deletes something that has already been created in OnInit of the new TF. It is not a bug! What should the programmer who created this example think and did not read this branch?

Demonstration of the ambiguity of the OnInit and OnDeinit sequence


#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {

   datetime t = TimeCurrent();
   double pr  = SymbolInfoDouble(Symbol(),SYMBOL_BID);

   ObjectCreate(0,"InitDeinit",OBJ_ARROW_THUMB_UP,0,t,pr);
   ObjectSetInteger(0,"InitDeinit",OBJPROP_WIDTH,15); 

   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   ObjectDelete(0,"InitDeinit");
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnCalculate (const int rates_total,      // размер массива price[]
                 const int prev_calculated,  // обработано баров на предыдущем вызове
                 const int begin,            // откуда начинаются значимые данные
                 const double& price[])      // массив для расчета
  {

   datetime t = TimeCurrent();
   double pr  = SymbolInfoDouble(Symbol(),SYMBOL_BID);
   ObjectMove(0,"InitDeinit",0,t,pr);
   return(rates_total);
  }
//+------------------------------------------------------------------+
Files:
 
Nikolai Semko:

Well, where is she single-mindedly.

The timer was talked about there.
 
fxsaber:
The timer was mentioned there.

What's the difference. You can put EventSetTimer in Unite instead of object creation, and put EventKillTimer in Deunite instead of object deletion. And this will not reduce uncertainty, because set timer will be killed by Deunite of old TF, and sometimes it won't. And it will be even worse, because at least you can see the object, but you can't see the timer - whether it works or not.
 

Maybe they've already invented it, haven't read the whole thing. If indicator creates panel, you can use global variable of terminal, increase its value by 1 in init and use it as an additive to names of graphical objects.

My task was different - to save parameters of the panel, for this I created global variables of the terminal in deinit. The solution is simple - to create global variables of the terminal in the inite and update each of them as parameters change in the graphic panel. Only delete variables in deinit if deinitialization is caused by removal of indicator.

 
Dmitry Fedoseev

If the indicator creates a panel, you can use a global variable of the terminal, increase its value by 1 and use it as an appendix to names of graphical objects.
These are crutches. You just need to make the correct order in the terminal and that's it. First deinit the previous instance, and only then initiate the new one.
Nikolai Semko:


What must a programmer who created this example think and hasn't read this thread?

I totally agree. Non-readers won't know about this feature and will kill their time trying to figure it out. And that would be hundreds of people... ...especially those who are beginners.

All you need is to fix a bug once and that's it.

 
Nikolai Semko:

What's the difference. You can put EventSetTimer in Unite instead of object creation, and put EventKillTimer in Deunite instead of object deletion. And uncertainty will not decrease, because set timer will be killed by Deunite of old TF, and sometimes it won't. And it will be even worse, because at least you can see the object, but you can't see whether the timer works or not.
This sounds silly. The timers of indicator copies have nothing to do with each other.
 
elibrarius:
It's all crutches. You just need to make the correct order in the terminal and that's all. First deinit the previous instance, and only then initialize the new one.

I totally agree. Non-readers won't know about this feature and will kill their time trying to figure it out. And that would be hundreds of people... especially sorry for beginners.

All you have to do is fix the bug once and that's it.


That's what I'm talking about!
I'm personally on a roll, as I feel I have an advantage over the majority, as I know how to deal with it all, not just in words, but in deeds as well. I have already made patches and added crutches to my programs.

I just don't understand why the developers stubbornly refuse to consider this "feature" a bug.
For instance:

Slawa:

Indicators should be used for their intended purpose.

In other words, the sequence of OnInit and OnDeinit indicator fulfillment when thechart symbol-period has changed should be of no concern to anybody

But in my example with the animated gif above, there is a definite bug for a programmer who hasn't read this topic! What is not done according to its intended purpose?