Get the account drawdown (Absolute, Maximal and Relative)

 

Hello forum, good day.

How can the account drawdown (Absolute, Maximal and Relative) be calculated in code? I found the following calculations for Absolute and Maximal DrawDown in this article, but it doesn't show how to do it in code:

 

AbsoluteDrawDown = InitialDeposit - MinimalBalance

MaximalDrawDown = Max of (Maximal Peak - next Minimal Peak) 


For the initial deposit I will try the following, but I don't know if it will work:

//+------------------------------------------------------------------+
//| Get deposits function                                            |
//+------------------------------------------------------------------+
double fnGetDeposits()
  {
    int    TotalHistory = OrdersHistoryTotal();
    double Deposit      = 0;

    for ( int cnt = 0; cnt < TotalHistory; cnt++ )
      {
        OrderSelect( cnt, SELECT_BY_POS, MODE_HISTORY );
        if ( ( OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber ) && OrderType() == 6 ) Deposit += OrderProfit();
      }

    Print( "Initial deposit: ", Deposit );

    return( Deposit );
  } //--- end fnGetDeposits()

 

Your help will be much appreciated.

 

Best regards and thank you in advance,

Gerardo 

What the Numbers in the Expert Testing Report Mean
What the Numbers in the Expert Testing Report Mean
  • 2006.05.05
  • MetaQuotes Software Corp.
  • www.mql5.com
Article explains how to read testing reports and to interpret the obtained results properly.