how convert this funcion mql4 in mql5

 

Hi i  have a code and i use  this library

https://www.mql5.com/en/code/16006

with this include

#include <MT4Orders.mqh> // if there is #include <Trade/Trade.mqh>, add this line AFTER that

#include <MQL4_to_MQL5.mqh> // ONLY for this example

in apart of my code

string formatOrderArrowInfo(int ticket) {
   // Seleziona l'ordine dalla cronologia utilizzando il ticket
   if (!HistoryOrderSelect(ticket)) {
      return "Errore: Impossibile selezionare l'ordine";
   }

   // Recupera le informazioni dell'ordine
   string comment = HistoryOrderGetString(ticket, ORDER_COMMENT);
   int magicNumber = HistoryOrderGetInteger(ticket, ORDER_MAGIC);
   double profit = HistoryOrderGetDouble(ticket, ORDER_PROFIT);  // Use ORDER_PROFIT in History
   double swap = HistoryOrderGetDouble(ticket, ORDER_SWAP);      // Use ORDER_SWAP in History
   double commission = HistoryOrderGetDouble(ticket, ORDER_COMMISSION); // Use ORDER_COMMISSION in History
   double openPrice = HistoryOrderGetDouble(ticket, ORDER_OPEN_PRICE); // Use ORDER_OPEN_PRICE in History
   double closePrice = HistoryOrderGetDouble(ticket, ORDER_CLOSE_PRICE); // Use ORDER_CLOSE_PRICE in History
   string accountCurrency = AccountInfoString(ACCOUNT_CURRENCY);
   double point = SymbolInfoDouble(HistoryOrderGetString(ticket, ORDER_SYMBOL), SYMBOL_POINT);

   // Calcola il numero di pips
   double pips = MathAbs(openPrice - closePrice) / (point * pointsPerPip());

   // Costruisci la stringa di informazione
   return StringConcatenate(
             comment,
             " (",
             magicNumber,
             ")\nP/L: ",
             DoubleToString(profit + swap + commission, 2),
             " ",
             accountCurrency,
             " (",
             DoubleToString(pips, 2),
             " pips)"
          );
}

i have some error in this part

 double profit = HistoryOrderGetDouble(ticket, ORDER_PROFIT);  // Use ORDER_PROFIT in History
   double swap = HistoryOrderGetDouble(ticket, ORDER_SWAP);      // Use ORDER_SWAP in History
   double commission = HistoryOrderGetDouble(ticket, ORDER_COMMISSION); // Use ORDER_COMMISSION in History
   double openPrice = HistoryOrderGetDouble(ticket, ORDER_OPEN_PRICE); // Use ORDER_OPEN_PRICE in History
   double closePrice = HistoryOrderGetDouble(ticket, ORDER_CLOSE_PRICE); // Use ORDER_CLOSE_PRICE in History

not recognize ORDER?PROFIT , ORDER?SWAP ETC...   but how can substitute that  ?

MT4Orders
MT4Orders
  • www.mql5.com
Parallel use of the MetaTrader 4 and MetaTrader 5 order systems.
 
Migrating from MQL4 to MQL5
Migrating from MQL4 to MQL5
  • www.mql5.com
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.
 
thanks i just saw this general  page for convert i ask in specifc my case
 
faustf #:
thanks i just saw this general  page for convert i ask in specifc my case

"saw this general  page " might be not enough, you should have understood - I guess - that in your case you should use deal properties: https://www.mql5.com/en/docs/constants/tradingconstants/dealproperties

Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Deal Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Deal Properties
  • www.mql5.com
A deal is the reflection of the fact of a trade operation execution based on an order that contains a trade request. Each trade is described by...
 
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
 

Hi

You haven’t really used this library in your code. To use them you should use the functions provided in those mqh files to obtain the data about orders. So instead of wrongly using those HIstoryOrderGet..

functions you should try this for example:

MT4_ORDER Res = GetOrderData();

and then get the data from this trade by:

int magicNumber = Res.MagicNumber; etc

But here you should also check out the differences between Positions/Orders and Deals: https://www.mql5.com/en/articles/211 Because you tried to get data about profitand close price  from the order (which are only pending orders) and I believe you meant to get close price and profit from closed positions (so you would have to use Deals to do that). You should use for this other functions from this library or simpler use those functions: HistoryDealGetTicket, HistoryDealGetInteger, HistoryDealGetDouble, HistoryDealGetInteger etc. with proper deal properties.

Have a nice day👍📊

Orders, Positions and Deals in MetaTrader 5
Orders, Positions and Deals in MetaTrader 5
  • www.mql5.com
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.