Can u check where's Problem in my code MQL5

 

hi.. i wanna make  EA will Close Order 1 by 1 from frist order , this code mql4 is succses , but when i try to mql5 with same way, im always get message "failed prices for  0 [Invalid request]"

this code from  Mql4 .. 

void CloseOrderPartial2() // Close partial Buy
{
    int orderstotal = OrdersTotal();
    int orders = 0;
    int ordticket[300];

    for (int i = 0; i < orderstotal; i++)
    {
        bool sel = OrderSelect(i, SELECT_BY_POS, MODE_TRADES);

        if (OrderType() != OP_BUY || OrderSymbol() != Symbol() || OrderComment() != CommentOrder)
        {
            continue;
        }

        ordticket[orders] = OrderTicket();
        orders++;
    }

    if (orders > 1)
    {
        ArrayResize(ordticket, orders);
        ArraySort(ordticket);
    }

    if (orders > 0)
    {
        if (OrderSelect(ordticket[0], SELECT_BY_TICKET) == true)
        {
            double lotToClose = OrderLots();
            {
                bool kret = OrderClose(OrderTicket(), lotToClose, OrderClosePrice(), Max_Slippage, Green);
                
                    
            }
        }
        orders = 0;
        RestartAllElement();
    }
}

this code from Mql5

void CloseOrderPartial2() // Close partial Buy
  {

   int totalOrders = PositionsTotal(); // Total order saat ini
   int orders = 0;
   ulong ordticket[300];

   for(int i = totalOrders - 1; i >= 0; i--)
     {
      if(PositionGetTicket(i) > 0)
        {
         string positionComment = PositionGetString(POSITION_COMMENT);
         string positionSymbol = PositionGetSymbol(i);

         if(PositionGetInteger(POSITION_TYPE) != POSITION_TYPE_BUY || positionSymbol != Symbol() || positionComment != CommentOrder)
           {
            continue;
           }

         ordticket[orders] = PositionGetInteger(POSITION_TICKET);
         orders++;

         if(orders >= ArraySize(ordticket))
            break; // Keluar dari loop jika ukuran array telah mencapai batas maksimum
        }
     }


   if(orders > 0)
     {
      ArraySort(ordticket); // Lakukan ArraySort setelah mengumpulkan tiket

      if(PositionSelectByTicket(ordticket[0]))
        {
         double lotToClose = PositionGetDouble(POSITION_VOLUME);

         MqlTradeRequest request;
         request.action = TRADE_ACTION_DEAL;
         request.symbol = Symbol();
         request.volume = lotToClose;
         request.price = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
         request.deviation = 5;

         MqlTradeResult result;
         if(OrderSend(request, result))
           {
            Print("Order closed successfully. Order ticket: ", result.order);
           }
         else
           {
            Print("Failed to close order: ", GetLastError());
           }
        }

      orders = 0;
      RestartAllElement();
     }
  }

Can u tell me where's wrong with MQl5 Code ?... thank you

 
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
 
  • Usually people who can't code don't receive free help on this forum.
  • If you show your attempts and describe your problem clearly, you will most probably receive an answer from the community. Use the CODE button (Alt-S) when inserting code.
  • To learn MQL programming, you can research the many available Articles on the subject, or examples in the Codebase, as well as reference the online Book and Documentation
  • If you do not want to learn to code, that is not a problem. You can either look at the Codebase if something free already exists, or in the Market for paid products (also sometimes free). However, recommendations or suggestions for Market products are not allowed on the forum, so you will have to do your own research.
  • Finally, you also have the option to hire a programmer in the Freelance section.
 

Articles

Migrating from MQL4 to MQL5

Sergey Pavlov, 2010.05.17 13:32

This article is a quick guide to MQL4 language functions, it will help you to migrate your programs from MQL4 to MQL5. For each MQL4 function (except trading functions) the description and MQL5 implementation are presented, it allows you to reduce the conversion time significantly. For convenience, the MQL4 functions are divided into groups, similar to MQL4 Reference.

Articles

Cross-Platform Expert Advisor: Orders

Enrico Lambino, 2016.09.16 10:55

MetaTrader 4 and MetaTrader 5 uses different conventions in processing trade requests. This article discusses the possibility of using a class object that can be used to represent the trades processed by the server, in order for a cross-platform expert advisor to further work on them, regardless of the version of the trading platform and mode being used.

Articles

Orders, Positions and Deals in MetaTrader 5

MetaQuotes, 2011.02.01 16:13

Creating a robust trading robot cannot be done without an understanding of the mechanisms of the MetaTrader 5 trading system. The client terminal receives the information about the positions, orders, and deals from the trading server. To handle this data properly using the MQL5, it's necessary to have a good understanding of the interaction between the MQL5-program and the client terminal.