|
It's not quite that easy. I had fits with this until Tomasz, incredible support guy that he is, helped me out.
The problem isn't too difficult when you want a built-in metric, but when you want something different, for example, the actual price or the Industry group there are a couple of tricks. Take special note of the function preceding the SetCustomBacktestProc("") and this statement: SetForeign(trade.Symbol);
Also note that there are two identical sections, one for closed trades and one for open trades.
I suggest anyone interested in adding stats columns to the back-tester copy and modify this code (inserted before your Buy/Sell/Short/Cover statements) :
/********************* CUSTOM BACKTEST PROCEDURE ********************/ function FindValueAtDateTime( array, dt, Value ) { found = -1; for( i = 0; i < BarCount AND found == -1; i++ ) { if( dt[ i ] == Value ) found = i - 1; //Coded by Tomasz = i, but I want the value from the day BEFORE the signal } result = Null; if( found != -1 ) result = array[ found ]; return result; }
SetCustomBacktestProc(""); dt = DateTime();
if( Status("action") == actionPortfolio ) { bo = GetBacktesterObject(); bo.Backtest(1); // run default backtest procedure
// iterate through closed trades and add some info for( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() ) { SetForeign(trade.Symbol); trade.AddCustomMetric("Industry",IndustryID(1) ); //Want to see IndustryID by trade trade.AddCustomMetric("PScore",trade.Score,0); //Lookup actual price at trade entry foi = Foreign( trade.Symbol, "I" ); temp = FindValueAtDateTime( foi, dt, trade.EntryDateTime ); // _TRACE( "Temp=" + temp ); trade.AddCustomMetric("Actual OI", temp/100 ); //Lookup Volume at trade entty foi = Foreign( trade.Symbol, "V" ); temp = FindValueAtDateTime( foi, dt, trade.EntryDateTime ); trade.AddCustomMetric("Volume", temp, 0 );
} // iterate through open trades and add same info for( trade = bo.GetFirstOpenPos(); trade; trade = bo.GetNextOpenPos() ) { SetForeign(trade.Symbol); trade.AddCustomMetric("Industry",IndustryID(1)); //Want to see IndustryID by trade trade.AddCustomMetric("PScore",trade.Score,0); //Lookup actual price at trade entry foi = Foreign( trade.Symbol, "I" ); temp = FindValueAtDateTime( foi, dt, trade.EntryDateTime ); // _TRACE( "Temp=" + temp ); trade.AddCustomMetric("Actual OI", temp ); //Lookup Volume at trade entty foi = Foreign( trade.Symbol, "V" ); temp = FindValueAtDateTime( foi, dt, trade.EntryDateTime ); trade.AddCustomMetric("Volume", temp, 0 );
} bo.ListTrades(); }
/********************** END C.B.T. PROCEDURE ************************/
-- Terry -----Original
Message-----
Search for
'backtest' under Help. Then select "How to add
user-defined metrics to backtest/optimization report" I am new to Amibroker and this site. I'm in the process of trying
to
|
