- Metatrader known bugs ...
- Expert Advisor properties by clicking on a button
- control live ea
What observations? It will call deinit() and then init() again, exactly as it is clearly described in the documentation.
You can call UninitializeReason() to determine why init() or deinit() have been called (newly loaded EA, chart change, properties change, chart close, EA removed, etc.)
What actually goes on when a user right clicks on the chart, brings up Expert Advisors --> Properties, changes an external parameter, then clicks OK? I always thought the expert was re-initialized but this doesn't seem to be the case based on my observations. Does it just keep running start() with the new parameters without calling init() again? Thanks!
You should have a look at:
https://www.mql5.com/en/articles/1393
Great stuff!
What observations? It will call deinit() and then init() again, exactly as it is clearly described in the documentation.
You can call UninitializeReason() to determine why init() or deinit() have been called (newly loaded EA, chart change, properties change, chart close, EA removed, etc.)
Actually, since I made the initial post, I confirmed that init() is, in fact, called but the reason I said that was because my EA has some external input who's value is used to determine some other values (one of which is a global variable created using the GlobalVariableSet() function); this is done inside the init() function. When I attached the EA to a chart, let it run, then pulled up Properties, changed some input, and clicked OK, this global variable would not change. This was despite my having this global variable deleted when deinit() is called. However, when I detached the EA from the chart, then re-attached it with the new input, all was as expected. Based on that, I figured init() is only called when an expert is attached to a chart, and not when it is already attached and input is changed. Though perhaps there is some nuance when it comes to global variables.
You should have a look at:
https://www.mql5.com/en/articles/1393
Great stuff!
Very helpful. Thanks!
Though perhaps there is some nuance when it comes to global variables.
Though perhaps there is some nuance when it comes to global variables.
I have used them in init() and deinit() myself and did not see any irregularities. Maybe there is some other logical error hidden somewhere in your code. If in doubt you can always surround every access of the variable with Print() statements before and after to see what value the variable had before and after and also to see more clearly in which order the various things happen in your EA.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use