HOw to stop an EA

 

Hello,


I want to know how to do to stop the execution of an expert, if a certain condition is met.

There is a special function for that?

 
crystal7:

Hello,


I want to know how to do to stop the execution of an expert, if a certain condition is met.

There is a special function for that?


return(0);  from the start() Function . . .
 
RaptorUK:

return(0);  from the start() Function . . .

Thank you,


And from Init(), this is the same?


It doesn't works from the start() funtion, the code make a cycle at each ticks.


Can we make deinit()?

For exemple:

   if(TimeCurrent() > TimeOfBegin)//Vérifie que la date n'est pas dans le passé
   { 
   Alert("La date est dans le passé!");
   deinit();
   }
 
crystal7:

Thank you,

And from Init(), this is the same?

It doesn't works from the start() funtion, the code make a cycle at each ticks.


Of course it works from start(),  put it at the start of the start() function and the EA will do nothing useful for each tick . . .  just return.
 

I'm not so sure if this still work with the latest build MT

to open EA property after 2 ticks

#include <WinUser32.mqh>
int Tick;

int start ()
  {
  Tick ++;
  if (Tick >= 2)
    {
    PlaySound ("wait.wav");
    PostMessageA(WindowHandle(Symbol (), Period ()), WM_COMMAND, 33048, 0);
    }
  return (0);
  }

And to remove completely remove EA from chart after 2 ticks - see journal tab

#include <WinUser32.mqh>
int Tick;

int start ()
  {
  Tick ++;
  if (Tick >= 2)
    {
    PlaySound ("wait.wav");
    PostMessageA(WindowHandle(Symbol (), Period ()), WM_COMMAND, 33050, 0);
    }
  return (0);
  }

See also this https://www.mql5.com/en/forum/124688

 

What I want to do, is to do not initialise my EA if a certain time is passed, the EA close itself with a message os error.

How can I do that?

 
crystal7:

What I want to do, is to do not initialise my EA if a certain time is passed, the EA close itself with a message os error.

How can I do that?


Try my codes above, or you can also deliberately make a error such divided by zero

int tick = 1;

if (condition == true)
  {
  tick = 5/(tick - 1);
  }

not compiled not tested - and I prefer my previous code - if it still works.

 

I don't want a trick to get an error.

I want a real clean exit of the expert, by the deinit() function.

But, thanks for all, if you have an other idea, you are welcom.

 
crystal7:

I don't want a trick to get an error.

I want a real clean exit of the expert, by the deinit() function.

But, thanks for all, if you have an other idea, you are welcom.


I've told you to try this code https://www.mql5.com/en/forum/141931 the second code will remove EA completely - try it first - if you don't like it then don't use it.