# Need Help with Function

37

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 (!OrderSymbol() == Symbol())continue;
if (OrderMagicNumber() == MagicNumber1 || OrderMagicNumber() == MagicNumber2)
{
{
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__);
}
}
}
}```
7092

What Error? 130?

37

Error 1.

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.

7092

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);

```
37

gooly:

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:

37

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))`
7092

Error 1 is returned by the Server (broker or tester!?) and it means: "No error returned, but the result is unknown."

So check whether the order has been modified?

37

Thank you Gooly,

You were correct....although I am get the error, the stoploss is moving to breakeven.

Interesting.