Quick question on how to setup orders for taking profit

 

Say I want to take profit on 1/2 of my position.

Is the only way to do this is to have 2 separate orders opened at the same price and once the TakeProfit level reached close one of the orders and let the other one go?

I would prefer to have a single open order and then be able to sell 1/2 of my Open Lots - is this possible? I haven't seen a way to do this with ModifyOrder() or OrderClose(), etc.

Thanks!

 
  1. One order: you close 1/2 order size with:
        double  minLot  = MarketInfo(Symbol(), MODE_MINLOT),
                lotStep = MarketInfo(Symbol(), MODE_LOTSTEP),
                curSize = OrderLots(),
                toClose = size = MathFloor(curSize/2  // close half
                                          /lotStep)*lotStep;
         if (size < minLot){ // too small to close half.
         else if (!OrderClose( OrderTicket, toClose, OrderClosePrice(),
                               Slippage.Pips*pips2points,  Aqua )){ ...
    
    Plus you then have to remember that you already did close half and not close again. Also the ticket number changes on the remainder and you have to orderSelect loop to find it.
  2. 2 separate orders mean you just have to set the TP and everything happens automatically
        double  maxLot  = MarketInfo( Symbol(), MODE_MAXLOT );  //IBFX=50.00
        double  LotStep = MarketInfo( Symbol(), MODE_LOTSTEP ); //IBFX= 0.01
        #define PAIRS 2 // Open two orders, one half lot size each.
        for(int count=MathCeil(lots.new/(PAIRS*maxLot))*PAIRS; count>0; count--) {
            // 50.00+49.99=99.99    25.01+25.00+25.00+25.00=100.01
            size = MathCeil(lots.new/count/LotStep)*LotStep;
            lots.new -= size;                               // Remaining amount.
            ticket  = OrderSend(Symbol(),       operation,      size,   now.open,
                                SlippagePips * pips2points,     0, 0,   // SL,TP
                                order.comment,  MagicNumber + Period.index,
                                NO_EXPIRATION,  clr );
            if (ticket < 0) {
                Alert(  "OrderSend(type=",  operation, " (",    operation.text,
                        "), lots=",     size,
                    ", price=", DoubleToStr( now.open,              Digits     ),
                        " (",   DoubleToStr((now.open-Bid)/pips2dbl,Digits.pips),
                    "), SL=0, TP=0, '", order.comment, "', ...) failed: ",
                                                                    GetLastError());
                                        reason.nt = "|OrderSend Failed";  break;
            }
        }   // for(count)
        ModifyStops();  // Set SL/TP
    
 
WHRoeder:
  1. One order: you close 1/2 order size with: Plus you then have to remember that you already did close half and not close again. Also the ticket number changes on the remainder and you have to orderSelect loop to find it.
  2. 2 separate orders mean you just have to set the TP and everything happens automatically

Awesome - Thanks!
Reason: