English

## Need Help with Function

 9 ThemBonez 2014.12.03 15:10   Hi,I wrote this simple function to move two open orders to breakeven when certain criteria are met.The problem I'm having is that it moves one trade to breakeven but gives me a modify error 1 for the second.Any ideas?Thank You``` void MoveToBreakEven() {          for (int i=OrdersTotal()-1; i >= 0; i--)      {          if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))return;             if (!OrderSymbol() == Symbol())continue;                if (OrderMagicNumber() == MagicNumber1 || OrderMagicNumber() == MagicNumber2)                {                     if (OrderType() == OP_BUY)                   {                      if (Bid > (OrderOpenPrice() +( OrderOpenPrice() - OrderStopLoss())))                         if (!OrderModify (OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+(PipsToLockIn*pips),OrderTakeProfit(),0,CLR_NONE))                            Print ("Error modifying order on line: ",__LINE__);                   }                                else if (OrderType() == OP_SELL)                   {                       if (Ask < (OrderOpenPrice() -( OrderStopLoss() - OrderOpenPrice())))                         if (!OrderModify (OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-(PipsToLockIn*pips),OrderTakeProfit(),0,CLR_NONE))                             Print ("Error modifying order on line: ",__LINE__);                   }                }       } }```
 2032 gooly 2014.12.03 15:30 #   ThemBonez:I don't see any problems with trade limits, because the first Order is modified, yet the second order isn't.The criteria for both are the same.  I want them to both be modified when criteria is met.This is not necessarily true, prices are moving and what is ok for the first order might fail the next time - depends on how fast is your broker/connection and how far away are your stops - can't see that :(Error 1 is not any more in the reference before b600+ it meant: #define ERR_NO_RESULT 1, exactly where this error appears?Try to have a little waiting loop:```while(  IsTradeContextBusy() ) Sleep(100); ```
 9 ThemBonez 2014.12.03 15:35 #   Hi Gooly,Thank you.Wait loop didn't help.Modify Error 1 occurs on the line below on the 2nd time around` if (!OrderModify (OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+(PipsToLockIn*pips),OrderTakeProfit(),0,CLR_NONE))`