I managed to create a custom metric in backtest results. Here is the code which displays the volume gain as custom metric.
SetCustomBacktestProc( "" );
if ( Status( "action" ) == actionPortfolio )
{
bo = GetBacktesterObject();
// run default backtest procedure without generating the trade list
bo.Backtest( True );
// iterate through closed trades
for ( trade = bo.GetFirstTrade( ); trade; trade = bo.GetNextTrade( ) )
{
// read Vol values and display as custom metric
symbolVol = StaticVarGet( trade.Symbol + "VolG" );
trade.AddCustomMetric( "VolumeGain", Lookup( symbolVol, trade.EntryDateTime ) );
}
// iterate through open positions
for ( trade = bo.GetFirstOpenPos( ); trade; trade = bo.GetNextOpenPos( ) )
{
// read Vol values and display as custom metric
symbolVol = StaticVarGet( trade.Symbol + "VolG" );
trade.AddCustomMetric( "VolumeGain", Lookup( symbolVol, trade.EntryDateTime ) );
}
// generate trade list
bo.ListTrades( );
}
// assign indicator values to ticker-specific variables
//GetVolGain() is function to calculate the desired volume information
StaticVarSet( Name() + "VolG", GetVolGain(NUM_BARS_MID_TERM) );
The custom metric results are displayed up to only 2 decimal places by default. However, I want the results to display up to 4 decimal places. How can this be done?
Thank you.