Adding Stop Loss to Open Trade

 

If a trade has been opened without a stop loss, but later on the necessity to add a stop to the open trade arises, what is the best way to deal with this situation?

Is it to use OrderModify:

OrderModify(Ticket,Open_Price,Stop_Loss,0,0,clrNONE);

and if so, how will the program know if the stop loss has been executed? Is it best practice to just write a function that checks this?

 

If you have selected the order and done whatever checks necessary to see if you want to add the SL....

double nsl=???????                  
if(!OrderModify(OrderTicket(),OrderOpenPrice(),nsl,OrderTakeProfit(),0,clrDodgerBlue))
    Print("Error Modifying Ticket #",ticket," Error Code ",GetLastError());
 
koranged:

If a trade has been opened without a stop loss, but later on the necessity to add a stop to the open trade arises, what is the best way to deal with this situation?

Is it to use OrderModify:

and if so, how will the program know if the stop loss has been executed? Is it best practice to just write a function that checks this?

Have a look in the CodeBase for EAs that apply a trailing stop-loss. That will give you plenty of examples of how to use the OrderModify() function to apply or add a stop-loss to an order.
 
Thanks Keith and Fernando
 
Thanks.