void ModifiOrders(int otype) { double avgprice = 0, order_lots = 0; int OSL = 0; price = 0; for(int i = OrdersTotal()-1; i>=0; i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) { if (OrderSymbol() != Symbol() || OrderMagicNumber() != Magic) continue; if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == otype) { price += OrderOpenPrice() * OrderLots(); order_lots += OrderLots(); OSL = NormalizeDouble(OrderStopLoss(),Digits)&& OrderType()== otype; SL = OSL; } } } if(TrailingStop>0) avgprice = NormalizeDouble(price/ order_lots, Digits); if(otype == OP_BUY) SL = NormalizeDouble((Bid - Point*TrailingStop),Digits ); if(otype == OP_SELL) SL = NormalizeDouble((Ask + Point*TrailingStop),Digits ); if( OrderType()== otype || (avgprice + SL <= OSL)) for(int i = OrdersTotal()-1; i>=0; i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) { if (OrderSymbol() != Symbol() || OrderMagicNumber() != Magic) continue; if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == otype) if(OrderModify(OrderTicket(), avgprice,OSL,OrderTakeProfit(),0,Yellow)) Print("OrderModify Error ", GetLastError()); else Print("OrderModify Ok "); } } RefreshRates(); }