130 (ERR_INVALID_STOPS)

 
Hi!
I have code like this:
double    bid, ask, point;
int    digits, stoplevel;
 
    int cnt, cntOrders, ticket, ticketBuy, ticketSell, total, f_news, f_logs;
    string n_time, n_pair, NewsPair, symbol;
    double lots;    // wielkosc otwieranej pozycji
    double balance, equity, lotsize;
    double price_b, price_s;
 
 
    point = MarketInfo(pair, MODE_POINT);
    bid = MarketInfo(pair, MODE_BID);
    ask = MarketInfo(pair, MODE_ASK);
    digits = MarketInfo(pair, MODE_DIGITS);
    stoplevel = MarketInfo(pair, MODE_STOPLEVEL);
 
    balance = AccountBalance();    equity = AccountEquity();
    lotsize = MarketInfo(NewsPair, MODE_LOTSIZE);
    lots = balance*Risk/lotsize;
    price_b = ask+15*point;
    price_s = bid-15*point;
 
    symbol = NewsPair;
    //Print(lots+" "+ask+" "+(ask-SL*point)+" "+ ask+TP*point+" "+"News EA"+" "+magic+" "+(now+Expire*60));
    ticketBuy = OrderSend(NewsPair,OP_BUYLIMIT, lots,price_b,Slippage,price_b-SL*point, price_b+TP*point,"EN EA",magic,now+Expire*60);
    if (ticketBuy < 0) {
        Print(""+"No buy ticket # :(     Error="+GetLastError()+"    Type=OP_BUYLIMIT");
//        return(-2);
    }
It's part of EA. Whan I run this EA I receive:
2008.03.25 20:59:39 My_EA EURUSD,M1: No buy ticket # :( Error=130 Type=OP_BUYLIMIT

It is even when SL is 50 pips.

Help, please...
 

You are trying to OP_BUYLIMIT above current price.

Try with OP_BUYSTOP.

Also, you might need to normalize your prices since they are calculated.

 
phy:

You are trying to OP_BUY above current price.

Try with OP_BUYSTOP.

Also, you might need to normalize your prices since they are calculated.

I'm trying OP_BUYLIMIT above current price.
What do you mean "to normalize"?
 

A buy_limit operation is used to set a price below current price and buy if it goes down there. I think you are misoperating the command.

See NormalizeDouble().

why?

read https://docs.mql4.com/trading/OrderSend carefully...

 
phy:

A buy_limit operation is to set a price below current price and buy if it goes down there. I think you are misoperating the command.

Thanks :) I didn't know that :|
 

Hi!

I've got some similar problem with an order of type Instant Market Sell .

I wrote a sample expert adviser and the problem is this part :

double p = Bid;
int tN = OrderSend(Symbol(),OP_SELL,0.1,p,50,NormalizeDouble(p+1000*Point,Digits),0);
   if(tN > 0){
      Alert("Done");
   }else{
      Alert(ErrorDescription(GetLastError()));
   }

This alerts "invalid stops".

But an order of type OP_SELLLIMIT with exactly same parameters executes with no problem.

I tried different values for stop loss, ranging from 0-Points to 1000-Points and different slippages.

I'm using a demo account with spread 0 and MarketInfo(Symbol(),MODE_STOPLEVEL) returns 0

Help me please!

Thanks a lot

 
 

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 doing mistake?

Reason: