5

I am making a EA for backTest.

Normally program works like this.

  1. Ontick() is called until the end of certain period.
  2. OnDeinit() OnTester() are called.

However now I want to stop in OnTick() and goto 2).

like this,

void OnTick()
{
    if (cnt > 100) {OnTick();OnTester();//Finish program here}
}

I think I could stop in OnInit() (to check user's initial setup etc...) However can I stop EA in OnTick()???

In summary, what I want to do is,

Call OnTester() from inside of the OnTick() and finish the program.

user3666197
  • 1
  • 6
  • 50
  • 92
whitebear
  • 11,200
  • 24
  • 114
  • 237

1 Answers1

5

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.

user3666197
  • 1
  • 6
  • 50
  • 92
  • Thanks it works well!, I didn't need to add `OnTester()` manually, it was called automatically by `ExpertRemove()`. I just added like this `if( cnt > 100 ) { ExpertRemove();}` – whitebear Nov 22 '17 at 04:00