Why HistoryDealsTotal & HistoryOrdersTotal returns bigger number than actual MT5 History Tab?

 

Hi there,

void OnStart() 
  { 
//--- request all the existing history on the account 
   if(!HistorySelect(0, TimeCurrent())) 
     { 
      Print("HistorySelect() failed. Error ", GetLastError()); 
      return; 
     } 
  
//--- get the number of deals in the list and display it in the journal 
   int total=HistoryDealsTotal(); 
   Print("Number of historical deals on the account: ", total); 
  }

Above code is from MQL5 help file  -   returns 38

Changed to:


void OnStart() 
  { 
//--- request all the existing history on the account 
   if(!HistorySelect(0, TimeCurrent())) 
     { 
      Print("HistorySelect() failed. Error ", GetLastError()); 
      return; 
     } 
  
//--- get the number of orders in the list and display it in the journal 
   int total=HistoryOrdersTotal(); 
   Print("Number of historical orders on the account: ", total); 
  }

Returns 37


But when manually counting all history in MT5 History Tab only 18 including first initial Deposit on Demo Account

What am I doing wrong?

How to return number of history which is the same as manually counting MT5 History Tab?

Please help - thank you

 
First of all, do you understand differences between Orders, Deals and Positions?
 

not sure if this might help. but try to limit the history to 1 day like I did here... 

HistorySelect(TimeCurrent() - PeriodSeconds(PERIOD_D1), TimeCurrent() + 10);

Improperly formatted code edited by moderator. Please use the CODE button (Alt-S) when inserting code.

Code button in editor

 
Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 

Please read the following ...

Articles

Orders, Positions and Deals in MetaTrader 5

MetaQuotes, 2011.02.01 16:13

Creating a robust trading robot cannot be done without an understanding of the mechanisms of the MetaTrader 5 trading system. The client terminal receives the information about the positions, orders, and deals from the trading server. To handle this data properly using the MQL5, it's necessary to have a good understanding of the interaction between the MQL5-program and the client terminal.