Sunday, October 7, 2012

Meta-Trader - Analyzing Account Equity

Welcome back Meta-Traders.

When last we left off, we were considering the analysis of account equity.  The objective of this exercise is to analyse the recent behavior of our trading system by examining the actual trading results.  Our goal is a money management scheme that works as follows:

- If a system is behaving poorly in current conditions, reduce the lot size or stop trading it altogether

- If a system is behaving in a neutral fashion, neither gaining or losing money, we can continue to trade it with standard lot sizes.

- If a system is behaving well under current market conditions, then we can go ahead with the full market exposure.

When this method is working properly, we can be trading (or monitoring) a whole crowd of trading systems and having the systems automatically scale into systems which are working and scale out of systems which are not.  Keep in mind that this method will work only for systems which trade frequently, and make (or lose) their money over a series of trades.  It will not work for long term trend followers which may have say 9 small losses and make it all back on the 10th trade.

Looking further into this, I found that Meta-Trader does not have functions which allow tracking of historical account equity.  However, there is a function called AccountEquity() which does just that and spits out the AccountEquity at any given point in time.  Fortunately, this function works as expected whether running live or in back testing mode.

Next, we have a series of functions which can determine (for any given magic number), how much money that instance made or lost as follows:

double OrderHistoryProfit(int nMagic)

int i;
int nOrders = OrdersHistoryTotal();
double dProfit = 0.0;

for(i=0; i < nOrders; i++) 
{
  if (OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true)
  {
    if (OrderMagicNumber() == nMagic)
    {
      dProfit = dProfit + OrderProfit();
    }
  }
}
return(dProfit);
}

This function takes a system's magic number (set inside your EA or in the EA Properties) and returns the total amount made or lost.  You might think that the total amount of money made or lost is a poor indicator of whether we should be trading the system.  On a long-term basis, I agree.  But on a short term basis (say the systems last 5 to 10 trades, it could be a good indicator of how well the system is performing.  If you don't agree, take a look at the equity graphs of the systems I have been trading live for the past few years.  Its clear to be that those systems have long, sustainable equity trends.

With this function, we can continue last week's thought experiment and adjust our lot sizes dynamically based on recent performance.

Unfortunately, that's all the time I have for this week.  Check back later and have a great week.


No comments:

Post a Comment