Expert Advisors --> Properties --> OK

 
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!
 

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.)

 
supertrade:
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!

 
7bit:

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.

 
metafx:

You should have a look at:

https://www.mql5.com/en/articles/1393

Great stuff!


Very helpful. Thanks!
 
supertrade:
Though perhaps there is some nuance when it comes to global variables.
post the init/deinit code, must be something wrong there.
 
supertrade:

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.

 
Thanks. I was hoping there was something else going on before I went digging in the code, but I guess not :P
Reason: