Add custom column to optimization results

I have a AFL optimisation script which works fine. I want to add a new column to show liquidity.

I added the 3 lines to my AFL script.

Liquidity = Volume*Close;
AddColumn(Liquidity, "Liquidity");
Filter = 1;

However, the liquidity column does not appear. How should I add the liquidity column to optimisation results?

1 Like

You code is EXPLORATION code.
In order to show columns (of custom metrics) in backtest you have to write a high level CBT (custom backtest code).

https://www.amibroker.com/guide/a_custommetrics.html
http://www.amibroker.com/kb/category/analysis/backtest-analysis/custom-backtest/
https://www.amibroker.com/guide/a_custombacktest.html


In addition to force AB to output backtest report during optimization you have to add

SetOption( "GenerateReport", True ); 

to your code. (As aside, since it forces to write report for each optimization step it slows down overall run of optimization.)


Anyway here is sample high level CBT code (adds extra Liquidity column to trade list) to be added to your own code.

SetCustomBacktestProc(""); 
if( Status("action") == actionPortfolio ) 
{ 
    bo = GetBacktesterObject(); 

    bo.Backtest(1); // run default backtest procedure 

    // iterate through closed trades first 
    for( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() ) 
    { 
        // do your calculations involving trade objects (list of closed trades)
        staticget = StaticVarGet( "Liquidity_" + trade.Symbol );
        trade.AddCustomMetric( "Liquidity", Lookup(staticget, trade.ExitDateTime), 2 ); 
    } 

    bo.ListTrades(); 
}

StaticVarSet( "Liquidity_" + Name(), V*C );
9 Likes

Hi fxshrat,

Thank you for the post. The code works fine for Backtest. However, when I tried to run "Individual Optimize", I get the following error;
Custom backtester is not yet supported in Multi-threaded Individual Optimization. Use regular optimization instead.

Is there some way to add liquidity column and run "Individual Optimize"?

As the message tells you... No, you can't use CBT code in individual optimization.
Use regular optimization instead.

As for why no CBT in "Individual Optimization" go and look here (at the very bottom) where it says:

as well as here where it says:

2 Likes