OrderSend failed with error #130

To add comments, please log in or register
kumaillakhani
166
kumaillakhani  

Hello,

I am getting Error:

EURUSD,H4: OrderSend failed with error #130

void OnTick()
  {
   
   H1EMAprev = NormalizeDouble(iMA(NULL,PERIOD_H1,14,0,MODE_EMA,PRICE_CLOSE,1), 5);
   H4EMAprev = NormalizeDouble(iMA(NULL,PERIOD_H4,14,0,MODE_EMA,PRICE_CLOSE,1), 5);
   StopLossBuy = High[2] + ((3 * 10) * Point);
   StopLossSell = Low[2] - ((3 * 10) * Point);

   if(
      Close[1]>H4EMAprev && 
      Close[1]>H1EMAprev
      )
     { 
      Price = High[1] + ((3 * 10) * Point);
      TpOrderOne = Price + ((10 * 10) * Point);

      //Pending order BUY
      Ticket1 = OrderSend(Symbol(),OP_BUYSTOP,1,Price,3,StopLossBuy,TpFirstOrder,"Pending Buy Order 1",16384,0,clrGreen);
      
      if(Ticket1<0)
       {
        Print("OrderSend failed with error #",GetLastError());
       }
      else
       {
        Print("OrderSend placed successfully");
       }
     }

   if(
      Close[1]<H4EMAprev && 
      Close[1]<H1EMAprev
      )
     {
      
      Price = Low[1] - ((3 * 10) * Point);
      TpOrderOne = Price - ((10 * 10) * Point);
      
      //Pending order BUY
      Ticket1 = OrderSend(Symbol(),OP_SELLSTOP,1,Price,3,StopLossSell,TpFirstOrder,"Pending Buy Order 1",16384,0,clrGreen);
      
      if(Ticket1<0)
       {
        Print("OrderSend failed with error #",GetLastError());
       }
      else
       {
        Print("OrderSend placed successfully");
     }

  }

Experts Please guide where I am making mistake?

Mehrdad Jeddi
29397
Mehrdad Jeddi  

Hi,

This error is for invalid stop error,

Check your StopLosses are not fit for stop pending orders.

kumaillakhani
166
kumaillakhani  
Mehrdad Jeddi:

Hi,

This error is for invalid stop error,

Check your StopLosses are not fit for stop pending orders.

Not getting could you please explain?


Trade Open Criteria:

  • Buy Trade will be open immediately on start of current candle IF last candle's closing price was above EMA(EXPONENTIAL MOVING AVERAGE) (i.e: Close[1] > EMA).
  • Sell Trade will be open immediately on start of current candle IF last candle's closing price was below EMA(EXPONENTIAL MOVING AVERAGE) (i.e: Close[1] < EMA).

Open Trade Price:

  • Pending Buy Trade price will be 3 pips above of last candle's High (i.e: TradePriceOpen = High[1] + 3 pips).
  • Pending Sell Trade price will be 3 pips below of last candle's Low (i.e: TradePriceOpen = Low[1] + 3 pips).

Stop Loss:

  • SL will be 3 pips below of 2nd last candle's Low in Sell Stop Pending Order (i.e: SL = Low[2] - 3 pips).
  • SL will be 3 pips above of 2nd last candle's High in Buy Stop Pending Order (i.e: SL = High[2] + 3 pips).

Take Profit:

  • TP will be 10 pips below of the price where trade was opened in Sell Stop Pending Order (i.e: TP = TradePriceOpen - 10 pips).
  • TP will be 10 pips above of the price where trade was opened in Buy Stop Pending Order (i.e: TP = TradePriceOpen + 10 pips).

Vitalii Ananev
10008
Vitalii Ananev  
kumaillakhani:

Not getting could you please explain?

Open Trade Price:

  • Pending Buy Trade will be open when last candle's closing price will be above EMA(EXPONENTIAL MOVING AVERAGE). Open trade price will be 3 pips above of last candle's High.
  • Pending Sell Trade will be open when last candle's closing price will be below EMA. Open trade price will be 3 pips below of last candle's Low.

Stop Loss:

  • SL will be 3 pips below of 2nd last candle's low in Sell Stop Pending Order
  • SL will be 3 pips above of 2nd last candle's High in Buy Stop Pending Order

Take Profit:

  • TP will be 10 pips below of the price where trade was opened in Sell Stop Pending Order
  • TP will be 10 pips above of the price where trade was opened in Buy Stop Pending Order

It is possible that you are trying to place a pending order too close to the current price. Either you set the SL or TP values incorrectly. To check, using the Print() function before sending a trade order, output the value of the current price and the order setting price, as well as the price of SL and TP, to the log.

Set TakeProfit and StopLoss need within a minimum level SYMBOL_TRADE_STOPS_LEVEL.


BuyLimit и BuyStop 
SellLimit и SellStop
TakeProfit - Order open price >= SYMBOL_TRADE_STOPS_LEVEL
Order open price - StopLoss >= SYMBOL_TRADE_STOPS_LEVEL
Order open price - TakeProfit >= SYMBOL_TRADE_STOPS_LEVEL
StopLoss - Order open price >= SYMBOL_TRADE_STOPS_LEVEL
kumaillakhani
166
kumaillakhani  
Vitalii Ananev:

It is possible that you are trying to place a pending order too close to the current price. Either you set the SL or TP values incorrectly. To check, using the Print() function before sending a trade order, output the value of the current price and the order setting price, as well as the price of SL and TP, to the log.

What is the minimum requirement of SL and TP? I mean how far from market price I'll be able to place a pending order?

Vitalii Ananev
10008
Vitalii Ananev  
kumaillakhani:

What is the minimum requirement of SL and TP? I mean how many pips far i could place a pending order?

SYMBOL_TRADE_STOPS_LEVEL

Minimal indention in points from the current close price to place Stop orders

int


https://www.mql5.com/en/docs/constants/environment_state/marketinfoconstants


If this value is zero and the error persists then I usually use a minimum average spread size multiplied by two.

Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties
Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties
  • www.mql5.com
To obtain the current market information there are several functions: SymbolInfoInteger(), SymbolInfoDouble() and SymbolInfoString(). The first parameter is the symbol name, the values of the second function parameter can be one of the identifiers of ENUM_SYMBOL_INFO_INTEGER, ENUM_SYMBOL_INFO_DOUBLE and ENUM_SYMBOL_INFO_STRING. Some symbols...
kumaillakhani
166
kumaillakhani  
Vitalii Ananev:

It is possible that you are trying to place a pending order too close to the current price. Either you set the SL or TP values incorrectly. To check, using the Print() function before sending a trade order, output the value of the current price and the order setting price, as well as the price of SL and TP, to the log.

Set TakeProfit and StopLoss need within a minimum level SYMBOL_TRADE_STOPS_LEVEL.


BuyLimit и BuyStop 
SellLimit и SellStop
TakeProfit - Order open price >= SYMBOL_TRADE_STOPS_LEVEL
Order open price - StopLoss >= SYMBOL_TRADE_STOPS_LEVEL
Order open price - TakeProfit >= SYMBOL_TRADE_STOPS_LEVEL
StopLoss - Order open price >= SYMBOL_TRADE_STOPS_LEVEL

Still not getting you could you show me a code with dummy market values to understand it better. Also guide me when I am debugging my EA I am not able to see my logs where could I see my logs while debuging?

kumaillakhani
166
kumaillakhani  
Vitalii Ananev:

SYMBOL_TRADE_STOPS_LEVEL

Minimal indention in points from the current close price to place Stop orders

int


https://www.mql5.com/en/docs/constants/environment_state/marketinfoconstants


If this value is zero and the error persists then I usually use a minimum average spread size multiplied by two.

Currently Market info:

Bid = 1.1368

Ask = 1.1369800000000001

Ticket1 = OrderSend(Symbol(),OP_SELLSTOP,1,1.1364099999999999,3,1.13731,1.13541,"Pending Sell Order 1",16384,0,clrGreen);

long ex = SymbolInfoInteger(Symbol(), SYMBOL_TRADE_STOPS_LEVEL);

ex is 8

Could you explain now where is problem?

Vitalii Ananev
10008
Vitalii Ananev  
kumaillakhani:

Currently Market info:

Bid = 1.1368

Ask = 1.1369800000000001

Ticket1 = OrderSend(Symbol(),OP_SELLSTOP,1,1.1364099999999999,3,1.13731,1.13541,"Pending Sell Order 1",16384,0,clrGreen);

long ex = SymbolInfoInteger(Symbol(), SYMBOL_TRADE_STOPS_LEVEL);

ex is 8

Could you explain now where is problem?

You need to normalize the order opening price, as well as SL and TP. To do this, use the function NormalizeDouble(Price,Digits()); where is Price, the price you want to normalize.

kumaillakhani
166
kumaillakhani  
Vitalii Ananev:

You need to normalize the order opening price, as well as SL and TP. To do this, use the function NormalizeDouble(Price,Digits()); where is Price, the price you want to normalize.

StopLossSell = NormalizeDouble(1.13761 - ((3 * 10) * Point), 5);

Price = NormalizeDouble(1.1367100000000001 - ((3 * 10) * Point), 5);

TpOrderOne = NormalizeDouble(1.13561 - ((10 * 10) * Point), 5);

long ex = SymbolInfoInteger(Symbol(), SYMBOL_TRADE_STOPS_LEVEL); // Getting 8

Ticket1 = OrderSend(Symbol(), OP_SELLSTOP, 1,1.13561, 3, 1.13731, 1.13541, "Pending Sell Order 1", 16384, 0, clrGreen);

Already doing normalize all values

Vitalii Ananev
10008
Vitalii Ananev  
kumaillakhani:

Already doing normalize all values

If the error persists, check that the SL and TP are not closer than SYMBOL_TRADE_STOPS_LEVEL. 

Also, the order opening price should not be closer than  MarketInfo (Symbol(), MODE_STOPLEVEL) to сurrent price. 

If MarketInfo (Symbol (), MODE_STOPLEVEL) is equal to zero, then this value is floating and it is necessary to use an offset from the current price of at least two spreads.

123
To add comments, please log in or register