Dear Metatraders,
I am trying to write a code in MQL5 that will allow me to calculate the current profit on all my open trades,
In back-testing, the OrdersTotal() is giving me 0 knowing that I have multiple open trades,
Any idea what seems the problem ?
Many Thanks
The problem is you didn't read the documentation.
Do not confuse current pending orders with positions, which are also displayed on the "Trade" tab of the "Toolbox" of the client terminal. An order is a request to conduct a transaction, while a position is a result of one or more deals.
What you need to check is positions, no orders.
I am trying to write a code in MQL5 that will allow me to calculate the current profit on all my open trades,
// MQL4&5-code #include <MT4Orders.mqh> // https://www.mql5.com/en/code/16006 double GetCurrentProfit() { double Res = 0; for (int i = OrdersTotal() - 1; i >= 0; i--) if (OrderSelect(i, SELECT_BY_POS)) Res += OrderProfit() + OrderSwap() + OrderCommission(); return(Res); }
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Dear Metatraders,
I am trying to write a code in MQL5 that will allow me to calculate the current profit on all my open trades,
In back-testing, the OrdersTotal() is giving me 0 knowing that I have multiple open trades,
Any idea what seems the problem ?
Many Thanks