Download MetaTrader 5
To add comments, please log in or register
Publish your article. We will translate it into other languages!
Automated-Trading
Admin
97631
Automated-Trading 2012.11.15 12:14 

CTradeStatistics:

Class for the calculation of the ENUM_STATISTICS enumeration parameters

Author: Andrey Voytenko

Young Ho Seo
15523
Young Ho Seo 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 ???

Jeremy Scott
8764
Jeremy Scott 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

If your question is more complex please add details ;) 

Pasi Hakamaki
4409
Pasi Hakamaki 2014.07.26 04:04  
Thank you Andrey! Excellent work.
Dua Yong Rew
5397
Dua Yong Rew 2014.10.07 14:36  
no average holding time?
Sasa Pucko
399
Sasa Pucko 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
  {
   NOVALUE=0, //<---- added
   WIN=1,
   LOSS
  };

Gustavo Hennemann
60
Gustavo Hennemann 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?

Thanks in advance.

/
To add comments, please log in or register