OrderSend() error 130

 

Hey guys,

I seem to be having a bit of a problem, and any help is appreciated.

I am constantly getting OrderSend() errors 130 which I presume to be (ERR_INVALID_STOPS) and 4059 while back testing..

2015.10.12 11:08:49.210 2015.01.02 11:28  EURUSD,M1: Failed to place a buy stop order, error#4059

2015.10.12 11:08:49.210 2015.01.02 11:28  EURUSD,M1: OrderSend error 130

2015.10.12 11:08:49.210 2015.01.02 11:27  EURUSD,M1: Failed to place a buy stop order, error#4059

2015.10.12 11:08:49.210 2015.01.02 11:27  EURUSD,M1: OrderSend error 130 

Below is the code and please let me know where I am going wrong!

Essentially, I place an order, and later on if conditions are met I place a stop order. I retrieve the values from the original order and use them in the placement of the stop order.  

//Order placement

if(Hour()>=LetsTradeHour && Hour()<=StopTradeHour)                      //Trading hours
 {
  int buyi=OrderSend(Symbol(),OP_BUY,LotSize,Ask,3,Ask-StopLoss,Ask+TakeProfit,"Buy 1",1,0,clrBlue);
   if(buyi<0)
    {
     PlaySound("alert2");
     Print("Failed to place Buy 1 order, error#",GetLastError());
    }
 }

if(XYZ)
 {
  int buystopiii=OrderSend(Symbol(),OP_BUYSTOP,lotsize,BuyOrderOpenPrice()+X,3,BuyOrderStopLoss()+Y,BuyOrderTakeProfit()+Z,"Buy stop order",MagicNumber,0,clrBlue);
   if(buystopiii>0) Sleep(3000);PlaySound(NULL);
    if(buystopiii<0)
     {
      PlaySound("alert2");
      Print("Failed to place a buy cycle order, error#",GetLastError());
     }
 }

//Call function for buy stop values

 double BuyOrderStopLoss()
  {
   for(int z=OrdersTotal()-1; z>=0; z--)
    {
     if(OrderSelect(z,SELECT_BY_POS,MODE_TRADES))
      if(OrderSymbol()==Symbol())
       if(OrderMagicNumber()<=2)
        if(OrderType()==OP_BUY)
         {
          double stoploss=OrderStopLoss();
         }
    }
     return(stoploss);
  }
 

You have 2 Prints in your code

     Print("Failed to place Buy 1 order, error#",GetLastError());

 and

      Print("Failed to place a buy cycle order, error#",GetLastError());

 

your error reports are

2015.10.12 11:08:49.210 2015.01.02 11:28  EURUSD,M1: Failed to place a buy stop order, error#4059

2015.10.12 11:08:49.210 2015.01.02 11:28  EURUSD,M1: OrderSend error 130

2015.10.12 11:08:49.210 2015.01.02 11:27  EURUSD,M1: Failed to place a buy stop order, error#4059

2015.10.12 11:08:49.210 2015.01.02 11:27  EURUSD,M1: OrderSend error 130 

 which cannot come from the code that you have posted

 
GumRai:

You have 2 Prints in your code

 and

 

your error reports are

 which cannot come from the code that you have posted

 

 

Sorry, it is the same Print() for the 

 

if(XYZ)
 {
  int buystopiii=OrderSend(Symbol(),OP_BUYSTOP,lotsize,BuyOrderOpenPrice()+X,3,BuyOrderStopLoss()+Y,BuyOrderTakeProfit()+Z,"Buy stop order",MagicNumber,0,clrBlue);
   if(buystopiii>0) Sleep(3000);PlaySound(NULL);
    if(buystopiii<0)
     {
      PlaySound("alert2");
      Print("Failed to place a buy cycle order, error#",GetLastError());
     }
 }

 I have double checked this. 

 Error report returns:

EURUSD,M1: Failed to place a buy cycle order, error#4059

EURUSD,M1: OrderSend error 130

EURUSD,M1: Failed to place a buy cycle order, error#4059

EURUSD,M1: OrderSend error 130 

 Can you see anything incorrect in my code?

 
  1. Capture the Last Error before it could be clobbered by the PlaySound.
          PlaySound("alert2");
          Print("Failed to place a buy cycle order, error#",GetLastError());
  2. Print out the OrderSend parameters and Ask and Bid to find out why.
Reason: