Positions History

 

In the Tool Box History we have four options to how to present it: Orders, deals, Ordens + deals and positions.

We have HistoryOrdersTotal + HistoryOrderGetTicket to iterate over the orders.

We have HistoryDealsTotal + HistoryDealGetTicket to iterate over the deals.

But we have no HistoryPositionsTotal + HistoryPositionGetTicket  to iterate over the positions.

The best way to do that would be iterate over all orders, getting the ORDER_POSITION_ID and taking care to not repeat?

Any more efficient way to get the list of positions from the history?

 
Use the MQL4-style
#include <MT4Orders.mqh> // https://www.mql5.com/en/code/16006

void OnStart()
{
  for (int i = OrdersHistoryTotal() - 1; i >= 0; i--)
    if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY) && (OrderType() <= OP_SELL))
      OrderPrint();
}
Reason: