You need select the history first.

Documentation on MQL5: Trade Functions / HistorySelect
- www.mql5.com
Retrieves the history of deals and orders for the specified period of server time. Parameters from_date [in] Start date of the request...

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 wanna loop through history deals but why am I getting print zero here? i tried HistoryDealsTotal() and HistoryOrdersTotal() both printing zero, what seems to be wrong here? tks all.
double totalProfitLoss = 0.0;
Print("Total historical deals__:", totalDeals);
for (int i = totalDeals - 1; i >= 0; i--)
{
// Select the deal by index
if (HistoryDealSelect(i))
{
ulong ticket = HistoryDealGetTicket(i);
double profit = HistoryDealGetDouble(ticket, DEAL_PROFIT);
double commission = HistoryDealGetDouble(ticket, DEAL_COMMISSION);
double swap = HistoryDealGetDouble(ticket, DEAL_SWAP);
Print("Deal Ticket__:", ticket," Profit__:", profit," Commission__:", commission," Swap__:", swap);
totalProfitLoss += profit + commission + swap;
}
}