Error OrderModify 130/1 MQL4

 

Hi, I have problems with OrderModify error 130 and 'OrderModify 1, but I don't understand why, this is the code from where I modify it



void OpenTrade(string sym, int tmode, double tsize){
   int err = 0, ticket = 0;
   double TP = 0, SL = 0;

   if(!IsTradeAllowed()){
      while(true){
         if(IsTradeAllowed()) break;
         Sleep(100);
      } 
   }
   RefreshRates();
   
   if (tmode == OP_BUY){
      err = 1;
      while(err > 0){
         RefreshRates();
         
         //if (TakeProfit > 0) TP = Ask + TakeProfit * Point * mp;
         //else TP = 0;
         TP = BUY_TP_Price;
         //Print("Current TP distance:", (TP - Ask) / Point / mp);
         if ((TP - Ask) / Point / mp < Min_TP_Distance) TP = Next_BUY_TP_Price;

         if (Stop_Loss > 0) SL = Ask - Stop_Loss * Point * mp;
         else SL = 0;
         
         ticket = OrderSend(sym, OP_BUY, tsize, Ask, 0, 0, 0, "", Magic_Number, 0, Green);
         err = GetLastError();
        Print(sym+" Buy open, err:",err);
        
         if (err == 3 || err == 64 || err == 65 || err == 130 || err == 131 || err == 133 || err == 134 || err == 148 || err == 4110 || err == 143 ) err = 0;
         
         if (err != 0) Sleep(1000);
      }
      
       if (ticket > 0 && (TP > 0 || SL > 0)){ 
           if (OrderSelect(ticket,SELECT_BY_TICKET)){    // check if the order is open
                  
          if (OrderStopLoss() != OrderOpenPrice()){   // check if the SL has already been moved
          
             if (!OrderModify(ticket,OrderOpenPrice(),SL, TP,OrderExpiration(),clrViolet))
             { 
                   
                Print("Error in OrderModify ", GetLastError());
                
             }
          
          }
                 
       }
 
    }
   
   
   }
   
   if (tmode == OP_SELL){
      err = 1;
      while(err > 0){
         RefreshRates();
         
         //if (TakeProfit > 0) TP = Bid - TakeProfit * Point * mp;
         //else TP = 0;
         TP = SELL_TP_Price;
         //Print("Current TP distance:", (Bid - TP) / Point / mp, ",TP:",TP);
         if ((Bid - TP) / Point / mp < Min_TP_Distance) TP = Next_SELL_TP_Price;
         
         if (Stop_Loss > 0) SL = Bid + Stop_Loss * Point * mp;
         else SL = 0;
         
         ticket= OrderSend(sym, OP_SELL, tsize, Bid, 0, 0, 0, "", Magic_Number, 0, Red);
         err = GetLastError();
         Print(sym+" Sell open, err:",err);
         if (err == 3 || err == 64 || err == 65 || err == 130 || err == 131 || err == 133 || err == 134 || err == 148 || err == 4111) err = 1;
         
         if (err != 0) Sleep(1000);
      }
      
      if (ticket > 0 && (TP > 0 || SL > 0)){ 
          if (OrderSelect(ticket,SELECT_BY_TICKET)){    // check if the order is open
                  
          if (OrderStopLoss() != OrderOpenPrice()){   // check if the SL has already been moved
          
             if (!OrderModify(ticket,OrderOpenPrice(),SL,TP ,OrderExpiration(),clrViolet)){ 
                

                      
                Print("Error Modify Order ", GetLastError());
                
             }
          
          }
                 
       }
       }
   }
   }
 
Comandantf:

Hi, I have problems with OrderModify error 130 and 'OrderModify 1, but I don't understand why, this is the code from where I modify it



Hi,

error 130 in INVALID_STOPS. it mostly occurs when the SL is too close to the open price. you have to check if your SL is at minimum distance. you can get the minimum distance like this:

MarketInfo(_Symbol, MODE_STOPLEVEL)


and also make sure to normalize the SL and TP prices:

NormalizeDouble(SL, Digits)
 
Vitor Palmeira Abbehusen #:

Hi,

error 130 in INVALID_STOPS. it mostly occurs when the SL is too close to the open price. you have to check if your SL is at minimum distance. you can get the minimum distance like this:


and also make sure to normalize the SL and TP prices:

Hi, thanks i solved the 103, The ordermodify 1 is null, right?

what could it refer to? As I sent to the screen, there are some operations like the one I pointed out that opens without SL & TP(It is I believe that most likely the ordermodify 1 is due to this)

 
Vitor Palmeira Abbehusen #: and also make sure to normalize the SL and TP prices:

Wrong. Prices must be a multiple of TickSize, not point.

 
William Roeder #:

Wrong. Prices must be a multiple of TickSize, not point.

You're absolutely right. my mistake. thanks for the notice.