I have found that there is an issue with HistoryDealsTotal() while using the optimization algorithms of the tester.
During a normal backtest everything's fine, but in an optimization session, during the initialization phase of the EA, HistoryDealsTotal() returns the number of deals from the previous run of the EA. Later on, during the trading phase, HistoryDealsTotal() starts at 0 again.
I ran into this issue through the following code snippet:
The way around this, is to initialize with 0 instead, but still I would be pleased with an official reply to this issue, because to me it looks like some internal variables are reset too late.
Thanks in advance!
I know this is old question, but someone may be come across.
Use HistorySelect before calling HistoryDealsTotal.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I have found that there is an issue with HistoryDealsTotal() while using the optimization algorithms of the tester.
During a normal backtest everything's fine, but in an optimization session, during the initialization phase of the EA, HistoryDealsTotal() returns the number of deals from the previous run of the EA. Later on, during the trading phase, HistoryDealsTotal() starts at 0 again.
I ran into this issue through the following code snippet:
The way around this, is to initialize with 0 instead, but still I would be pleased with an official reply to this issue, because to me it looks like some internal variables are reset too late.
Thanks in advance!