Call OnDeinit when exiting Mt5

 

Hi,

I've written and EA that dynamically open charts and templates. The EA includes OnDeInit() which closes the open charts. This function works fine if the EA is removed manually, but doesn't get called when exiting MT5 via file->exit or 'x'.  If I forget to remove the EA, I get stuck with a number of orphan charts on next startup.

Is there any technique to trigger the system to call OnDeInit() when exiting the system, or some other method?

Thanks

 
ceejay1962:

Hi,

I've written and EA that dynamically open charts and templates. The EA includes OnDeInit() which closes the open charts. This function works fine if the EA is removed manually, but doesn't get called when exiting MT5 via file->exit or 'x'.  If I forget to remove the EA, I get stuck with a number of orphan charts on next startup.

Is there any technique to trigger the system to call OnDeInit() when exiting the system, or some other method?

Thanks

I don't think there is, but you could write some code in the OnInit() so when the EA restarts it repeats the clean-up process you want to invoke.

 
ceejay1962: I've written and EA that dynamically open charts and templates. … I get stuck with a number of orphan charts on next startup.

Don't open charts that already exist.

 
William Roeder #:

Don't open charts that already exist.

Thanks. I'm trying to avoid doing that. If I have to remember to remove the EA before exiting, I can live with it.

 
R4tna C #:

I don't think there is, but you could write some code in the OnInit() so when the EA restarts it repeats the clean-up process you want to invoke.

Thanks. I'll think about that.

 
ceejay1962 #: Thanks. I'm trying to avoid doing that. If I have to remember to remove the EA before exiting, I can live with it.

Do or do not, there is no trying, there is no remembering. Find out if the chart exists before opening a new one.

Reason: