MQL5 HistoryDealGetTicket()
Returns the ticket of the deal at a place in the loaded history, and selects that deal for the history deal functions.
Risk warning: CFDs and spread bets are complex instruments and come with a high risk of losing money rapidly due to leverage. You can lose money on these products, and each provider publishes its own loss figure under FCA rules. You should consider whether you understand how they work and whether you can afford to take the high risk of losing your money. Automated and API trading can amplify losses through bugs, connectivity failures and runaway orders.
This is an MQL5 function, not an HTTP endpoint. It has no method, no path and no address to send a request to: it runs inside the MetaTrader 5 terminal, in a program written in MQL5.
The page says HistorySelect() or HistorySelectByPosition() has to be called first to load the history.
Signature
The form of the call on the vendor's page, with the vendor's comments taken out.
ulong HistoryDealGetTicket( int index )
Arguments
| Name | Type | Description |
|---|---|---|
| indexrequired | int | The deal's number in the list of deals. |
Return value
- Type
- ulong
- What comes back
- The ticket, or 0 when the function fails.
Sample
Written by this site from the signature and arguments recorded on this page. It has not been run against a terminal, a server or an account, and the values in it are placeholders. It holds no credential and needs none: the program runs inside a terminal that is already logged in to an account. Nothing is entered on this site.
void OnStart()
{
if(!HistorySelect(D'2026.01.01',TimeCurrent()))
return;
for(int i=0; i<HistoryDealsTotal(); i++)
{
ulong ticket=HistoryDealGetTicket(i);
if(ticket>0)
PrintFormat("#%I64u %s %.2f lots, profit %.2f",ticket,HistoryDealGetString(ticket,DEAL_SYMBOL),HistoryDealGetDouble(ticket,DEAL_VOLUME),HistoryDealGetDouble(ticket,DEAL_PROFIT));
}
}