My Main goal is to add a few columns BUT ONLY IN CASE OF BACKTESTING. By OPTIMIZATION it is no neccessary and the optimization is too slowly.
I have tried it with actionBacktest, but why i get error "COM/Object handle is null" ???
With actionPortfolio it works.
/*******************
* BACKTEST COLUMNS *
********************/
function backtest()
{
/* Now custom-backtest procedure follows */
if( Status("action") == actionBacktest )
{
SetCustomBacktestProc("");
bo = GetBacktesterObject();
if( NOT IsNull(bo) )
{
bo.Backtest(1); // run default backtest procedure
for( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() )
{
SetForeign( trade.Symbol );
myTradeEntryBar = Lookup(BarIndex(),trade.entrydatetime,0);
todayOpenAt093000 = ValueWhen( TimeNum() == 093000 AND BarIndex() < myTradeEntryBar , O , 1 );
yesterdayCloseAt155900 = ValueWhen( TimeNum() == 155900 AND BarIndex() < myTradeEntryBar , C , 1 );
//trade.AddCustomMetric("myTradeEntryBar", myTradeEntryBar, 0 );
trade.AddCustomMetric("gap", abs( todayOpenAt093000[myTradeEntryBar] / yesterdayCloseAt155900[myTradeEntryBar] - 1 ), 6);
trade.AddCustomMetric("todayOpenAt093000", todayOpenAt093000[myTradeEntryBar] );
trade.AddCustomMetric("yesterdayCloseAt155900", yesterdayCloseAt155900[myTradeEntryBar] );
trade.AddCustomMetric("Commission", trade.GetCommission());
trade.AddCustomMetric("Commission / PositionValue", trade.GetCommission() / trade.GetPositionValue(), 8);
}
bo.ListTrades();
}
}
}
backtest();