OrderModify returns error 130 for no reason!

 

I have been strugling all afternoon on a little piece of code that has no reason not to work. It is a simple fucntion to modify existing orders. Here is the code:

void test()
{
double last_tp_s=0, last_tp_l=0;
int total=OrdersTotal();
   for (int cnt=0; cnt<total; cnt++) 
   {
      if( OrderSelect(cnt,SELECT_BY_POS, MODE_TRADES)==true)
      {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==id)
         { 
            if ( OrderType()==OP_SELL)
            {
            last_tp_s=MathMax(last_tp_s,OrderTakeProfit()); 
            }
         }  
      }
   }
}

   for (cnt=0; cnt<total; cnt++) 
   {
      if( OrderSelect(cnt,SELECT_BY_POS, MODE_TRADES)==true)
      {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==id)
         { 
         
            if ( OrderType()==OP_SELL)
            {
              if(OrderOpenPrice()<last_tp_s)
               {
               Print("******************************** ",OrderType()," / ",OrderOpenPrice()," / " ,last_tp_s);
               OrderModify(OrderTicket(),NormalizeDouble(OrderOpenPrice(),Digits),NormalizeDouble(last_tp_s,Digits),NormalizeDouble(OrderTakeProfit(),Digits),OrderExpiration(),Magenta);
               }   
            }
         }
      }
   }
return;
}

Here is the Print from the log:

2008.11.10 00:51:37	2007.01.02 08:49  TrendProfit EURUSD,H1: OrderModify error 130
2008.11.10 00:51:37	2007.01.02 08:49  TrendProfit EURUSD,H1: ******************************** 1 / 1.3189 / 1.3219

As you can see from the log i have a OP_SELL order. All my doubles are normalized. The OrderOpenPrice() is well bellow the new SL. Yet i still get a 130 error. Can anyone help?

 

run the test again, print Bid and Ask price along with OrderOpenPrice() and last_tp_s

Also, add

Print("******************************** stop_level = ", MarketInfo(Symbol(), MODE_STOPLEVEL), " freeze_level = ", MarketInfo(Symbol(),MODE_FREEZELEVEL), );

 
make sure your sl must have at least 5 pips with current price (bid or ask, depends on your order is sell or buy).
 

Here you go guys:

2008.11.10 08:16:20	2007.01.02 08:49  TrendProfit EURUSD,H1: OrderModify error 130
2008.11.10 08:16:20	2007.01.02 08:49  TrendProfit EURUSD,H1: Order_Type= 1OrderOpen= 1.3189NewSL= 1.3219Bid= 1.3269Ask= 1.3271stop_level= 8 freeze_level= 0

I'm very confused. This is suposed to just work!

 

Your order is sell at 1.3189

Current price is 1.3269/71

Stop loss must be above 1.3271 + 8 stoplevel

 
phy:

Your order is sell at 1.3189

Current price is 1.3269/71

Stop loss must be above 1.3271 + 8 stoplevel

Maybe I was not clear enough. The order is a market order. The current market price has nothing to do with modifying the SL as long as it is 8 pips away from the order opening price, which it is. Having said that my order was open at 1.3189 the new SL is 1.3219 which is clearly 8+ pips away. Why the 130 error?

 

The current market price has nothing to do with modifying the SL as long as it is 8 pips away from the order opening price,

Wrong.

 
phy:

Wrong.

So what you are saying is i can not modify the SL of an order opened at 1.3189 until price goes above 1.3271 + 8 stoplevel. What kind of sence does that make?

 

Your example printed a current Ask price of 1.3271

You can't set a new stop loss on a sell for less than current Ask + 8 pips, per your Dealer's restrictions on stop placement.

Have a nice day.

Reason: