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 ?
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.
#include <MT4Orders.mqh> // https://www.mql5.com/en/code/16006
double Res = 0;
for (int i = OrdersTotal() - 1; i >= 0; i--)
if (OrderSelect(i, SELECT_BY_POS))
Res += OrderProfit() + OrderSwap() + OrderCommission();