Download MetaTrader 5
MQL5 ReferenceTrade FunctionsHistorySelectByPosition 

HistorySelectByPosition

Retrieves the history of deals and orders having the specified position identifier.

bool  HistorySelectByPosition(
   long   position_id     // position identifier - POSITION_IDENTIFIER
   );

Parameters

position_id

[in]  Position identifier that is set to every executed order and every deal.

Return Value

It returns true if successful, otherwise returns false.

Note

Do not confuse orders of a trading history with current pending orders that appear on the "Trade" tab of the "Toolbox" bar. The list of orders that were canceled or have led to a transaction, can be viewed in the "History" tab of "Toolbox" of the client terminal.

HistorySelectByPosition() creates in a mql5 program a list of orders and a list of deals with a specified position identifier for further reference to the elements of the list using the appropriate functions. To know the size of the list of deals, use function HistoryDealsTotal(), the size of the list of orders in the history can be obtained using HistoryOrdersTotal(). To run through elements of the orders list, use HistoryOrderGetTicket(), for elements of the deals list - HistoryDealGetTicket().

After using HistoryOrderSelect(), list of history orders available to the mql5 program is reset and filled again with the found order, if search of an order by its ticket was successful. The same refers to the list of deals available to the mql5 program - it is reset by function HistoryDealSelect() and is filled out again if a deal was found successfully by the ticket number.

See also

HistorySelect(), HistoryOrderGetTicket(), Order Properties


Updated: 2015.12.03