Error 4755 ERR_TRADE_DEAL_NOT_FOUND
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
You must first select the Deal History with HistoryDealSelect(). Take a close look at the example code in the documentation for OnTradeTransaction().
... case TRADE_TRANSACTION_DEAL_ADD: // adding a trade { ulong lastDealID =trans.deal; ENUM_DEAL_TYPE lastDealType =trans.deal_type; double lastDealVolume=trans.volume; //--- Trade ID in an external system - a ticket assigned by an exchange string Exchange_ticket=""; if(HistoryDealSelect(lastDealID)) Exchange_ticket=HistoryDealGetString(lastDealID,DEAL_EXTERNAL_ID); if(Exchange_ticket!="") Exchange_ticket=StringFormat("(Exchange deal=%s)",Exchange_ticket); PrintFormat("MqlTradeTransaction: %s deal #%I64u %s %s %.2f lot %s",EnumToString(trans_type), lastDealID,EnumToString(lastDealType),trans_symbol,lastDealVolume,Exchange_ticket); } ...
Good day Fernando,
Thanks for the help, that worked.
Hi guys,
i have same issue here and i do selecting history before call for ticket and selecting deal.
if (!HistorySelect(D'1970.01.01', TimeCurrent())) {Print("History selection failed!"); return;} else Print("History selection is OK! # of Deals:", HistoryDealsTotal()); int tot = HistoryDealsTotal()-1; for (int i=0; i<=tot; i++) { ulong ticket = HistoryDealGetTicket(i); //Print(i," ticket: ",ticket," "); ResetLastError(); if (HistoryDealSelect(ticket)) { Print(i, " ---- ", HistoryDealGetDouble(ticket, DEAL_PROFIT)); } else PrintFormat("%i HistoryDealSelect(%I64u) failed. Error %d",i, ticket, GetLastError()); }
and here is output↓

As you see there is not any ticket number for different indexes!
if I change code to this one↓, we can see different ticket numbers for Deals but can not select those deals by ticket number.
if (!HistorySelect(D'1970.01.01', TimeCurrent())) {Print("History selection failed!"); return;} else Print("History selection is OK! # of Deals:", HistoryDealsTotal()); int tot = HistoryDealsTotal()-1; for (int i=0; i<=tot; i++) { ulong ticket = HistoryDealGetTicket(i); Print(i," ticket: ",ticket," "); //ResetLastError(); //if (HistoryDealSelect(ticket)) // { // Print(i, " ---- ", HistoryDealGetDouble(ticket, DEAL_PROFIT)); // } //else PrintFormat("%i HistoryDealSelect(%I64u) failed. Error %d",i, ticket, GetLastError()); }
and result is like this↓:

what am i doing wrong?!
Hi,
I need some help to resolve the error I'm getting from from function HistoryDealGetInteger.
With the following code I'm trying to determine two things when a new position opened and when one closed.
HistoryDealGetInteger keeps returning 0 no matter the entry type. Also when I add an if not statement and print the last error I get error 4755.
I'm not sure if I'm doing something wrong or if the function just does not work within this event.
I'm also open to any other suggestions of methods that determines newly opened and newly closed position.