void SL_TP()
{
if(StopLoss<MarketInfo(Symbol(),MODE_STOPLEVEL) || TakeProfit<MarketInfo(Symbol(),MODE_STOPLEVEL)) {Alert("Stops to close to price");return;}
for (int i=OrdersTotal()-1; i>=0; i--)
{
OrderSelect(i,SELECT_BY_POS);
{
if(OrderMagicNumber()==magic)
{
if(OrderType()==OP_BUY || OrderType()==OP_BUYSTOP || OrderType()==OP_BUYLIMIT)
{
while(IsTradeContextBusy()) Sleep(1000);
if(StopLoss>0 && OrderStopLoss()!=NormalizeDouble(OrderOpenPrice()-StopLoss*Point,Digits)) OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()-StopLoss*Point,Digits),OrderTakeProfit(),0,CLR_NONE);
while(IsTradeContextBusy()) Sleep(1000);
if(TakeProfit>0 && OrderTakeProfit()!=NormalizeDouble(OrderOpenPrice()+TakeProfit*Point,Digits)) OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),NormalizeDouble(OrderOpenPrice()+TakeProfit*Point,Digits),0,CLR_NONE);
}
if(OrderType()==OP_SELL || OrderType()==OP_SELLSTOP || OrderType()==OP_SELLLIMIT)
{
while(IsTradeContextBusy()) Sleep(1000);
if(StopLoss>0 && OrderStopLoss()!=NormalizeDouble(OrderOpenPrice()+StopLoss*Point,Digits)) OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()+StopLoss*Point,Digits),OrderTakeProfit(),0,CLR_NONE);
while(IsTradeContextBusy()) Sleep(1000);
if(TakeProfit>0 && OrderTakeProfit()!=NormalizeDouble(OrderOpenPrice()-TakeProfit*Point,Digits)) OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),NormalizeDouble(OrderOpenPrice()-TakeProfit*Point,Digits),0,CLR_NONE);
}
}
}
}
}