Perhaps an old thread however I have worked out how to do this.
You need to run custom backtester.
I have pasted the related Code to make it work below.
The important part is that whatever you name the custom metric you need to exactly and perfectly type that same name manually into the Backtester Settings Walk-Forward tab in the “Optimization Target” window. It will not show in this window as a drop-down option, however it will in fact work successfully when you run the backtest/optimization if you have exactly typed in the name of whatever you have called it. It will also show in backtest report window and will successfully copy across to excel when copy/pasting results from Amibroker to excel.
As you will see from my example code and screenshots I am performing a simple multiplication of two already available variables. I have not tried making any calls to other arrays or variables outside those available by default, but I guess that is the next challenge on making more interesting optimization targets. Use the help file in Amibroker to see the names of all the available, existing variables using the st.GetValue method.
If you are not already using custom backtester, you would use the following…….
// Custom Backtester such that WW calculation can be used in Optimization process…
SetCustomBacktestProc(“”);
if( Status(“action”) == actionPortfolio )
{
bo = GetBacktesterObject();
bo.Backtest(); // run default backtest procedure
st = bo.GetPerformanceStats(0); // get stats for all trades
// WonderWife Calculation for custom optimisation target…
WW = st.GetValue(“RRR”) * st.GetValue(“UlcerPerformanceIndex”) ;
bo.AddCustomMetric( “WonderWife Score”, WW );
}
If you are already using custom backtester (like the Script Julian sorted out for limit order ranking) then you just need to paste the following into the bottom end of the custom backtester code. It should go after the section for Custom Metrics and before the final } …..
// WonderWife Calculation for custom optimisation target…
WW = st.GetValue(“RRR”) * st.GetValue(“UlcerPerformanceIndex”) ;
bo.AddCustomMetric( “WonderWife Score”, WW );