Error 130 by OrderModify No sense, 2 outputs with the same slice of code

 

Hi everyone, I'm struggling with this. It should be really simple, basically I have sent an order, (example 1) after it takes certain Points of profit I decide to modify it and then close half of the position showing a 130 error (BUY_LIMIT / SELL_LIMIT)


(2019.05.06 00:02:10.318 2019.01.03 00:35:07  convergence USDJPY,M30: OrderModify error 130)


well, it collapses for no reason, I have tried to set up a new order placed manually and then run the second script (same slice of code as the first one) and goes smoothly, any advice about the error and how to solve it? Thanks in advance.


1 -------------------------------

for(int i=total_orders;i>=0;i--)  //Check for the first profit
          {
           if(OrderSelect(i,SELECT_BY_POS)==true)
            {
            if(OrderProfit()>=first_profit && !(OrderStopLoss()==OrderOpenPrice()))
              {
               bool order_modify = OrderModify(OrderTicket(),0,Ask-Point*150, NormalizeDouble(OrderOpenPrice() + Point *200,5),0,clrGreen); //NormalizeDouble(Ask-Point*first_profit,5)
               bool order_close = OrderClose(OrderTicket(),OrderLots()*0.5,Bid,1);
              }
            }
          
          }





2 -----------------------------------------------------------


void OnStart()
 {
  if(OrderSelect(0,SELECT_BY_POS)==True)
    {
     Alert("ORDER SELECTED!!!");
    }
  

  bool order_modify = OrderModify(OrderTicket(),0,Ask-Point*150, NormalizeDouble(OrderOpenPrice() + Point * 200,5),0,clrAliceBlue); 
  
  if(order_modify)
  {
   Alert("ORDER MODIFIED!!!");
  }
  else
  {
   Alert("CANT MODIFIED!!");
  }
  
 }




 
  1. When you post code please use the CODE button (Alt-S)! (For large amounts of code, attach it.) Please edit your (original) post.
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  2. Why did you post your MT4 question in the Root / MT5 General section Why did you post your MT4 question in the Root / MT5 General section

  3. Ask-Point*150,  
    What is Point? It is not _Point nor Point().

  4. bool order_close = OrderClose(OrderTicket(),OrderLots()*0.5,Bid,1);
    You can't just use OrderLots()/2 because that is not a multiple of LotStep, and you can't close or have remaining less than MinLot. See my code.
  5. Check your return codes for errors, and report them including GLE/LE. Don't look at it unless you have an error. Don't just silence the compiler, it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
    Only those functions that return a value (e.g. iClose, MarketInfo, etc.) must you call ResetLastError before in order to check after.
  6. How do you know that the order is a buy?

  7. if(OrderProfit()>=first_profit && !(OrderStopLoss()==OrderOpenPrice())) 
    Doubles are rarely equal. Understand the links in:
              The == operand. - MQL4 and MetaTrader 4 - MQL4 programming forum

Reason: