Hello. I would love to change the output metric "Winning Rate" from 85.71 to p = 85.71 %., because it makes my further processing more efficient.
Here is the current code:
/* First we need to enable custom backtest procedure and
** tell AmiBroker to use current formula
*/
SetCustomBacktestProc("");
/* Now custom-backtest procedure follows */
if( Status("action") == actionPortfolio )
{
bo = GetBacktesterObject();
bo.Backtest(); // run default backtest procedure
st = bo.GetPerformanceStats(0); // get stats for all trades
// Expectancy calculation (the easy way)
// %Win * AvgProfit - %Los * AvgLos
// note that because AvgLos is already negative
// in AmiBroker so we are adding values instead of subtracting them
// we could also use simpler formula NetProfit/NumberOfTrades
// but for the purpose of illustration we are using more complex one :-)
WinningRate=st.GetValue("WinnersPercent");
// Here we add custom metric to backtest report
bo.AddCustomMetric( "Winning Rate", WinningRate, Null, Null, DecPlaces=2);
}
Hi @EveryDayBetter
As mentioned in the doc, AddCustomMetric second argument is a Variant, so you can provide a string. To format a string, it's possible to use StrFormat. For instance:
@beauty, the above screenshot results from an "Optimize" execution. So include in your formula some variables to be "optimized".
Then, modify the AddCustomMetric line of the original post as suggested by @alligator and it should work.