Order Modify Error 1 Help Please

 

I keep getting the error when closing out part of the lots of a trade and cannot seem to fix it, any ideas? It does not perform order modify on the sell order either which is strange!


void BreakEven1()
{
 if (BreakEvenType==1)
{
    double lots = 0;
    double takeprofit = 0;
    for (int i=OrdersTotal()-1; i >= 0; i--)
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
    {
        
        {

            if (OrderType() == OP_BUY && Ask - OrderOpenPrice() > BreakEvenPoint*PipValue*Point && (OrderStopLoss() < Ask-(BreakEvenPoint)*PipValue*Point))
            {
                lots = (OrderLots() * BreakEvenRisk2) / 100;
                lots = NormalizeDouble(lots, NDigits);
                if (lots < MarketInfo(Symbol(), MODE_MINLOT))    // make sure lot is not smaller than allowed value
                lots = MarketInfo(Symbol(), MODE_MINLOT);
                
                takeprofit = Ask+TakeProfit*PipValue*Point;
                if (TakeProfit == 0) takeprofit = OrderTakeProfit();
                bool ret1 = OrderModify(OrderTicket(), OrderOpenPrice(), Ask-TrailingGap2*PipValue*Point, takeprofit, OrderExpiration(), White);
                if (ret1 == false)
                Print("OrderModify() error - ", ErrorDescription(GetLastError()));
                else if (OrderLots() >= MinLot2)
                {
                    ret1 = OrderClose(OrderTicket(), lots, OrderClosePrice(), 4, White);
                    if (ret1 == false)
                    Print("OrderModify() error - ", ErrorDescription(GetLastError()));
                }
                
            }
            if (OrderType() == OP_SELL && OrderOpenPrice() - Bid > BreakEvenPoint*PipValue*Point && (OrderStopLoss() > Bid+(BreakEvenPoint)*PipValue*Point))
            {
                lots = (OrderLots() * BreakEvenRisk2) / 100;
                lots = NormalizeDouble(lots, NDigits);
                if (lots < MarketInfo(Symbol(), MODE_MINLOT))    // make sure lot is not smaller than allowed value
                lots = MarketInfo(Symbol(), MODE_MINLOT);
                
                takeprofit = Bid-TakeProfit*PipValue*Point;
                if (TakeProfit == 0) takeprofit = OrderTakeProfit();
                bool ret2 = OrderModify(OrderTicket(), OrderOpenPrice(), Bid+TrailingGap2*PipValue*Point, takeprofit, OrderExpiration(), White);
                if (ret2 == false)
                Print("OrderModify() error - ", ErrorDescription(GetLastError()));
                else if (OrderLots() >= MinLot2)
                {
                    ret2 = OrderClose(OrderTicket(), lots, OrderClosePrice(), 4, White);
                    if (ret2 == false)
                    Print("OrderModify() error - ", ErrorDescription(GetLastError()));
                }
                
            }
            
        }
    }
    else
    Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
    
}
}
 
gangsta1:

I keep getting the error when closing out part of the lots of a trade and cannot seem to fix it, any ideas?

You need to make sure that your new TP != OrderTakeProfit()  and that your new SL  !=  OrderStopLoss() (bearing in mind the issues with comparing doubles)  otherwise you are just setting the same values and you will get error 1  
 
Thank you. So I need to set a value other than 0 then? I was setting sl/tp 0 to use the initial stop loss/take profit but this may be the error. Thanks again you are always very responsive and helpful.
 

Why do you always print your errordiscription with same line ??

Print("OrderModify() error - ", ErrorDescription(GetLastError()));

 Even when you get a return for Orderclosecommand ???

With using always the same line makes finding part error coming from only more difficult !! 

 
Yes, I think it is because I was using 0 for tp and sl as I wanted to use the sl/tp of previous order.
Reason: