Failed to open buy order. Error code: 10013

 

Hi guys, 
I have no experience in coding but want to make a simple EA which buys on Bullish Engulfing Candle with TP 40 pips and SL 30 pips as a test. However, there is something wrong with my code and I want some intelligent individual to point out and correct my code please. I am getting this error:

failed prices for XAUUSDx 0.5 [Invalid request]

Failed to open buy order. Error code: 10013


Here is the code: 

//+----------------------------------------------------------------+
// | Engulfing Candle Strategy EA for Gold/USD (15m)        |
// |                               |
// | Author: Bard                         |
// | Date: 2024-01-24                       |
//+----------------------------------------------------------------+

// Expert Initialization Function
int OnInit()
{
    return(INIT_SUCCEEDED);
}

void OnDeinit(const int reason)
{
    // ----
}

void OnTick()
{
    if (getBullishEngulfing()) {
        openBuyOrder();
    }
}

int getBullishEngulfing() {
 datetime time = iTime(_Symbol, PERIOD_CURRENT,1);
    double open1 = iOpen(_Symbol,PERIOD_CURRENT,1);
    double high1 = iHigh(_Symbol,PERIOD_CURRENT,1);
    double low1 = iLow(_Symbol,PERIOD_CURRENT,1);
    double close1 = iClose(_Symbol,PERIOD_CURRENT,1);
    
    double open2 = iOpen(_Symbol,PERIOD_CURRENT,2);
    double high2 = iHigh(_Symbol,PERIOD_CURRENT,2);
    double low2 = iLow(_Symbol,PERIOD_CURRENT,2);
    double close2 = iClose(_Symbol,PERIOD_CURRENT,2);
    

    
    //conditions
    if ( open1 < close1){ //1st Bullish Candle
       if ( open2 > close2){ //2nd Bearish Candle Behind It
       if ( high1 > high2 && low1 < low2){
       if ( close1 > open2 && open1 < close2){
       Print("Bullish Engulfing Found");
       createArrow(time, low1,233,clrGreen);
       return 1;
       
       }
       }
       }
    }
    
    return 0;
      }
      
 //creating arrow
 void createArrow (datetime time, double price, int arrCode, color clr){
      string arrName = " ";
      if (ObjectCreate(0, arrName, OBJ_ARROW,0,time, price)){
          ObjectSetInteger(0, arrName, OBJPROP_ARROWCODE, arrCode);
          ObjectSetInteger(0, arrName, OBJPROP_COLOR,clr);
          ObjectSetInteger(0, arrName, OBJPROP_WIDTH,4);
          
      }
      
      }

void openBuyOrder() {
    double lotSize = 0.5;
    double stopLossPips = 30;
    double takeProfitPips = 40;

   double askPrice = SymbolInfoDouble(_Symbol, SYMBOL_ASK);  // Get current Ask price using SymbolInfoDouble

    double stopLossPrice = NormalizeDouble(askPrice - stopLossPips * Point(), Digits());
    double takeProfitPrice = NormalizeDouble(askPrice + takeProfitPips * Point(), Digits());

 MqlTradeRequest request;
MqlTradeResult result;

request.symbol = _Symbol;
request.type = ORDER_TYPE_BUY;
request.volume = 0.5;
request.price = askPrice;
request.deviation = 3;  // Slippage
request.sl = stopLossPrice;  // Stop loss (will be set later)
request.tp = takeProfitPrice;
request.comment = "Buy Order";
request.magic = 0;
request.type_time = ORDER_TIME_GTC;  // No expiration
request.type_filling = ORDER_FILLING_RETURN;  // Return error if not filled immediately

bool orderSent = OrderSend(request, result);


  if (orderSent) {
  // Extract ticket number from result
  uint ticket = result.retcode;
  Print("Buy order opened successfully. Ticket: ", ticket);

  // Set stop loss using ticket and stopLossPrice... (your remaining code)
} else {
  Print("Failed to open buy order. Error code: ", result.retcode);
}
}
 
Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 
request.action=TRADE_ACTION_DEAL;
request.type_filling = ORDER_FILLING_IOC;  

The other options not supported for type_filling.

Reason: