Publish your article. We will translate it into other languages!
97631
2012.11.15 12:14
Class for the calculation of the ENUM_STATISTICS enumeration parameters

Author: Andrey Voytenko

15523
2014.04.19 03:19

I found this code can't calculate any statistics related to equity drawdown. Anyone has a success to calculate equity drawdown with their own code ???

8764
2014.04.21 09:25

What do you mean?  I must be misunderstanding your question because this simple answer can't possibly be what you are looking for is it? --->  Equity - Balance = { draw-down if negative, profit if positive } pretty simple calculation.  with MT5 trade classes you can create an account object CAccountInfo acc;  acc is the created account info object giving you quick access to all account detail functions. then do this acc.Equity()-acc.Balance().    Well to be honest you can use an even simpler code acc.Profit().  If positive is profit, if negative is draw-down right?  Negative equity profit is the same as draw-down.  Profit() is the difference between equity and balance

4409
2014.07.26 04:04
Thank you Andrey! Excellent work.
5397
2014.10.07 14:36
no average holding time?
399
2014.12.11 15:41

perfect work!

if you want to avoid to get compile warnings

you need to add null element to enum deal_result:

//+------------------------------------------------------------------+
//|   deal result                                                    |
//+------------------------------------------------------------------+
enum deal_result
{
WIN=1,
LOSS
};

60
2017.01.25 15:44

Hello,

I'm using the class CTradeStatistics to get some specific statistics about the trades, but, in certain moment I got the error "zero divide in 'ctradestatistics.mqh'".

Investigating the situation, I discovered in the code:

for(int i=1; i<limit; i++)
{
if(m_balance_data.At(i)!=0.0)
{
HPR[i-1]=m_balance_data.At(i)/m_balance_data.At(i-1);
m_ahpr+=HPR[i-1];
}
}

that, the "m_balance_data.At(i-1)" could be zero, eventually.

So, I changed to:

for(int i=1; i<limit; i++)
{
if(m_balance_data.At(i)!=0.0)
{
if(m_balance_data.At(i-1)==0){
HPR[i-1]=1;
}
else{
HPR[i-1]=m_balance_data.At(i)/m_balance_data.At(i-1);
}
m_ahpr+=HPR[i-1];
}
}

Is correct to assume that when the balance is 0, the HPR is equal to 1?