Hi- 
     
    I have run into some
major performance problems when trying to add a single simple metric to
the backtest results.  I have no doubt that its something I'm doing, I
just have no idea what that might be.  I have seen a post or two in the
past on how to accomplish what I'm trying to do (as the examples
below will replicate), but there was no follow up on the performance of
the proposed solutions.  Since there was no further discussion, I'm
wondering if the code is fine but my settings (or something else) may
be causing the problem.  Below I list what I believe to be all
pertinent information - would very much appreciate any help on this.
     
    Base system is
tested on 5 symbols, 5min data, from 1/1/2000 - 12/31/2006. Quick AFL
is checked in the setting and data is padded and aligned.  I'm running
the 64bit version of AB 5.22.  
     
    Performance
without calling CBT : 65 secs
     
    ------------
--------- --------- --------- --------- ---
     
    Performance
with the code below added: 72 secs (very good)
    
    SetCustomBacktestPr oc("");
if (Status("action") == actionPortfolio)
{
    bo = GetBacktesterObject();	//  Get backtester object
    bo.Backtest(True);			//  Run backtests with no trade listing
    stat = bo.GetPerformanceStats(0);	//  Get Stats object for all trades
    winAvgProfit = stat.GetValue("WinnersAvgProfit");
    loseAvgLoss = stat.GetValue("LosersAvgLoss");
    for (trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade())
    {					//  Loop through all closed trades
        prof = trade.GetProfit();		//  Get trade profit in dollars
        relProf = 0;			//  This will be profit/avgProfit as %
        if (prof > 0)			//  If a winner (profit > 0)
            relProf = prof / winAvgProfit * 100;	//  Profit relative to average
        else				//  Else if a loser (profit <= 0)
            relProf = -prof / loseAvgLoss * 100;	//  Loss relative to average
        trade.AddCustomMetric("Rel Avg Profit%", relProf);	//  Add metric
    }					//  End of for loop over all trades
    bo.ListTrades();			//  Generate list of trades
}
    ------------ --------- --------- --------- --------- --------- --------- --------- --------- --------- ------
    Performance with the code below added to record ATR at entry: 854 secs
    
    SetCustomBacktestPr oc("");
    if (Status("action") == actionPortfolio) 
    { 
    bo = GetBacktesterObject();
    
    bo.Backtest(True);
    dates = DateTime(); 
    bi = BarIndex();
    for (trade = bo.GetFirstTrade( );
trade; trade = bo.GetNextTrade( )) 
    {
    SetForeign(trade.Symbol) ; 
    entryBar = LastValue(ValueWhen(trade.EntryDateTim
e == dates, bi)); 
    foreignATR = ATR(14); 
    trade.AddCustomMetr ic("Entry ATR",foreignATR[
entryBar] ); 
    RestorePriceArrays(); 
    }
    bo.ListTrades( ); 
    }
    
    Anyone have any ideas where I may be going wrong?