Calculating Unrealized Profit for the account
There are plenty of codes in this forum that you could have fixed your issue if you had only read 1 of them. The line you already suspect is the reason it will not work. And please follow the rules for posting in the forum! Use the src button when posting code, or you wont get any replies from this point (punn intended) haha
there is a function
https://www.mql5.com/en/docs/constants/tradingconstants/positionproperties
in this webpage you will find position_profit
so if you calculate the total for all positions - you will be very near your total
- www.mql5.com
Hi all,
I have been struggling in figuring out how to calculate unrealized net/gross profits for my current account. In other trading platforms there is a property of UnrealizedGrossProfit and UnrealizedNetProfit on the Account object itself. If this does not exist, can you do something like loop through open orders?
double TotalProfit()
{
double totalUnrealizedProfit =
for(int iPos=OrdersTotal()-1; iPos>=0; iPos--)
{//loop end to beginning
if(OrderSelect(iPos)== true) // not sure this works!
{//we found a ticket number
totalUnrealizedProfit += OrderProfit()+OrderSwap()+OrderCommission()); // these functions don't exist!
}
}
return(0.00);
} */