Cannot close open orders and positions at EA termination

 

Hi,

I have an EA which will close all open orders and positions in the OnDeinit function.

This works fine if if I change the timeframe of the chart the EA is attached to.

But if I remove the EA from the chart the OnDeinit function will be called; but cannot close the open orders and positions,

the error message is 

OrderDelete: auto trading disabled by client

Is this intended?

If yes, how I can close open orders after having finished the EA? Separate script?

Matthias

 
Dr Matthias Hammelsbeck: I have an EA which will close all open orders and positions in the OnDeinit function.
No you don't. An EA must exit withing 2½ second after being commanded. You do not have enough time to close orders.
 
Dr Matthias Hammelsbeck:

Hi,

I have an EA which will close all open orders and positions in the OnDeinit function.

This works fine if if I change the timeframe of the chart the EA is attached to.

But if I remove the EA from the chart the OnDeinit function will be called; but cannot close the open orders and positions,

the error message is 

Is this intended?

If yes, how I can close open orders after having finished the EA? Separate script?

Matthias

Add a button on your chart "Close and exit", when clicked close your orders and remove the EA from the chart.

Using OnDeinit() is very bad practice.

 
Alain Verleyen:

Add a button on your chart "Close and exit", when clicked close your orders and remove the EA from the chart.

Using OnDeinit() is very bad practice.

Thanks. The idea with the button is good 
 
Alain Verleyen: Add a button on your chart "Close and exit",
Add a button in the EA, or create a script with a hot key.
          Fast Navigation - User Interface - MetaTrader 4 Help (Hot keys)
          Hot Keys - For Advanced Users - MetaTrader 5 Help
 

dont use deinit for trade exit, 

use ontick instead

 
Hi,

I also encountered this problem

I hope to develop this feature, I don't know if anyone will:

1. When the EA is removed from the chart, delete all pending orders for the current currency
2. When the EA operates on the chart, when closing the chart, delete all pending orders of the current currency

Because I have seen that EA can already do this function, please refer to the following video

My MT5 Version= 5.00 build 3446



 
Te Fu Chang #: I also encountered this problem

I hope to develop this feature, I don't know if anyone will:
  1. No one will, because no one can. Read the thread again.

  2. There is no need to create pending orders in code.

    1. The pending has the slight advantage, A) you are closer to the top of the queue (filled quicker), B) there's no round trip network delay (filled quicker.)

      Don't worry about it unless you're scalping M1 or trading news.

    2. Humans can't watch the screen 24/7, so they use pending orders; EAs can, so no need for pending orders, have it wait until the market reaches the trigger price and just open an order.

 
William Roeder #:
  1. No one will, because no one can. Read the thread again.

  2. There is no need to create pending orders in code.

    1. The pending has the slight advantage, A) you are closer to the top of the queue (filled quicker), B) there's no round trip network delay (filled quicker.)

      Don't worry about it unless you're scalping M1 or trading news.

    2. Humans can't watch the screen 24/7, so they use pending orders; EAs can, so no need for pending orders, have it wait until the market reaches the trigger price and just open an order.


Thanks for reply and notification

Because this function is one of the functions requested by users

So I came to ask

I have searched for related topics, and currently MT5 cannot perform the action of deleting pending orders after OnDeinit().

So I'm really curious how the EA in the movie did it

 
Te Fu Chang #: So I'm really curious how the EA in the movie did it

Possibilities ...

  • It may issue asynchronous order deletes without actually checking if they are carried out.
  • It may send a signal to another EA or Service that is running, so that it carries out the procedure on behalf of the EA that is being terminated.
  • The video may be false
 
Te Fu Chang #: So I'm really curious how the EA in the movie did it
Or it got lucky with low network latency, low server backlog, and this time made the 2½ second window.
Reason: