2) Maybe it is not necessary to re-initialize some variables
staticintChanGeTF = 0; // Признак смены ТФ , держим как статическую переменную в памяти эксперта
//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+intOnInit()
{
if( ChanGeTF == 0) // при первом вызове код в OnInit полностью обрабатывается , но не отработает если просто менялся ТФ
{
// тут сформируем переменные для нашего эксперта которые отработают при первом старте экперта
// возможно сформируем графические объекты
}
else
{
ChanGeTF=0;
// сюда попадет при смене ТФ
// а формировать ничего уже не будем , у нас все сформировано и мы не желаем делать инициализацию переменных
// но если необходимо - что то обработаем в код OnInit
}
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+voidOnDeinit(constint reason)
{
Print(__FUNCTION__,"_UninitReason = ",getUninitReasonText(_UninitReason)); // пишем в лог причину входа в DeInit - очень полезная информация
if ( REASON_CHARTCHANGE != _UninitReason )
{
// сюда не попадаем , если произошла смена ТФ
// удалим графические объекты - для полноценного завершения работы эксперта
//
}
else
{
// сюда попадем если просто произошла смена ТФ
// сделаем то что нам интересно - но при этом - к примеру - не будем удалять с графика графические объекты
ChanGeTF=1;
}
}
//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+string getUninitReasonText(int reasonCode)
{
string text="";
//--- switch(reasonCode)
{
caseREASON_ACCOUNT:
text="Account was changed";break;
caseREASON_CHARTCHANGE:
text="Symbol or timeframe was changed";
break;
caseREASON_CHARTCLOSE:
text="Chart was closed";break;
caseREASON_PARAMETERS:
text="Input-parameter was changed";break;
caseREASON_RECOMPILE:
text="Program "+__FILE__+" was recompiled"; break;
caseREASON_REMOVE:
text="Program "+__FILE__+" was removed from chart";break;
caseREASON_TEMPLATE:
text="New template was applied to chart";break;
default:text="Another reason";
}
//--- return text;
}
How to process these codes of deinitialization in an indicator, what do we need these codes for? After all, there is no possibility to wait in the indicator, Sleep does not work.
Didn't you read what I wrote several times?
There is no way in the indicators. You can't do it in five from the very beginning. Because you download a completely new copy of the indicator with all its consequences.
Nikolai Semko: That is the end of the Expert Advisors.
It is not always wise to limit yourself to reading the first post before writing anything.
It is not quite correct to say what is reasonable and what is not. I did a little run through the subject before writing it.
I pasted a code sample into the subject and now those who read the subject can see that this mechanism doesn't work in an indicator and that it works in an EA.
The author of the topic at least got an answer to one question, and with an example.
Well, it's not really accurate to say what's reasonable and what's not. I did a little research on the subject before writing.
Now those who read the subject can see that this mechanism does not work in an indicator and works in an EA.
Thanks for the code of course. It works fine with Expert Advisors because when we change TF, the variables are not reinitialized, while in indicators they are reinitialized. If you really want to help with advice, please "run" it again in less haste.
Option for solving problems when changing timeframes
If you just changed TF
1) It is probably not necessary to delete graphical objects.
2) Maybe it is not necessary to re-initialize some variables
Option for solving problems when changing timeframes
If you just changed TF
1) It is probably not necessary to delete graphical objects.
2) Maybe it is not necessary to re-initialize some variables
.
Option for solving problems when changing timeframes
If there was just a timeframe change
1) Maybe you should not delete graphical objects.
2) Maybe you should not re-initialize any variables
Your code will not work.
Once again:
You cannot control the results of Deinit in Inite, because Deinit may work after Inite is done.
Your code will not work.
Once again:
You cannot control the results of Deinit in Inite, because Deinit can be triggered after Inite has run.
You mean it won't work- in an indicator ? In experts it works.
How to process these codes of deinitialization in an indicator, what do we need these codes for? After all, there is no possibility to wait in the indicator, Sleep does not work.
Didn't you read what I wrote several times?
There is no way in the indicators. You can't do it in five from the very beginning. Because you download a completely new copy of the indicator with all its consequences.
There is no problem with experts. This topic is just about indicators. Read it carefully.
I read the first post.
It says, and I quote:
"Written Indicator or Co-Assessor"
I read the first post.
It says, and I quote:
"Written by an indicator or co-author."
That is the end of the Expert Advisors.
It is not quite correct to say what is reasonable and what is not.
I did a little run through the subject before writing it.
I pasted a code sample into the subject and now those who read the subject can see that this mechanism doesn't work in an indicator and that it works in an EA.
The author of the topic at least got an answer to one question, and with an example.
Well, it's not really accurate to say what's reasonable and what's not.
I did a little research on the subject before writing.
Now those who read the subject can see that this mechanism does not work in an indicator and works in an EA.