You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
komposter
You are right. I made a mistake.
Thank you for your reply.
MQL5 Reference Manual - Standard Library - Classes for organizing data - CArrayObj (on the website and in the help):
2. The memory management mechanism is disabled.
In this case, CArrayObj is not responsible for memory freeing
Documentation. Static variables section.
"...Static variables exist from the moment of program execution and are initialized once before calling the specialized function OnInit()..."
Checking code of the Expert Advisor:
"Placing" the EA on the chart:
Without removing the EA from the chart, we change the chart period:
Is it supposed to work like this?
I actually interpreted the information from the documentation as a forced initialization of static variables at any call of the function OnInit(), regardless of whether it was caused by recompilation or a change of the symbol or something else...
It turns out that I was mistaken. Please enlighten me: what are exceptions to this rule?
When the input parameters are changed, it's the same "mess".
When the account is changed, however, it is handled correctly - the static variables are re-initialised.
I wonder how to change chart symbol without deleting expert(REASON_CHARTCHANGE)?
Documentation. Static variables section.
"...Static variables exist from the moment of program execution and are initialized once before calling the specialized function OnInit()..."
Checking code of the Expert Advisor:
"Placing" the EA on the chart:
Without removing the EA from the chart, we change the chart period:
Is it supposed to work like this?
Yes, it should work.
The program (its code) has already been loaded once and only performs a hot re-initialization (Deinit/Init without code unloading). In this case, developer himself must take care of a proper initialization of the environment.
Yes, it should work like that.
The program (its code) is already loaded once and just does a hot re-initialization (Deinit/Init without code unloading). In this case, developer must care about proper initialization of the environment.
Firstly, your comment clearly contradicts the definition in documentation: initialize once before calling OnInit(). Then you should clearly specify the definition in documentation: "...initialize once before calling OnInit(). first call OnInit()".
Secondly, your comment clearly contradicts the case of change of account, in which MT, obviously, forcibly terminates the Expert Advisor and restores it again.
Can the fundamental question of whether static variables should be forcibly reinitialized at each (not just the first) call to OnInit() be brought up for consideration/voting?
In general, it's funny how things work.
At first sight, I thought that the OnDenit function is a kind of destructor, and OnInit - the constructor of the Expert Advisor.
In fact, it turns out that OnInit is a multiple event (within the lifetime of expert). Then it is not clear, why do we need to explicitly generate the OnDenit event if we know that the EA doesn't terminate its operation (for example, in case of change of chart period)?
And another question.
The reason for deinitialization of REASON_CHARTCHANGE is the symbol or period of a chart has been changed.
Please explain how a chart symbol can be changed without deleting the EA on it?
And another question.
Reason for deinitialisation REASON_CHARTCHANGE - The chart symbol or period has been changed.
Please explain how a chart symbol can be changed without deleting the EA on it?
Actually, it's funny.
On my intuition, I thought that the OnDenit function is a kind of destructor and OnInit is the constructor of the Expert Advisor.
In fact, it appears that OnInit is a multiple event (within the lifetime of an Expert Advisor). Then it is not clear, why do we need to explicitly generate the OnDenit event if we know that the EA doesn't terminate its operation (for example, in case of change of chart period)?
And another question.
The reason for deinitialization of REASON_CHARTCHANGE - The symbol or period of a chart has been changed.
.Please explain how a chart symbol can be changed without deleting the EA on it?
The same way everything was called in MT4. And it is not known, whether expert finishes its work or not (for this purpose in OnDeinit parameters are fallen, though the reason of possible OnInit triggering is easy to know, too).
2. It's very simple, in the terminal settings allow the Expert Advisor to trade when the symbol and period change.
Then select another symbol in the market overview and "drop" it on the chart with your mouse.
The EA in any case, with normal initialization after the change of symbol/period "will not be deleted" (it will "Hot Restart" as Renat said below). If we look at it on a simple level, the Expert Advisor will be allowed to trade under certain terminal settings.
ChartSetSymbolPeriod()
Firstly, your comment clearly contradicts the definition in documentation: they are initialized once before call OnInit(). Then you should clearly specify the definition in the documentation: "...initialize once before calling OnInit(). first OnInit() call".
Secondly, your comment clearly contradicts the case of account change, in which MT obviously forcibly terminates the EA and restores again.
Can we introduce/vote a fundamental question about the necessity of forced reinitialization of static variables at each (not only at first) call of OnInit()?