How can i send Stop Loss and Take Profit order seperately?

 

Hello, I am trying to find out which function i can use from mql5 which allows me to send

seperate Stop Loss and Take Profit orders?

I want to send SL and TP order not with the current order, but only when a condition is met.

Thanks
 
if(), then orderselect, then ordermodify
 
You can either modify an order or you can send two orders, 1 with No SL but with TP, 2nd with SL but no TP.
 
Dark Ryd3r:

Hello, I am trying to find out which function i can use from mql5 which allows me to send

seperate Stop Loss and Take Profit orders?

I want to send SL and TP order not with the current order, but only when a condition is met.

Thanks

Try this way:

// Set stop levels by condition
for(int i=0;i<PositionsTotal();i++){
  ulong iTicket=PositionGetTicket(i);
  if(PositionGetString(POSITION_SYMBOL)==_Symbol){
    if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY){
      if(Condition==true){
        double SL=YourSL...,TP=YourTP...;
        if(PositionGetDouble(POSITION_SL)!=SL||PositionGetDouble(POSITION_TP)!=0){
          if(!trade.PositionModifiy(iTicket,SL,TP)){
            Print(PositionModify error ",trade.ResultRetcode());
            return;
            }
          }
        }
      }
    // Same for POSITION_TYPE_SELL.
    }
  }
Reason: