OrderSend error 130 placing pending orders

 

Hi everybody,

I am getting some 130 errors placing pending orders (sell stops and buy stops). The funny thing is that, for ECN compliance, I am opening all trades without initial stoploss or takeprofit, to later update the ticket and set the proper stoploss and takeprofit levels. Therefore, why is mt4 throwing a invalid stops error? (I am accounting for the stoplevel to set the pending orders)

Thanks in advance :)

 

If your open price for a Buy Stop is too close to Ask you will get an error 130 . . it's all here: https://book.mql4.com/appendix/limits

If that doesn't help then please show the error from the log including the Bid and Ask at the time of placing the order and the Entry price and Order type.

 
RaptorUK:

If your open price for a Buy Stop is too close to Ask you will get an error 130 . . it's all here: https://book.mql4.com/appendix/limits

If that doesn't help then please show the error from the log including the Bid and Ask at the time of placing the order and the Entry price and Order type.

Thanks a lot!! I'll look into this.
 

Okay, this did it!

/**
* Places an order
* @param    int      Type
* @param    double   Lotz
* @param    double   PendingPrice    Only for pending orders
*/
void PlaceOrder(int Type, double Lotz, double PendingPrice = 0)
{
   // Local
   int err;
   double l_stoploss = 0;
   double l_price = 0;
   color  l_color;
   double stoplevel = getStopLevelInPips();
   RefreshRates();
   
   // Price and color for the trade type
   if(Type == OP_BUY){ l_price = Ask;  l_color = Blue; }
   if(Type == OP_SELL){ l_price = Bid; l_color = Red; } 
   if(Type == OP_BUYSTOP) { l_price = PendingPrice; if(l_price <= Ask+stoplevel*DecimalPip) l_price = Ask + stoplevel*DecimalPip; l_color = LightBlue; }
   if(Type == OP_SELLSTOP) { l_price = PendingPrice; if(l_price >= Bid-stoplevel*DecimalPip) l_price = Bid - stoplevel*DecimalPip; l_color = Salmon; }
   //-- Buy limit and sell limit not supported
   
   // Avoid collusions
   while (IsTradeContextBusy()) Sleep(1000);
   int l_datetime = TimeCurrent();
   
   // Send order
   int l_ticket = OrderSend(Symbol(), Type, Lotz, l_price, Slippage, 0, 0, "", MagicNumber, 0, l_color);
   
   // Rety if failure
   if (l_ticket == -1)
   {
      while(l_ticket == -1 && TimeCurrent() - l_datetime < 60 && !IsTesting())
      {
         err = GetLastError();
         if (err == 148) return;
         Sleep(1000);
         while (IsTradeContextBusy()) Sleep(1000);
         RefreshRates();
         l_ticket = OrderSend(Symbol(), Type, Lotz, l_price, Slippage, 0, 0, "", MagicNumber, 0, l_color);
      }
      if (l_ticket == -1)
         Print(ShortName +" (OrderSend Error) "+ ErrorDescription(GetLastError()));
   }
   if (l_ticket != -1)
   {
      LastOrderTime[Type]     = iTime(Symbol(), 0, 0);
      LastOrderTicket[Type]   = l_ticket;
      LastOrderLots[Type]     = Lotz;
      d_totaltrades++;
        
      if (OrderSelect(l_ticket, SELECT_BY_TICKET, MODE_TRADES))
      {
         l_stoploss = MyNormalizeDouble(GetStopLoss(Type));
         if(!OrderModify(l_ticket, OrderOpenPrice(), l_stoploss, 0, 0, Green))
            Print(ShortName +" (OrderModify Error) "+ ErrorDescription(GetLastError())); 
      }
   }
}
 
if(l_price <= Ask+stoplevel*DecimalPip)
OrderSend(Symbol(), Type, Lotz, l_price, Slippage...
EA's must adjust for 4/5 digit brokers. You appear to adjust stoplevel but you don't adjust Slippage
 
WHRoeder:
EA's must adjust for 4/5 digit brokers. You appear to adjust stoplevel but you don't adjust Slippage


flaab is using an ECN broker which ignores the slippage parameter. You cannot control slippage with a market order on an ECN broker. https://www.mql5.com/en/forum/123636 and here http://www.forexfactory.com/showthread.php?t=8046

If you want some control with an ECN then use limit or stop orders, but then you cannot control spread. So the house always has the upper hand! Go figure.

 
Does your EA always places pending order too close.?? If yes, then moniter price inside EA and as soon as it reaches your pending price, pull the trigger..