How to access the second or third deal in MT5 history ?
Muhammad Elbermawi:
Why don't you store the one found and start searching from there?
Hello friends,
The following function is designed to search the history of the deals then it breaks when it finds the first deal out from below.
Is there a way in MQL5 to find the second or the third deal from below, and extract information from it?
A screenshot to show what I want to do
FYI.
void GetFirstHistory(ulong magic,string symbol,long &type, double &lot, double &profits,int counter = 1) { int cnt = 0; if(HistorySelect(0, TimeCurrent()) == true) { for(int i = HistoryDealsTotal() - 1; i >= 0; i-- ) { ulong ticket = HistoryDealGetTicket(i); if(ticket > 0) { if(HistoryDealGetInteger(ticket, DEAL_MAGIC) == magic && HistoryDealGetString(ticket,DEAL_SYMBOL)==symbol && HistoryDealGetInteger(ticket, DEAL_ENTRY) == DEAL_ENTRY_OUT) { type = HistoryDealGetInteger(ticket, DEAL_TYPE); lot = HistoryDealGetDouble(ticket, DEAL_VOLUME); profits = HistoryDealGetDouble(ticket, DEAL_PROFIT); if(++cnt>=counter)break; } } } } }
Hello friends,
The following function is designed to search the history of the deals then it breaks when it finds the first deal out from below.
Is there a way in MQL5 to find the second or the third deal from below, and extract information from it?
A screenshot to show what I want to do
