Download MetaTrader 5

Libraries: CTradeStatistics

To add comments, please log in or register
Automated-Trading
Admin
108383
Automated-Trading  

CTradeStatistics:

Class for the calculation of the ENUM_STATISTICS enumeration parameters

Author: Andrey Voytenko

Young Ho Seo
24657
Young Ho Seo  

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

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
7288
Pasi Hakamaki  
Thank you Andrey! Excellent work.
Dua Yong Rew
5536
Dua Yong Rew  
no average holding time?
Sasa Pucko
398
Sasa Pucko  

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
222
Gustavo Hennemann  

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.

SASAN Morady Sarju
238
SASAN Morady Sarju  

Thanks for great work.can you add calculate correlation(profit,MFE) , correlation(profit,MAE) ,correlation(MFE,MAE)   in Class?

Anthony Garot
178
Anthony Garot  

A quicker way to get the Z-score percent. No looping.

double CTradeStatistics::CalcZScorePercent(double z_score)
  {
   int total=ArrayRange(Laplas,0);
   double value=NormalizeDouble(MathAbs(z_score),2);

   int index = (int) (value*100.0);

   if ( index < total )
     {
       return Laplas[index][1];
     }

   return(0);
  }
Anthony Garot
178
Anthony Garot  

This adds several more entries to the Laplas multidimensional array, i.e. entries 3.02 to 3.70.

I only had access to 4 digits of precision.

