Please help 'Buy OrderSend failed with error #4756'

 

The code below produces the error “Buy OrderSend failed with error #4756”. What is the problem?

I am new to MQL5, so I would appreciate your help.


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   //--- create timer
   EventSetTimer(5); // Execute every 5 seconds
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   //--- destroy timer
   EventKillTimer();
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   double price = SymbolInfoDouble(_Symbol, SYMBOL_BID); // Get current price
   Print("Current price: ", price);

   // Buy condition: when the price is 30 dollars or less
   if(price <= 30.0)
     {
      MqlTradeRequest request;
      MqlTradeResult result;
      ZeroMemory(request);
      ZeroMemory(result);

      request.action = TRADE_ACTION_DEAL;
      request.symbol = _Symbol;
      request.volume = 1.0;
      request.type = ORDER_TYPE_BUY;
      request.price = price;
      request.deviation = 3;
      request.magic = 0;
      request.comment = "Buy order";
      request.type_filling = ORDER_FILLING_IOC; // Modified part
      request.type_time = ORDER_TIME_GTC;

      if(!OrderSend(request, result))
        {
         Print("Buy OrderSend failed with error #", GetLastError());
        }
      else
        {
         Print("Buy order placed successfully");
        }
     }

   // Sell condition: when the price is 40 dollars or more
   if(price >= 40.0)
     {
      for(int i = PositionsTotal() - 1; i >= 0; i--)
        {
         if(PositionSelect(_Symbol))
           {
            Print("Position selected: ", _Symbol);
            if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY)
              {
               MqlTradeRequest request;
               MqlTradeResult result;
               ZeroMemory(request);
               ZeroMemory(result);

               request.action = TRADE_ACTION_DEAL;
               request.symbol = _Symbol;
               request.volume = PositionGetDouble(POSITION_VOLUME);
               request.type = ORDER_TYPE_SELL;
               request.price = price;
               request.deviation = 3;
               request.magic = 0;
               request.comment = "Sell order";
               request.type_filling = ORDER_FILLING_IOC; // Modified part
               request.type_time = ORDER_TIME_GTC;

               if(!OrderSend(request, result))
                 {
                  Print("Sell OrderSend failed with error #", GetLastError());
                 }
               else
                 {
                  Print("Sell order placed successfully");
                 }
              }
           }
           else
           {
             Print("PositionSelect failed for symbol: ", _Symbol);
           }
        }
     }
  }
//+------------------------------------------------------------------+