{"id":730,"date":"2014-11-20T06:22:58","date_gmt":"2014-11-20T11:22:58","guid":{"rendered":"http:\/\/www.amibroker.com\/kb\/?p=730"},"modified":"2014-12-04T08:20:04","modified_gmt":"2014-12-04T13:20:04","slug":"how-to-show-indicator-values-in-backtest-trade-list","status":"publish","type":"post","link":"https:\/\/www.amibroker.com\/wordpress\/kb\/2014\/11\/20\/how-to-show-indicator-values-in-backtest-trade-list\/","title":{"rendered":"How to display indicator values in the backtest trade list"},"content":{"rendered":"
Backtesting engine in AmiBroker allows to add custom metrics to the report, both in the summary report and in the trade list. This is possible with Custom Backtester Interface, which allows to modify the execution of portfolio-level phase of the test and (among many other features) adjust report generation.<\/p>
Due to the fact that the report generation occurs in 2nd phase of the test, when the backtester works on ~~~EQUITY ticker, we can not refer directly to given indicators. For example, to display ATR values – calling ATR() function directly is not enough, because we want to see ATR values of the traded symbol, while in portfolio-phase of the test we are no longer working on that symbol’s quotes.<\/p>
So, we need to:<\/p>
The following formula shows how this can be coded. The formula below displays the value of ATR indicator for the entry bar of given trade:<\/p> Backtesting engine in AmiBroker allows to add custom metrics to the report, both in the summary report and in the trade list. This is possible with Custom Backtester Interface, which allows to modify the execution of portfolio-level phase of the test and (among many other features) adjust report generation.Due to the fact that the report […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8],"tags":[53,14,15],"_links":{"self":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/730"}],"collection":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/comments?post=730"}],"version-history":[{"count":2,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/730\/revisions"}],"predecessor-version":[{"id":733,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/730\/revisions\/733"}],"wp:attachment":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/media?parent=730"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/categories?post=730"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/tags?post=730"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}SetCustomBacktestProc<\/span>( <\/span>"" <\/span>);
if ( <\/span>Status<\/span>( <\/span>"action" <\/span>) == <\/span>actionPortfolio <\/span>)
{
<\/span>bo <\/span>= <\/span>GetBacktesterObject<\/span>();
<\/span>\/\/ run default backtest procedure without generating the trade list
<\/span>bo<\/span>.<\/span>Backtest<\/span>( <\/span>True <\/span>);
<\/span>\/\/ iterate through closed trades
<\/span>for ( <\/span>trade <\/span>= <\/span>bo<\/span>.<\/span>GetFirstTrade<\/span>( ); <\/span>trade<\/span>; <\/span>trade <\/span>= <\/span>bo<\/span>.<\/span>GetNextTrade<\/span>( ) )
{
<\/span>\/\/ read ATR values and display as custom metric
<\/span>symbolATR <\/span>= <\/span>StaticVarGet<\/span>( <\/span>trade<\/span>.<\/span>Symbol <\/span>+ <\/span>"ATR" <\/span>);
<\/span>trade<\/span>.<\/span>AddCustomMetric<\/span>( <\/span>"Entry ATR"<\/span>, <\/span>Lookup<\/span>( <\/span>symbolATR<\/span>, <\/span>trade<\/span>.<\/span>EntryDateTime <\/span>) );
}
<\/span>\/\/ iterate through open positions
<\/span>for ( <\/span>trade <\/span>= <\/span>bo<\/span>.<\/span>GetFirstOpenPos<\/span>( ); <\/span>trade<\/span>; <\/span>trade <\/span>= <\/span>bo<\/span>.<\/span>GetNextOpenPos<\/span>( ) )
{
<\/span>\/\/ read ATR values and display as custom metric
<\/span>symbolATR <\/span>= <\/span>StaticVarGet<\/span>( <\/span>trade<\/span>.<\/span>Symbol <\/span>+ <\/span>"ATR" <\/span>);
<\/span>trade<\/span>.<\/span>AddCustomMetric<\/span>( <\/span>"Entry ATR"<\/span>, <\/span>Lookup<\/span>( <\/span>symbolATR<\/span>, <\/span>trade<\/span>.<\/span>EntryDateTime <\/span>) );
}
<\/span>\/\/ generate trade list
<\/span>bo<\/span>.<\/span>ListTrades<\/span>( );
}
<\/span>\/\/ your trading system here
<\/span>Buy <\/span>= <\/span>Cross<\/span>( <\/span>MACD<\/span>(), <\/span>Signal<\/span>() );
<\/span>Sell <\/span>= <\/span>Cross<\/span>( <\/span>Signal<\/span>(), <\/span>MACD<\/span>() );
<\/span>\/\/ assign indicator values to ticker-specific variables
<\/span>StaticVarSet<\/span>( <\/span>Name<\/span>() + <\/span>"ATR"<\/span>, <\/span>ATR<\/span>( <\/span>15 <\/span>) )<\/code>","protected":false},"excerpt":{"rendered":"