Download MetaTrader 5

Close All order and pending order if one of the order is take profit

To add comments, please log in or register
kasur
5
kasur  

Hi Guys,,apologize me if my english is bad,,I'm from Indonesia,,and I want to make an EA but I got the problem

How to close all opened order and all pending order if one of the opened order is already take profit?

I'm very appreciate for all the forum to help me :D thanks.

whroeder1
15727
whroeder1  
How to close all opened order and all pending order if one of the opened order is already take profit?
Do you really want to close the one order that is one pip in profit? Anyway something like this:
    for(int inProfit = OrdersTotal()-1; pos >= 0 ; pos--) if (
        OrderSelect(inProfit, SELECT_BY_POS)         // Only my orders w/
    &&  OrderMagicNumber() == magic.number           // my magic number
    &&  OrderSymbol()      == Symbol()               // and symbol
    &&  OrderProfit()       > 0 ){
        CloseAll(); break;
    }
...
void CloseAll(){
    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 symbol
        if (OrderType()< OP_SELL) 
           OrderClose(OrderTicket(), OrderLots(), OrderClose(), Slippage.Pips*pips2points,  Aqua );
        else
           OrderDelete(OrderTicket());
}   }
To add comments, please log in or register