Questions from Beginners MQL5 MT5 MetaTrader 5 - page 742
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
In real code, the function returns an object.
I think the copy constructor should create a temporary copy in this case.
The code works correctly in MQL5 build 1545.
In the new build, the copy constructor cannot resize even a one-dimensional array: Error 4007.
I think it is not correct.
It's difficult for me to make a definite statement in this case. There are very good experts for your question, so I recommend to address this question tohttps://www.mql5.com/ru/forum/1111.
With my edits the code works as it should. Without it, it doesn't. But whether or not your code should work is better to the branch at the link above.
In real code, the function returns an object.
I think the copy constructor should create a temporary copy in this case.
The code works correctly in MQL5 build 1545.
In the new build, the copy constructor cannot resize even a one-dimensional array: Error 4007.
This is not correct in my opinion.
The error has been fixed in build 1580, thanks, everything works as it should).
It is difficult for me to say anything definitively in this case. There are very good experts on your question, so I recommend that you take it up with thehttps://www.mql5.com/ru/forum/1111 branch.
With my edits the code works as it should. Without it, it doesn't. But whether or not your code should work is better to be directed to the branch at the link above.
Thanks for the link.
Maybe someone can give me a hint.
I can't figure out how to interrupt the execution of the EA after manually changing the input settings.
1) Run the EA code like this on the chart:
2) Open the settings window and change the "Setting_" parameter to 1.
3) And apply the changes.
So, in order to start applying the changes, OnInit must be executed, but OnInit will not be executed until the calculations in OnTick (or any other) stop.
As far as I know, there is only a check forstopping the program through _StopFlag - flag to stop an mql5-program, but it is only for full exit. But I don't know how to understand that the input settings have changed to stop the calculations.
Maybe someone has faced such a situation? Maybe there is some secret hack?
Maybe someone can give me a hint.
I can't figure out how to interrupt the execution of the EA after manually changing the input settings.
1) Run the EA code like this on the chart:
2) Open the settings window and change the "Setting_" parameter to 1.
3) And apply the changes.
So, in order to start applying the changes, OnInit must be executed, but OnInit will not be executed until the calculations in OnTick (or any other) stop.
As far as I know, there is only a check forstopping the program through _StopFlag - flag to stop an mql5-program, but it is only for full exit. But I don't know how to understand that the input settings have changed to stop the calculations.
Maybe someone has faced such a situation? Maybe there is some secret hack?
Check deinitialization code in OnInit()
Reasons for deinitialization
Expert Advisor's deinitialization reason codes returned by UninitializeReason(). They can have any of the following values:
Constant .
Value
Description
REASON_PROGRAM
0
Expert has stopped its work by calling ExpertRemove()
REASON_REMOVE
1
Program removed from the chart
REASON_RECOMPILE
2
Program recompiled
REASON_CHARTCHANGE
3
The chart symbol or period has been changed
REASON_CHARTCLOSE
4
The chart is closed
REASON_PARAMETERS
5
Input parameters were changed by the user
REASON_ACCOUNT
6
Another account was activated or reconnected to the trade server because the account settings were changed
REASON_TEMPLATE
7
Another chart template was applied
REASON_INITFAILED
8
A sign that the OnInit() handler has returned a non-zero value
REASON_CLOSE
9
Terminal was closed
Check deinitialisation code in OnInit()
...
Um... You misunderstand me :)
You need to know inside the function (for example inOnTick), that the user has changed the input parameters, i.e. know that it's time to wrap up and let the program go to OnDeinit.
Um... You misunderstand me :)
You need to know inside the function (e.g. inOnTick) that the user has changed the input parameters, i.e. know that it's time to call it a day and let the program exit to OnDeinit.
As soon as a user calls the EA settings window (F7) and clicks the OK button there, OnDeinit() is immediately called, and this, in its turn, writes the value of REASON_PARAMETERS in the deinitialization code. Then OnInit() is called, where using UninitializeReason() you can check the deinitialization code and, if its value is equal toREASON_PARAMETERS, decide what to do next.
All right.
Please:
1) First run my code, which I gave in my first post. I didn't put it there for the sake of beauty... You can run it on any chart.
2) Call the EA settings window.
3) Change the parameter and press OK.
If you look carefully at my code, then the result will not surprise you: OnDeinit() will not be called.
Not only that, I have added a print in the deinit, both the reason and the parameter, so that you can make sure that the expert does NOT reach the deinit.
Please note the most important piece in the code:
It's a clear emulation of a long calculation that won't be interrupted by a change in the input parameters. And I need to interrupt it and the question is how? :)
I just want to make sure I'm not missing anything in MQL5 and there's really nothing else in the language but_StopFlag, which unfortunately does not solve this situation.
Roughly speaking, I need to catch the moment the input parameters change during a heavy calculation.
Not only that, I have added a print in the deinit, both the reason and the parameter, so that you can make sure that the expert does NOT reach the deinit.
Please note the most important piece in the code:
It's a clear emulation of a long calculation that won't be interrupted by a change in the input parameters. And I need to interrupt it and the question is how? :)
I just want to make sure I'm not missing anything in MQL5 and there's really nothing else in the language but_StopFlag, which unfortunately does not solve this situation.
Roughly speaking, I need to catch the moment the input parameters change during a heavy calculation.
Roughly speaking - reread carefully what I wrote to you and drop the infinite loop from your code.
Are you sure that driving the Expert Advisor into an infinite loop is the right solution?