Add take profit without removing stop loss

 

 I use this to set a take profit for an order: 

modify = OrderModify(ticket, price, 0, (price + (direction * (TakeProfit + ii) * PointSize)), 0, Green);

 The problem is that it removes the stop loss which was previously set.  The stop loss is changed to 0.

How can I set a take profit without removing the stop loss?

 



 
hknight:

 I use this to set a take profit for an order: 

 The problem is that it removes the stop loss which was previously set.  The stop loss is changed to 0.

How can I set a take profit without removing the stop loss?

That because when you set value for take profit you set zero for stop loss. See what are parameters for OrderModify

modify = OrderModify(ticket, price, 0, (price + (direction * (TakeProfit + ii) * PointSize)), 0, Green);

It's better to use OrderSelect to do this :

#include <stdlib.mqh>

  if (OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES) == true)
     {
     if (OrderModify (ticket, OrderOpenPrice(), OrderStopLoss(), the-new-take-profit, 0, Green) == false)
       {
       Print ("Error in modifying take profit ",ErrorDescription(GetLastError());
       }
     }
 
hknight:

 I use this to set a take profit for an order: 

 The problem is that it removes the stop loss which was previously set.  The stop loss is changed to 0.

How can I set a take profit without removing the stop loss?

 




Thats because you have specified 0 for stop loss.

First select the order and then in ordermodify specify OrderStopLoss() in place of stop loss.