Help please, simplest way to close pending orders if orders that was open closed.

 

I am still working through the book, and try small tasks at a time. I would like to find out what the best way is to approach this.

What should the script look like for: If no open orders, close all pending orders.

Any help would be appreciated.

Marius

 
6601205058083:

[...]

What should the script look like for: If no open orders, close all pending orders.

[...]

If no open market orders, close all pending orders.
 

Yes, I want to make sure when any take profits or stop losses closed market orders, the pending orders get closed.

 

No problem, you asked: "What should the script look like for: If no open orders, close all pending orders." & i answered yes, only with a small change i add "market"

 
int openCount=0;
for(int pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
    OrderSelect(pos, SELECT_BY_POS)             // Only my orders w/
&&  OrderType()        <= OP_SELL               // Only open orders
&&  OrderMagicNumber() == Magic.Number          // my magic number
&&  OrderSymbol()      == Symbol() ){           // and period and symbol
    openCount++;
}
if (openCount == 0)    
for(int pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
    OrderSelect(pos, SELECT_BY_POS)             // Only my orders w/
&&  OrderMagicNumber() == Magic.Number          // my magic number
&&  OrderSymbol()      == Symbol() ){           // and period and symbol
    OrderDelete(OrderTicket());
}
 
WHRoeder:


Thanks a stack, nice of you to point me in the right direction.
 
6601205058083:

Thanks a stack, nice of you to point me in the right direction.


point you in the right direction?

he wrote the whole code for you

 
You are right, thank you again for the help.
Reason: