Is it possible for EA to close all orders?

 

This works in scripts but not in EA.

      Comment( Commentary + " | Closing All Orders, please wait ..." );

      CloseAll( "None", 0, OP_ALL ,MaxRetry, Slippage, Commentary );

      Comment("");

 

When compiling EA it gives error 'OP_ALL' variable not defined.  I just started learning mql4, any help is appreciated.

 

What are you trying to do?


Thank you.

 
the EA i'm trying to make opens a number of trades, either long or short, but not both at the same time. At some point set of conditions occurs when I want all of the positions to be closed.
 

I believe your EA must select each order individually using the OrderSelect() function in order to close it's orders individually and in order. There might be a way of selecting the group of orders to close them all at once, but I

am not familiar with that practice.

Are you familiar with the OrderSelect() function?

Thank you.

 

NOT without coding it....

Show your attempt no mindreaders here

For the way how to do see   https://www.mql5.com/en/forum/139654 

 
data1701:

This works in scripts but not in EA.

      Comment( Commentary + " | Closing All Orders, please wait ..." );

      CloseAll( "None", 0, OP_ALL ,MaxRetry, Slippage, Commentary );

      Comment("");

 

When compiling EA it gives error 'OP_ALL' variable not defined.  I just started learning mql4, any help is appreciated.

Where is your function  CloseAll()  coming from ?  include file ?  in your mq4 file ?    can you show it please . . .   OP_ALL is probably a constant,  have you defined it ?
 
RaptorUK:
Where is your function  CloseAll()  coming from ?  include file ?  in your mq4 file ?    can you show it please . . .   OP_ALL is probably a constant,  have you defined it ?

Here it is in the script that does it.
 
void start()
{
         int      MaxRetry = 10;     // If the Order Fails - How many time do we retry?
         int      Slippage = 10;  
      string    Commentary = "Close ALL orders";
      
      Comment( Commentary + " | Closing All Orders, please wait ..." );                 
      CloseAll( "None", 0, OP_ALL ,MaxRetry, Slippage, Commentary );
      Comment("");
      return;
}

CloseAll( "None", 0, OP_ALL ,MaxRetry, Slippage, Commentary );  ?????? 

. 'OP_ALL' - variable not defined C:\.....

For the way how to do close and delete all see https://www.mql5.com/en/forum/139654 

I told you before....   looks like you didn't learn yourself nothing go read again and try something

 

Good that you just learn mql4 :) 

You need an mql4 function to close position which is OrderClose() (https://docs.mql4.com/trading/OrderClose), however OrderClose() need to be selected first by OrderSelect() (https://docs.mql4.com/trading/OrderSelect)

Also read these https://www.mql4.com/search keyword=close all module=mql4_module_forum

 
data1701:

This works in scripts but not in EA.

      Comment( Commentary + " | Closing All Orders, please wait ..." );

      CloseAll( "None", 0, OP_ALL ,MaxRetry, Slippage, Commentary );

      Comment("");

 

When compiling EA it gives error 'OP_ALL' variable not defined.  I just started learning mql4, any help is appreciated.

Can you please show the script where this code works ?