const double Laplas[][2]=
{
   {0.00,0.00000},{0.01,0.00798},{0.02,0.01596},{0.03,0.02393},{0.04,0.03191},{0.05,0.03988},
   {0.06,0.04784},{0.07,0.05581},{0.08,0.06376},{0.09,0.07171},{0.10,0.07966},{0.11,0.08759},
   {0.12,0.09552},{0.13,0.10348},{0.14,0.11134},{0.15,0.11924},{0.16,0.12712},{0.17,0.13499},
   {0.18,0.14285},{0.19,0.15069},{0.20,0.15852},{0.21,0.16633},{0.22,0.17413},{0.23,0.18191},
   {0.24,0.18967},{0.25,0.19741},{0.26,0.20514},{0.27,0.21284},{0.28,0.22052},{0.29,0.22818},
   {0.30,0.23582},{0.31,0.24344},{0.32,0.25103},{0.33,0.25860},{0.34,0.26614},{0.35,0.27366},
   {0.36,0.28115},{0.37,0.28862},{0.38,0.29605},{0.39,0.30346},{0.40,0.31084},{0.41,0.31819},
   {0.42,0.32552},{0.43,0.33280},{0.44,0.34006},{0.45,0.34729},{0.46,0.35448},{0.47,0.36164},
   {0.48,0.36877},{0.49,0.37587},{0.50,0.38292},{0.51,0.38995},{0.52,0.39694},{0.53,0.40389},
   {0.54,0.41080},{0.55,0.41768},{0.56,0.42452},{0.57,0.43132},{0.58,0.43809},{0.59,0.44481},
   {0.60,0.45149},{0.61,0.45814},{0.62,0.46474},{0.63,0.47131},{0.64,0.47783},{0.65,0.48431},
   {0.66,0.49075},{0.67,0.49714},{0.68,0.50350},{0.69,0.50981},{0.70,0.51607},{0.71,0.52230},
   {0.72,0.52848},{0.73,0.53461},{0.74,0.54070},{0.75,0.54675},{0.76,0.55275},{0.77,0.55870},
   {0.78,0.56461},{0.79,0.57047},{0.80,0.57629},{0.81,0.58206},{0.82,0.58778},{0.83,0.59346},
   {0.84,0.59909},{0.85,0.60468},{0.86,0.61021},{0.87,0.61570},{0.88,0.62114},{0.89,0.62653},
   {0.90,0.63188},{0.91,0.63718},{0.92,0.64243},{0.93,0.64763},{0.94,0.65278},{0.95,0.65789},
   {0.96,0.66294},{0.97,0.66795},{0.98,0.67291},{0.99,0.67783},{1.00,0.68269},{1.01,0.68750},
   {1.02,0.69227},{1.03,0.69699},{1.04,0.70166},{1.05,0.70628},{1.06,0.71086},{1.07,0.71538},
   {1.08,0.71986},{1.09,0.72429},{1.10,0.72867},{1.11,0.73300},{1.12,0.73729},{1.13,0.74152},
   {1.14,0.74571},{1.15,0.74986},{1.16,0.75395},{1.17,0.75800},{1.18,0.76200},{1.19,0.76595},
   {1.20,0.76986},{1.21,0.77372},{1.22,0.77754},{1.23,0.78130},{1.24,0.78502},{1.25,0.78870},
   {1.26,0.79233},{1.27,0.79592},{1.28,0.79945},{1.29,0.80295},{1.30,0.80640},{1.31,0.80980},
   {1.32,0.81316},{1.33,0.81648},{1.34,0.81975},{1.35,0.82298},{1.36,0.82617},{1.37,0.82931},
   {1.38,0.83241},{1.39,0.83547},{1.40,0.83849},{1.41,0.84146},{1.42,0.84439},{1.43,0.84728},
   {1.44,0.85013},{1.45,0.85294},{1.46,0.85571},{1.47,0.85844},{1.48,0.86113},{1.49,0.86378},
   {1.50,0.86639},{1.51,0.86696},{1.52,0.87149},{1.53,0.87398},{1.54,0.87644},{1.55,0.87886},
   {1.56,0.88124},{1.57,0.88358},{1.58,0.88589},{1.59,0.88817},{1.60,0.89040},{1.61,0.89260},
   {1.62,0.89477},{1.63,0.89690},{1.64,0.89899},{1.65,0.90106},{1.66,0.90309},{1.67,0.90508},
   {1.68,0.90704},{1.69,0.90897},{1.70,0.91087},{1.71,0.91273},{1.72,0.91457},{1.73,0.91637},
   {1.74,0.91814},{1.75,0.91988},{1.76,0.92159},{1.77,0.92327},{1.78,0.92492},{1.79,0.92655},
   {1.80,0.92814},{1.81,0.92970},{1.82,0.93124},{1.83,0.93275},{1.84,0.93423},{1.85,0.93569},
   {1.86,0.93711},{1.87,0.93852},{1.88,0.93989},{1.89,0.94124},{1.90,0.94257},{1.91,0.94387},
   {1.92,0.94514},{1.93,0.94639},{1.94,0.94762},{1.95,0.94882},{1.96,0.95000},{1.97,0.95116},
   {1.98,0.95230},{1.99,0.95341},{2.00,0.95450},{2.01,0.95557},{2.02,0.95662},{2.03,0.95764},
   {2.04,0.95865},{2.05,0.95964},{2.06,0.96060},{2.07,0.96155},{2.08,0.96247},{2.09,0.96338},
   {2.10,0.96427},{2.11,0.96514},{2.12,0.96599},{2.13,0.96683},{2.14,0.96765},{2.15,0.96844},
   {2.16,0.96923},{2.17,0.96999},{2.18,0.97074},{2.19,0.97148},{2.20,0.97219},{2.21,0.97289},
   {2.22,0.97358},{2.23,0.97425},{2.24,0.97491},{2.25,0.97555},{2.26,0.97618},{2.27,0.97679},
   {2.28,0.97739},{2.29,0.97798},{2.30,0.97855},{2.31,0.97911},{2.32,0.97966},{2.33,0.98019},
   {2.34,0.98072},{2.35,0.98123},{2.36,0.98172},{2.37,0.98221},{2.38,0.98269},{2.39,0.98315},
   {2.40,0.98360},{2.41,0.98405},{2.42,0.98448},{2.43,0.98490},{2.44,0.98531},{2.45,0.98571},
   {2.46,0.98611},{2.47,0.98649},{2.48,0.98686},{2.49,0.98723},{2.50,0.98758},{2.51,0.98793},
   {2.52,0.98826},{2.53,0.98859},{2.54,0.98891},{2.55,0.98923},{2.56,0.98953},{2.57,0.98983},
   {2.58,0.99012},{2.59,0.99040},{2.60,0.99068},{2.61,0.99095},{2.62,0.99121},{2.63,0.99146},
   {2.64,0.99171},{2.65,0.99195},{2.66,0.99219},{2.67,0.99241},{2.68,0.99263},{2.69,0.99285},
   {2.70,0.99307},{2.71,0.99327},{2.72,0.99347},{2.73,0.99367},{2.74,0.99386},{2.75,0.99404},
   {2.76,0.99422},{2.77,0.99439},{2.78,0.99456},{2.79,0.99473},{2.80,0.99489},{2.81,0.99505},
   {2.82,0.99520},{2.83,0.99535},{2.84,0.99549},{2.85,0.99563},{2.86,0.99576},{2.87,0.99590},
   {2.88,0.99602},{2.89,0.99615},{2.90,0.99627},{2.91,0.99639},{2.92,0.99650},{2.93,0.99661},
   {2.94,0.99672},{2.95,0.99682},{2.96,0.99692},{2.97,0.99702},{2.98,0.99712},{2.99,0.99721},
   {3.00,0.99730},{3.01,0.99739},{3.02,0.9974}, {3.03,0.9976}, {3.04,0.9976}, {3.05,0.9978},
   {3.06,0.9978}, {3.07,0.9978}, {3.08,0.9980}, {3.10,0.9980}, {3.11,0.9982}, {3.12,0.9982},
   {3.13,0.9982}, {3.14,0.9984}, {3.15,0.9984}, {3.16,0.9984}, {3.17,0.9984}, {3.18,0.9986},
   {3.19,0.9986}, {3.20,0.9986}, {3.21,0.9986}, {3.22,0.9988}, {3.23,0.9988}, {3.24,0.9988},
   {3.25,0.9988}, {3.26,0.9988}, {3.27,0.9990}, {3.28,0.9990}, {3.29,0.9990}, {3.30,0.9990},
   {3.31,0.9990}, {3.32,0.9990}, {3.33,0.9992}, {3.34,0.9992}, {3.36,0.9992}, {3.37,0.9992},
   {3.38,0.9992}, {3.39,0.9994}, {3.40,0.9994}, {3.41,0.9994}, {3.42,0.9994}, {3.43,0.9994},
   {3.44,0.9994}, {3.45,0.9994}, {3.46,0.9994}, {3.47,0.9994}, {3.48,0.9994}, {3.49,0.9996},
   {3.50,0.9996}, {3.51,0.9996}, {3.52,0.9996}, {3.53,0.9996}, {3.54,0.9996}, {3.55,0.9996},
   {3.56,0.9996}, {3.57,0.9996}, {3.58,0.9996}, {3.59,0.9996}, {3.60,0.9996}, {3.70,0.9998}
};
To add comments, please log in or register