Order modify error 1 in Break Even code.

 

I coded a break even code.

But when I run it, sometimes it shows order modify error 1.

I just want to move stoploss to zero(0) but I tried to use  = 1 to avoid order modify error1

Can you advice where the problem?


extern int MoveToBreakEven=2;//BE_Start Pips

void BreakEven() {
    int exitTypePer = MoveToBreakEven; 
    double Min_Profit = 1;
    bool res;
    for (int i = OrdersTotal() - 1; i >= 0; i--) {
        if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == true && OrderSymbol() == Symbol() && (OrderMagicNumber() == MAGIC ) {
            double orderPrice = OrderOpenPrice();
            if (OrderType() == OP_BUY && OrderCloseTime() == 0) {
                double Pips_Profit = Bid - orderPrice;
                Min_Profit = exitTypePer * Point;
                if (Pips_Profit >= Min_Profit && orderPrice != OrderStopLoss()) {
                    double newPrice = NormalizeDouble(orderPrice, Digits);
                    res = OrderModify(OrderTicket(), newPrice, newPrice, OrderTakeProfit(), 0, Orange);

                    if (res == false) {
                        Print("Error modifying order. Error code: ", GetLastError());
                    }
                }
            }
            else if (OrderType() == OP_SELL && OrderCloseTime() == 0) {
                double Pips_Profit = orderPrice - Ask;
                Min_Profit = exitTypePer * Point;
                if (Pips_Profit >= Min_Profit && orderPrice != OrderStopLoss()) {
                    double newPrice = NormalizeDouble(orderPrice, Digits);
                     res = OrderModify(OrderTicket(), newPrice, newPrice, OrderTakeProfit(), 0, Orange);

                    if (res == false) {
                        Print("Error modifying order. Error code: ", GetLastError());
                    }
                }
            }
        }
    }
}

The checks a trading robot must pass before publication in the Market
The checks a trading robot must pass before publication in the Market
  • www.mql5.com
Before any product is published in the Market, it must undergo compulsory preliminary checks in order to ensure a uniform quality standard. This article considers the most frequent errors made by developers in their technical indicators and trading robots. An also shows how to self-test a product before sending it to the Market.
 
orderPrice != OrderStopLoss()) {

Doubles are rarely equal. Understand the links in:
          The == operand. - MQL4 programming forum #2 (2013)

                    double newPrice = NormalizeDouble(orderPrice, Digits);
Now newPrice is not orderPrice. Use orderPrice.
 

Thank you!


Is this true ?


          res = OrderModify(OrderTicket(), orderPrice, orderPrice, OrderTakeProfit(), 0, Orange);
 
Hong Ling Mu #:

Thank you!


Is this true ?


res = OrderModify(OrderTicket(),OrderOpenPrice(), orderPrice, OrderTakeProfit(), 0, Orange);
       
 
Mehmet Bastem #:

Thank you so much!

I will try it.