How to get Profit of the Closed Position by its ticket?

 

I can't get Profit of the closed position, cause the ticket of closed order is different, how can I get it only knowing ticket of the position while opening?

P.S. On mql5

 

Forum on trading, automated trading systems and testing trading strategies

price slippage on pending order

fxsaber, 2022.06.14 07:32

#property script_show_inputs

#include <MT4Orders.mqh> // https://www.mql5.com/en/code/16006

input long inTicket = 0; // Position Ticket

#define PRINT(A) Print(#A + " = " + (string)(A))

void OnStart()
{
  if (OrderSelect(inTicket, SELECT_BY_TICKET))
  {
    OrderPrint();
    
    PRINT(OrderProfit());       
  }
}
 
fxsaber #:
sorry I meant for mql5
 
Dreamcatcher_579 Lvl_126 #:
sorry I meant for mql5

This is MQL5.

 
Dreamcatcher_579 Lvl_126 #: sorry I meant for mql5
fxsaber #: This is MQL5.

The code provided by @fxsaber is using his MT4Orders library which provides a MQL4 like functionality in MQL5.

Using only pure MQL5 code is more complicated. So I suggest reading the following:

Also read the following article ...

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.
 
Print Closed Position
Print Closed Position
  • www.mql5.com
Print info about a closed position by its position ticket or identifier.
 
Thank you all))