loop HistoryDealsTotal() printing zero? or am i wrong here?

 

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;

int totalDeals = HistoryDealsTotal();

    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;

        }

    }

Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Deal Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Deal Properties
  • www.mql5.com
A deal is the reflection of the fact of a trade operation execution based on an order that contains a trade request. Each trade is described by...
 

You need select the history first.


https://www.mql5.com/en/docs/trading/historyselect

Documentation on MQL5: Trade Functions / HistorySelect
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...
 
Samuel Manoel De Souza #:

You need select the history first.


https://www.mql5.com/en/docs/trading/historyselect

thank you, solved it.