Yes, this is also possible:
syntax is:
void ExpertRemove();
The Expert Advisor is not stopped immediately as you call ExpertRemove();
just a flag to stop the EA operation is set. That is, any next event won't be processed, OnDeinit()
will be called and the Expert Advisor will be unloaded and removed from the chart.
So the OnDeinit(){...}
-handler is activated "automatically", once a first call to the ExpertRemove()
system function has raised the pre-termination flag.
If your logic requires, put this call into a "manually" called OnTester()
handler, relying on it being invoked as posted above
if( cnt > 100 ) { OnTester(); // having the "killer"-ExpertRemove() there ... }
and you are done.
You might have noticed, there should not be the posted OnTick()
-call inside the if(){...}
-code-block, as it would never let the code-execution reach the manually-pre-scribed call to the OnTester()
, but will remain in a lethal never ending loop of manually-injected endless diving of re-entries into the OnTick(){...}
-handler, having no way to exit from.