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

 
Alexey Viktorov:

This issue is solved like two fingers... You know what...

In OnDeinit it is necessary to condition the reason for deinitialisation before deleting the object... If it is NOT a period change, then the object is deleted. AND THAT'S IT...


Yes, I can not delete some object or resource at TF change, I can even save some small arrays through object-resource, and write in resource information about TF change, but the point isDeunit may start to be executed after the unit has been executed in a new timeframe - how should I inform the unit that the TF has changed and the old data should be read? Isn't it wrong?
 
Slawa:

What kind of logic is spoiled?

When you change timeframe, a new copy of the indicator is created that knows nothing about the previous copy. For a certain period of time (very short) both copies of the indicator exist in parallel. Then the previous copy is unloaded.

Read documentation https://www.mql5.com/ru/docs/runtime/running


I have read the description of the link, but haven't found such information, as you've given. And if it is really so, it is a great problem for indicator developers. It's very strange and very bad that such logic is adopted for reloading indicators when you change timeframe. Why do we need the existence of two copies of the same indicator in memory? Who benefits from it? What does it give? It would be more logical to complete the execution of one copy of the indicator, to unload it and only then to load the next copy.
 
Nikolai Semko:
And that's ALL!?
I've been experimenting and using this reason code(REASON_CHARTCHANGE) as much as possible. And what's the use if all variables are set to their original state again, and OnDeinit can be executed after OnInit of a new TF
I've only read about deleting an object on deinitialization and was only responding to this problem. It is more complicated with saving of past calculations. And apparently this problem will never be solved. Slava was answering this question, new indicator, new calculations. And this is fair.
 
Alexey Viktorov:
Slava has answered this question, new indicator, new calculations. And this is fair.
The point is that the indicator is the same, but the timeframe is new. And the question is about desynchronization of unit and deunit, i.e. the reverse (illogical) sequence of execution occurs, and sometimes it is logical. There is nothing worse for a programmer than a floating error and logic.
 
Alexey Viktorov:
And apparently this problem will never be solved.

And I have faith in the development team, they are great guys and have done an incredible amount and will do more. I just haven't gotten around to it yet. True, you always have to get feedback from them with bells and whistles. :))
My task is to convince them that it needs to be done. Although I do not exclude that they will convince me that it is better not to do, maybe I do not understand something.
 
Nikolai Semko:

And I have faith in the development team, they are great guys and have done an incredible amount and will do more. I just haven't gotten around to it yet. But I always have to get feedback from them with tambourines. :))
My task is to convince them that it needs to be done. Although I do not exclude that they will convince me that it is better not to do, maybe I do not understand something.


Slawa, what does the phrase in the documentation"Librariesdon't handle any events" mean?

Very vague

 
nmaratr:

- When Inite sets the colour of the main graph to transparent.

I draw my own chart (according to my parameters)


I want it to restore the colour of the main chart after removal of my indicator

- In DeInit I restore the colour of the main chart


When changing the TF I mean first DeInit (restore the colour), and then Init (go back to being transparent)


The execution of commands is not sequential; periodically, when changing the TF

periodically the main chart (with restored colour) is overlaid on my indicator.

Here is for example one "logic breakdown".


Maybe to try to assign to graphical objects the TF period as a component of their name prefix,

and then apply something like this:

 // --- Переменная для хранения текущего ТФ
ENUM_TIMEFRAMES currentTF;

//+---------------------------------------------------------------------------+
void OnInit()
{
  currentTF = (ENUM_TIMEFRAMES)Period();
}

//+---------------------------------------------------------------------------+
void OnDeinit(const int reason)
{
   // --- на момент выгрузки индикатора уже сменился ТФ
  if(currentTF != Period()) 
  {
    // если нужно, удалим объекты имеющие префикс старого ТФ и выходим, не трогаем цвет основного графика
    return;
  }

  // раз дошли сюда, ТФ не сменился, восстанавливаем цвет основного графика
  // удалим объекты имеющие префикс старого ТФ
}
 
nmaratr:

- When Inite sets the colour of the main graph to transparent.

I draw my own chart (according to my parameters)


I want it to restore the colour of the main chart after removal of my indicator

- In DeInit I restore the colour of the main chart


When changing the TF I mean first DeInit (restore the colour), and then Init (go back to being transparent)


The execution of commands is not sequential; periodically, when changing the TF

periodically the main chart (with restored colour) is overlaid on my indicator.

Here is, for example, one "logic breakdown".

Of course it is better when everything happens in a logical sequence, but since we have to work with what we have, we can move the colour of the main chart to OnCalculate with check of the current value.
 
Nikolai Semko:
And that's ALL!?
I've been experimenting and using this reason code(REASON_CHARTCHANGE) as much as possible. And what's the use if all variables are set to the original state again, and OnDeinit can be executed after OnInit of the new TF


Try to update terminal to version 1065. In previous versions there was an error of reinitialization just during timeframe change. May help :)

https://www.mql5.com/ru/forum/187690

Новая версия платформы MetaTrader 4 build 1065
Новая версия платформы MetaTrader 4 build 1065
  • www.mql5.com
Новая версия платформы MetaTrader 4 build 106523 марта 2017 года будет опубликовано обновление платформы MetaTrader 4...
 
Aleksei Radchenko:


Try to update the terminal to version 1065. Previous versions had a reinitialisation error just by changing the timeframe. Might help :)

https://www.mql5.com/ru/forum/187690

We are talking about MT5