Error # 130

 
for(i = 0; trade_flag != 1 && SSL_flag != 1 && BSL_flag != 1 && SSL_flag != 2 && BSL_flag != 2 && i < 100; i++)
    {
        if(//<condition>)
        {
        trade_flag = 1;
         //<DECLARING BUY PRICES, SELL PRICES>
                
        Print("Buy Abv ",DoubleToStr(buy_price,4),", TGT - ", DoubleToStr(btgt,4),", SL - ",DoubleToStr(buy_SL,4));
        Print("Sell Below ",DoubleToStr(sell_price,4),", TGT - ", DoubleToStr(stgt,4),", SL - ",DoubleToStr(sell_SL,4)); 
        
        RefreshRates();        
        if(Ask<buy_price) buy_type = 4; // BUYSTOP
        if(Ask>buy_price) buy_type = 2; //BUYLIMIT
        if(Ask==buy_price) 
        {
        buy_type = 0; //OP-BUY
        RefreshRates();
        buy_price = Ask;
        buy_SL = NULL;
        btgt = NULL;
        }
        
        int buy_ticket = OrderSend(Symbol(), buy_type, 1.0, buy_price, 1, buy_SL, btgt, "Success #", 0, close_time, CLR_NONE);
        int buy_checker = GetLastError();
        Print("Buy Error Code : ", buy_checker);
        
        if(buy_checker != 0 || buy_checker!= 1)
        for(int loop = 0; loop < 11 && (buy_checker == 130 || buy_checker == 146 || buy_checker == 141); loop++)  
        {
        RefreshRates();
        buy_ticket = OrderSend(Symbol(), OP_BUY, 1.0, Ask, 1, NULL, NULL, "Success #", 0, NULL, CLR_NONE);
        buy_checker = GetLastError();
        Print("Special Buy Error #", buy_checker);
        BSL_flag = 1;
        }
        
        if(buy_checker==0||buy_checker==1) Alert(Symbol(),": Buy Order Placed Successfully");
        else Alert(Symbol(),": Buy order failed. Error #",buy_checker);
      
      //`````````````````````````````````````````````````````````````````````````````````````````````````````````````````` 
        if(Bid<sell_price) sell_type = 3; //OP-SELLLIMIT
        if(Bid>sell_price) sell_type = 5; //OP-SELLSTOP
        if(Bid==sell_price) 
        {
        sell_type = 1; //OP_BUY
        RefreshRates();        
        sell_price = Bid;
        sell_SL = NULL;
        stgt = NULL;
        }
        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();
             
        for(loop = 0; loop < 11 && ((sell_checker != 0 && sell_checker != 1) 
        && (sell_checker == 130 || sell_checker == 146 || sell_checker == 141)); loop++) 
        {
        RefreshRates();
        sell_ticket = OrderSend(Symbol(), 1, 1.0, Bid, 1, NULL, NULL, "Success #", 0, NULL, CLR_NONE);
        sell_checker = GetLastError();
        SSL_flag = 1;
        }
        
        if(sell_checker==0||sell_checker==1) Alert(Symbol(),": Sell Oder Placed Successfully");
        else Alert(Symbol(),": Sell order failed. Error #",sell_checker);
        
       }
    } 
    
    if(BSL_flag == 1)
    {
      if((OrderModify(buy_ticket, NULL, sell_bk, btgt_bk, NULL, NULL))== true)
      {
      BSL_flag = 2;
      Print("Buy Order Modified");
      }
    }
    
    if(SSL_flag == 1)
    {
      if((OrderModify(sell_ticket, NULL, buy_bk, stgt_bk, NULL, NULL)) == true)
      {
      SSL_flag = 2;
      Print("Sell Order Modified");
      }
    }
Here is the code to handle Error#130
Can anyone suggest corrections here?
 
You don't need to "handle" error 130 . . . place your trade correctly and you will not have an error 130.
 
RaptorUK:
You don't need to "handle" error 130 . . . place your trade correctly and you will not have an error 130.


You didn't get me. Open prices are EA generated. So it is not possible to avoid error #130 all the time.

Most of the time it gives open price very nearer to the Ask/Bid. I tried a solution for that here.

 
krishna_gopal_2:


You didn't get me. Open prices are EA generated. So it is not possible to avoid error #130 all the time.

Yes, it is possible to avoid error 130 ALL the time . . . your EA is coded wrong.
 
  1. OrderSend(Symbol(), 1, 1.0, Bid, 1, NULL, NULL, "Success #", 0, NULL, C...
    TP and SL are doubles not STRINGS. Use zeros or #define NO_SL 0
  2. On ECN brokers, you must open first and THEN set stops.
  3. if(Bid<sell_price) sell_type = 3; //OP-SELLLIMIT
    if(Bid>sell_price) sell_type = 5; //OP-SELLSTOP
    You can not open pending order closer than MarketInfo(chart.symbol, MODE_STOPLEVEL)*Point
  4. if((OrderModify(buy_ticket, NULL, sell_bk, btgt_bk, NULL, NULL))== true)
    NULL is not a valid price, datetime, or color.
    //++++ 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());
         */

  5. trade_flag != 1 && SSL_flag != 1 && BSL_flag != 1 && SSL_flag != 2 && BSL_flag != 2 
    This means SSL_flag and BSL_flag must be not 1 or 2. Do you mean that or did you mean (SSL != 1 and BSL != 1) or (SSL !=2 and BSL != 2) or some other combinations.
  6. Don't hard code numbers. what does SSL_flag == 1 mean.
    #define SSL_xxxx 1
    #define SSL_yyyy 2
    #define BSL_xxxx 1
    #define BSL_yyyy 2
    trade_flag != 1 && SSL_flag != SSL_xxxx && BSL_flag != BSL_xxxx && SSL_flag != SSL_yyyy && BSL_flag != BSL_yyyy 
  7. If you use understandable names and bools you simplify your code
    //trade_flag != 1 && SSL_flag != 1 && BSL_flag != 1 && SSL_flag != 2 && BSL_flag != 2 
    bool isTradingAllowed = true;
    :
    isTradingAllowed && SSL_flag != 1 && BSL_flag != 1 && SSL_flag != 2 && BSL_flag != 2 

 
WHRoeder:
  1. TP and SL are doubles not STRINGS. Use zeros or #define NO_SL 0
  2. On ECN brokers, you must open first and THEN set stops.
  3. You can not open pending order closer than MarketInfo(chart.symbol, MODE_STOPLEVEL)*Point
  4. NULL is not a valid price, datetime, or color.
  5. This means SSL_flag and BSL_flag must be not 1 or 2. Do you mean that or did you mean (SSL != 1 and BSL != 1) or (SSL !=2 and BSL != 2) or some other combinations.
  6. Don't hard code numbers. what does SSL_flag == 1 mean.
  7. If you use understandable names and bools you simplify your code

Very useful tips friends. I am a trader with little bit programming knowledge.

This is what I expected. Thanks A Lot.

Reason: