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()); } }
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:
- Retrieve profit by position, best practice?
- Find related orders and positions
- MT5 Position History Information
Also read the following article ...
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
- www.mql5.com
Print info about a closed position by its position ticket or identifier.
Thank you all))

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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