How do I programmatically stop an EA from trading? - page 2

 

I used to work for NEC. The topic was Telephone Central Offices -- and the required software/firmware to run such a beast

that might service up to 100,000 subscriber lines, interconnect with other local or long distance offices, maybe implement

Signalling System #7 and ISDN protocols.

One lesson I learned there was:

'Software is never complete. You just tell the Customer it is"

 

Hi guys,

the start() function is called at each tick.

now I can "stop" the EA by simply exiting start() before it got a chance to do anything else. however, this is not very safe. some condition (e.g. closing and re-opening mt4) might re-initialize the ea and it might "start" running again.

hence, there are situations where programmatically removing the ea might be a good idea. as far as i know, if this can be done at all, then only at the level of indows calls (winuser32.mqh & more).

 
arstrube:

the start() function is called at each tick.

now I can "stop" the EA by simply exiting start() before it got a chance to do anything else. however, this is not very safe. some condition (e.g. closing and re-opening mt4) might re-initialize the ea and it might "start" running again.

That's why all experts need a persistence layer. If done properly then expert will resume exact previous state - remain 'disabled'.

p.s. removal via WinAPI call -> https://www.mql5.com/en/forum/120736.

 

Hello,

As I needed this information, I put the one I found.

To exit from an EA by programming in MT4, we can use the function :

ExpertRemove ()

Sample :

if (my_Exit_EA_Condition == true ) ExpertRemove();

After that if the OnDeinit () function exists, it is executed and the EA stops

Best regards.

-------------- En Français ---------------------------

Bonjour,

Comme j'ai eu besoin de cette information, je mets celle que j'ai trouvée.

Pour sortir d'un EA en programmant dans MT4, on peut utiliser la fonction:

ExpertRemove ()

Exemple :

if (my_Exit_EA_Condition == true) ExpertRemove ();

Après cela, si la fonction OnDeinit () existe, elle est exécutée et l' EA s’arrête

Salutations.

 

If you wish to stop the execution of an expert advisor programmatically, use the ExpertRemove() function.

Once the current event is finished executing, the expert advisor will stop its operation and remove itself from the chart.

If you wish to close the terminal, the TerminalClose() function will close MetaTrader. The TerminalClose() function takes one parameter, a deinitialization code that will be passed to the OnDeinit() function.

When calling the TerminalClose() function, it must be followed by the return operator:


TerminalClose(REASON_CLOSE);

return;

Reason: