Cannot succeed Error #130

 

Dear All,

I am here again for your help. I tried different methods to succeed Error #130. I couldnt place orders when the price is near to Ask or Bid.

Here is one of my technique. Can any one suggest alternate method or changes to be made that will workout.

Thanks in advance.

if(Bid<sell_price) sell_type = 3;
if(Bid>sell_price) sell_type = 5;
if(Bid==sell_price) sell_type = 1;
int sell_ticket = OrderSend(Symbol(), sell_type, 1.0, sell_price, 1, sell_SL, stgt, "Success #", 0, close_time, CLR_NONE);
int sell_checker = GetLastError();
        
if(sell_checker != 0 || sell_checker != 1)       
for(loop = 0; loop < 11 && (sell_checker == 130 || sell_checker == 146 || sell_checker == 141); loop++) 
    {
    Sleep(3500);
    Print("Sleep(3.5 Sec)");
    sell_ticket = OrderSend(Symbol(), sell_type, 1.0, sell_price, 1, sell_SL, stgt, "Success #", 0, close_time, CLR_NONE);
    sell_checker = GetLastError();
    }
        
if(sell_checker==0||sell_checker==1) Alert(Symbol(),": Sell Oder Placed Successfully");
else Alert(Symbol(),": Sell order failed. Error #",sell_checker);

At last i am getting again the same error even after the Sleep.

 

You need to check the ticket before you check for an error . . . even if the Order is OK there may be an error from somewhere else in the code . . .

If the Order fails the ticket will be -1 . . . from the documentation "Returns number of the ticket assigned to the order by the trade server or -1 if it fails."

So . . . if (sell_ticket == -1) then check for the error

Read, understand and follow this: Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial

 
RaptorUK:

You need to check the ticket before you check for an error . . . even if the Order is OK there may be an error from somewhere else in the code . . .

If the Order fails the ticket will be -1 . . . from the documentation "Returns number of the ticket assigned to the order by the trade server or -1 if it fails."

So . . . if (sell_ticket == -1) then check for the error

Read, understand and follow this: Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial


fine. But order is not placed as the ask/bid is very close to the open price. How can I do that in such a situation?
 
krishna_gopal_2:

fine. But order is not placed as the ask/bid is very close to the open price. How can I do that in such a situation?
You can place a Market order AT Ask/Bid
 
RaptorUK:
You can place a Market order AT Ask/Bid


By doing that, actual process will not be done.

So I have to place at exact sell_price/buy_price as per my calculation.

Is there any other method?

 
krishna_gopal_2:


By doing that, actual process will not be done.

So I have to place at exact sell_price/buy_price as per my calculation.

Is there any other method?

You have to place orders in accordance with the FreezeLevel and StopLevel that your Broker sets . . . if you don't like those values find a Broker with values that you do like.
 
if(Bid<sell_price) sell_type = 3;
if(Bid>sell_price) sell_type = 5;
if(Bid==sell_price) sell_type = 1;
int sell_ticket = OrderSend(Symbol(), sell_type, 1.0, sell_price, 1, sell_SL, stgt, "Success #", 0, close_time, CLR_NONE);
  1. Don't hard code numbers 1, 3, 5. Use OP_SELL, OP_SELLLIMIT so you/we can understand the code.
  2. You can't open a pending order closer to market than stop level. Show the rest of the code.
  3. Doubles rarely compare equal.
  4. EA's must adjust tp, sl, AND slippage for 4/5 digit brokers
  5. On ECN brokers you must open first and THEN set stops.
  6. Always test return codes so you find out WHY
  7. You must refresh your variable after a sleep as sell_price and Bid will be wrong (op_sell)
//++++ These are adjusted for 5 digit brokers.
int     pips2points;    // slippage  3 pips    3=points    30=points
double  pips2dbl;       // Stoploss 15 pips    0.015      0.0150
int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
int     init(){                                                     OptParameters();
     if (Digits % 2 == 1){      // DE30=1/JPY=3/EURUSD=5 https://www.mql5.com/en/forum/135345
                pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
    } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
//---- These are adjusted for 5 digit brokers.
    /* On ECN brokers you must open first and THEN set stops
    int ticket = OrderSend(..., 0,0,...)
    if (ticket < 0)
       Alert("OrderSend failed: ", GetLastError());
    else if (!OrderSelect(ticket, SELECT_BY_TICKET))
       Alert("OrderSelect failed: ", GetLastError());
    else if (!OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0)
       Alert("OrderModify failed: ", GetLastError());
     */
 
WHRoeder:
  1. Don't hard code numbers 1, 3, 5. Use OP_SELL, OP_SELLLIMIT so you/we can understand the code.
  2. You can't open a pending order closer to market than stop level. Show the rest of the code.
  3. Doubles rarely compare equal.
  4. EA's must adjust tp, sl, AND slippage for 4/5 digit brokers
  5. On ECN brokers you must open first and THEN set stops.
  6. Always test return codes so you find out WHY
  7. You must refresh your variable after a sleep as sell_price and Bid will be wrong (op_sell)

Thanks friend. Please tell me how to update(refresh) the Bid/Ask in the middle of the start function.
 
krishna_gopal_2:

Thanks friend. Please tell me how to update(refresh) the Bid/Ask in the middle of the start function.
Erm . . RefreshRates()
Reason: