Need Help with Function

 

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

What Error? 130?

Do you know the trade-limits?

 

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.

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


 

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

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?

 

Thank you Gooly,

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

Interesting.

Reason: