To find your mistake, throw out all unnecessary: 'isout', 'way', 'num' ...
//+------------------------------------------------------------------+ //| Profit for the period | //+------------------------------------------------------------------+ double ProfitForPeriod(const datetime from_date,const datetime to_date) { double result=0.0; //--- request trade history HistorySelect(from_date,to_date); //--- uint total=HistoryDealsTotal(); ulong ticket=0; long position_id=0; //--- for all deals for(uint i=0; i<total; i++) // for(uint i=0;i<total;i++) => i #0 - 2016, i #1045 - 2017 { //--- try to get deals ticket if((ticket=HistoryDealGetTicket(i))>0) { //--- get deals properties long deal_type =HistoryDealGetInteger(ticket,DEAL_TYPE); long deal_entry =HistoryDealGetInteger(ticket,DEAL_ENTRY); long deal_magic =HistoryDealGetInteger(ticket,DEAL_MAGIC); double deal_commission =HistoryDealGetDouble(ticket,DEAL_COMMISSION); double deal_swap =HistoryDealGetDouble(ticket,DEAL_SWAP); double deal_profit =HistoryDealGetDouble(ticket,DEAL_PROFIT); string deal_symbol=HistoryDealGetString(ticket,DEAL_SYMBOL); //--- only for current symbol and magic if(deal_magic==InpMagic && deal_symbol==m_symbol.Name()) if(ENUM_DEAL_ENTRY(deal_entry)!=DEAL_ENTRY_IN) if(ENUM_DEAL_TYPE(deal_type)==DEAL_TYPE_BUY || ENUM_DEAL_TYPE(deal_type)==DEAL_TYPE_SELL) result+=(deal_commission+deal_swap+deal_profit); } } //--- return(result); }
An example of working with a trading history:
How can you affirm that I didn't do anything after I said that I did it? That's kinda rude, or maybe your crystal ball is broken.
Yes, I tried removing these "unnecessary things". Anyhow, that's not the point. My question was:
Why my function returns all the properties correctly (even with the "unnecessary things"), and the only property that is not returned correctly is the DEAL_PROFIT?
Do you think you're able to answer my question without showing me another solution / function? Thank you anyways.
Also throw out 'break'
//+------------------------------------------------------------------+ //| Get Deals Profit | //+------------------------------------------------------------------+ double GetDealsProfit(void) { ulong ticket; double profit=0.0; if(HistorySelect(0,TimeCurrent())) { for(int i=HistoryDealsTotal()-1; i>=0; i--) { if((ticket=HistoryDealGetTicket(i))>0) { profit+=HistoryDealGetDouble(ticket,DEAL_PROFIT); } } } return(profit); }
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello.
The following function returns all properties correctly (DEAL_VOLUME, DEAL_TIME... etc), with exception of DEAL_PROFIT.