Download MetaTrader 5

OrderSend - Error Code 130 - OP_BUYLIMIT

To add comments, please log in or register
Mark
27
Mark  

Hi,

I know there are similar questions to this one elsewhere on the forum, but none of them seem to solve the problem with my script. I am fairly new to MQL4, so I'm not sure if there's something obvious that I'm doing wrong.

I have simplified my problem down to placing a simple limit order. Whenever I try to place an OP_BUYLIMIT order, I get the error #130. I am using the Alpari UK Demo account. This is my code....

int Limit = 10;
int stoploss = 2000;
int takeprofit = 2000;

double BuyLimitPrice = Ask-(Limit*Point);
double StopPrice = Ask-((Limit+stoploss)*Point);
double TakeProfitPrice = Ask+((-Limit+takeprofit)*Point);

Print(BuyLimitPrice + " Stop: " + StopPrice + " TakeProfit: " + TakeProfitPrice);

int ticket=OrderSend(Symbol(),OP_BUYLIMIT,0.1,NormalizeDouble(BuyLimitPrice,Digits),5,NormalizeDouble(StopPrice,Digits),NormalizeDouble(TakeProfitPrice,Digits),"LimitTest",0,0,Blue);

I have been testing it on GBPUSD and get the following output:

2010.01.18 10:18:47 2009.12.30 23:59 LimitTesting GBPUSD,H1: OrderSend error 130
2010.01.18 10:18:47 2009.12.30 23:59 LimitTesting GBPUSD,H1: 1.60740000 Stop: 1.58740000 TakeProfit: 1.62740000

I have placed the stoploss and take profit values a fair distance away from the current price and the limit order price, so I'm sure there must be something else wrong.

I have also tried setting the stoploss and take profit values to zero, and this gives the same error.

Any help would be greatly appreciated. Thanks in advance.

Mark

Brian Dee - Random Trader
1760
Brian Dee - Random Trader  

Your pending order price is 'too close to market'

Alpari is sub-pip so your value for Limit is only one full pip

Your entry point for a pending order needs to be further away from current price

Good Luck

-BB-

Mark
27
Mark  

Hi BB,

Thanks. That works.

By trail and error, I found that the minimum the value of Limit could be is 30 (3 whole pips). Not sure if this is different for other brokers.

Is there any function that tells you the distance that the limit order needs to be placed away?

Mark

Brian Dee - Random Trader
1760
Brian Dee - Random Trader  

M

Use https://docs.mql4.com/constants/marketinfo with the MODE_STOPLEVEL

NB - This will be in the pipsize of the broker

Viffer
614
Viffer  

I have a similar problem. I have error 130 and I can't track down why. I would really appreciate some pointers.

I've checked the following...

The SL is delivered as a real price rather than pips away.

It's the correct format... a double and it's been normalised.

It's the correct figure.... confirmed by print in the line above the ordersend.

It's an allowable distance ~50pips

It's not the Boston Technologies Bridge refered to in another thread


double sl=NormalizeDouble(shortstop,Digits);
Alert ("SL ", sl, " Bid ",Bid );
OrderSend(Symbol(),OP_SELL,lot,Bid,slip,sl, target);             

I get

Alert: SL 1.4255 Bid 1.4201
OrderSend error 130

I have run out of ideas of where to look next... thanks for any help

V

cloudbreaker
1577
cloudbreaker  
Viffer:

I have a similar problem. I have error 130 and I can't track down why. I would really appreciate some pointers.

I've checked the following...

The SL is delivered as a real price rather than pips away.

It's the correct format... a double and it's been normalised.

It's the correct figure.... confirmed by print in the line above the ordersend.

It's an allowable distance ~50pips

It's not the Boston Technologies Bridge refered to in another thread


I get

Alert: SL 1.4255 Bid 1.4201
OrderSend error 130

I have run out of ideas of where to look next... thanks for any help

V

TP could be causing the stops error. What's the value of target?


CB

Viffer
614
Viffer  
cloudbreaker:

TP could be causing the stops error. What's the value of target?


CB

You found it... TP was miscalculating... Thankyou!!... I was too focused on taking the fault code literally.

V

whroeder1
15566
whroeder1  

mark1808 wrote >>

By trail and error, I found that the minimum the value of Limit could be is 30 (3 whole pips). Not sure if this is different for other brokers.

Is there any function that tells you the distance that the limit order needs to be placed away?

// A pending order price can be no closer to the current price, than this
// amount.  On IBFX it's equal to 30 (3.0 pips.) A TP or SL, can be no
// closer to the order price (open, limit, or stop) or closing price (filled
double // order) than this amount.
minGap.stops    = MarketInfo( Symbol(), MODE_STOPLEVEL )*Point;
Likewise, your constants should be given in pips not points and internally adjusted so it works on any broker.
//---- These are adjusted for 5 digit brokers.
double  pips2points,    // slippage  3 pips    3=points    30=points
        pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
int init()
{
    pips2dbl    = Point;    pips2points = 1;    Digits.pips = 0;    // re-Init
    if (Digits == 3 || Digits == 5) {
        pips2points *= 10;
        pips2dbl    *= 10;
        Digits.pips++;
    }
//...
Also remember for OP_SELL the SL is relative to the Ask price, so it appears on the chart at 3+2(spread) or 50 points at least from the Bid.
nima
8
nima  

Hi!

I've got some similar problem with an order of type Instant Market Sell . It seems I can get help here

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

whroeder1
15566
whroeder1  
Nima:

I've got some similar problem with an order of type Instant Market Sell . It seems I can get help here

I tried different values for stop loss, ranging from 0-Points to 1000-Points and different slippages.
  1. On 5 digit brokers you must adjust TP, SL, AND slippage.
    //++++ These are adjusted for 5 digit brokers.
    int     pips2points;    // slippage  3 pips    3=points    30=points
    double  pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
    int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
    int     init(){
        if (Digits == 5 || Digits == 3){    // Adjust for five (5) digit brokers.
                    pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
        } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
        // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
    
  2. On ECN brokers you must open first and THEN set stops.
    int ticket = OrderSend(..);
    if (ticket < 0) 
        Alert("OrderSend Failed: ",GetLastError());
    else if (!OrderSelect(ticket, , SELECT_BY_TICKET))
        Alert("OrderSelect Failed: ",GetLastError());
    else if (!OrderModify(OrderTicket(), OrderOpenPrice(), ...)
        Alert("OrderModify Failed: ",GetLastError());
    
nima
8
nima  

Thanks for your reply.

But this code has got the same problem. I used your code and just replaced Slippage.Pips with an integer value, same error raised after executing.

For learning purpose, I want to write a simple expert which sends just one instant sell or buy order, and I want to adjust everything according to parameters queried from broker.

Any advice?

123
To add comments, please log in or register