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) removed.
When you switch the TF, it turns out that the object appears and then disappears. Why does this happen? Because sometimes OnDeinit of the old TF deletes what 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?
What is the point of using a primitive example of a two-timers?
Use an example of the VERY correct code instead.
//+------------------------------------------------------------------+//| ProjectName |//| Copyright 2012, CompanyName |//| http://www.companyname.net |//+------------------------------------------------------------------+#property copyright"Copyright 2016, MetaQuotes Software Corp."#property link"https://www.mql5.com"#property version"1.00"#property indicator_chart_window#property indicator_plots0//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+intOnInit()
{
datetime t = TimeCurrent();
double pr = SymbolInfoDouble(Symbol(),SYMBOL_BID);
if(ObjectFind(0, "InitDeinit") < 0) // ПРОВЕРКА СУЩЕСТВОВАНИЯ ОБЪЕКТА ПЕРЕД ЕГО СОЗДАНИЕМ ОБЯЗАТЕЛЬНА!!!
{
ObjectCreate(0,"InitDeinit",OBJ_ARROW_THUMB_UP,0,t,pr);
Print(__FUNCTION__, " создан InitDeinit");
}
ObjectSetInteger(0,"InitDeinit",OBJPROP_WIDTH,50);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+voidOnDeinit(constint reason)
{
if(UninitializeReason() != REASON_CHARTCHANGE) // ПРОВЕРКА ПРИЧИНЫ ДЕИНИЦИАЛИЗАЦИИ РЕШАЕТ ТВОЮ ПРОБЛЕМУ НА РАЗ...
{
ObjectDelete(0,"InitDeinit");
ChartRedraw(0); // ЭТО НУЖНО ТОЛЬКО НА ВЫХОДНЫЕ. В РАБОЧИЕ ДНИ НЕ БУДЕТ ЛИШНИМ, НО С ПРИХОДОМ НОВОГО ТИКА ОБЪЕКТ БУДЕТ НЕДОСТУПЕН.
Print(__FUNCTION__, " InitDeinit удалён");
}
}
//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+intOnCalculate (constint rates_total, // размер массива price[]constint prev_calculated, // обработано баров на предыдущем вызовеconstint begin, // откуда начинаются значимые данныеconstdouble& price[]) // массив для расчета
{
datetime t = TimeCurrent();
double pr = SymbolInfoDouble(Symbol(),SYMBOL_BID);
ObjectMove(0,"InitDeinit",0,t,pr);
return(rates_total);
}
//+------------------------------------------------------------------+
fxsaber: This is the same. The object can be deleted via Deinit of the irrelevant indicator copy. And OnInit of the actual one is performed BEFORE this event.
if(UninitializeReason() != REASON_CHARTCHANGE)
{
// Если причина деинициализации смена периода графика сюда не попадаем и объекты не удаляются.
}
In all other cases, except for pulling the computer's power plug, the object will be deleted.
In all other cases, except for pulling the computer's power plug, the object will be deleted.
You have demonstrated a solution to a private discussion problem. The general one is formulated as follows
fxsaber:
Reliablypass any information from OnDeinit of the old copy to OnInit of the new copy.
Which, consequently, requires a clear OnDeinit/OnInit execution sequence. I've never needed this, but I've implemented the solution idea without any problems.
fxsaber: You have demonstrated the solution to a private discussion problem. A general one may be formulated as follows
Which, consequently, requires a clear OnDeinit/OnInit execution sequence. I never needed this, but I implemented the solution idea without any problems.
Well, I am not against it. But scratching my right ear with my left little finger is not for me. Instead of such a simple test to write"it" ... I don't even know what to call it. Let it be for the amateur, because masochism has a right to exist. With all due respect to your professionalism in programming.
fxsaber: So you did not understand the essence of the problem discussed in this thread.
I understand, but you have transferred discussion of the problem to your abilities (not small).
And after all my answer was to a specific example of a code of a colt, and not in response to your abilities and an example of data transfer with regulation of sequence of execution On_Init and On_Deinit.
What is the purpose of continuing the dialogue? Are you trying to convince me that scratching the right ear with left little finger is very pleasant? Or another purpose?
The example you redid did not perfectly match the problem you were discussing. You could show another example that would not have a solution throughUninitializeReason.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
In principle, you could do with a single line.
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) removed.
When you switch the TF, it turns out that the object appears and then disappears.
Why does this happen?
Because sometimes OnDeinit of the old TF deletes what 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?
What is the point of using a primitive example of a two-timers?
Use an example of the VERY correct code instead.
Better use an example of Virtually correct code.
It's the same. The object can be deleted via Deinit of the irrelevant indicator copy. And OnInit of the actual one is performed BEFORE this event.
But it is much better to show the transfer of any information from OnDeinit of the old copy to OnInit of the new one. Actually, this is the point.
This is the same. The object can be deleted via Deinit of the irrelevant indicator copy. And OnInit of the actual one is performed BEFORE this event.
In all other cases, except for pulling the computer's power plug, the object will be deleted.
But it's much better to show passing any information from OnDeinit of the old copy to OnInit of the new one. This is actually the point.
In all other cases, except for pulling the computer's power plug, the object will be deleted.
Reliablypass any information from OnDeinit of the old copy to OnInit of the new copy.
Which, consequently, requires a clear OnDeinit/OnInit execution sequence. I've never needed this, but I've implemented the solution idea without any problems.
You have demonstrated the solution to a private discussion problem. A general one may be formulated as follows
Which, consequently, requires a clear OnDeinit/OnInit execution sequence. I never needed this, but I implemented the solution idea without any problems.
Well, I am not against it. But scratching my right ear with my left little finger is not for me. Instead of such a simple test to write"it" ... I don't even know what to call it. Let it be for the amateur, because masochism has a right to exist. With all due respect to your professionalism in programming.
Instead of such a simple check, write"it" ...
So you did not understand the essence of the problem discussed in this thread.
I understand, but you have transferred discussion of the problem to your abilities (not small).
And after all my answer was to a specific example of a code of a colt, and not in response to your abilities and an example of data transfer with regulation of sequence of execution On_Init and On_Deinit.
What is the purpose of continuing the dialogue? Are you trying to convince me that scratching the right ear with left little finger is very pleasant? Or another purpose?
Or is it a different target?