[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [amibroker] Adding Columns to Backtester Output page



PureBytes Links

Trading Reference Links

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-----
From: amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx] On Behalf Of Keith McCombs
Sent: Monday, May 08, 2006 11:41
To: amibroker@xxxxxxxxxxxxxxx
Subject: Re: [amibroker] Adding Columns to Backtester Output page

 

Search for 'backtest' under Help.  Then select "How to add user-defined metrics to backtest/optimization report"

rdavenportca wrote:

I am new to Amibroker and this site.  I'm in the process of trying to
learn the language.  It's a lot harder than TradeStation!

I would like to add two columns to the backtester output:

(1) the month each trade was exited
(2) the year each trade was exited

I think this should be possible, but I can't figure out how.  Any help
would be greatly appreciated.

Regards,

Rob







Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com

For other support material please check also:
http://www.amibroker.com/support.html





SPONSORED LINKS
Investment management software Real estate investment software Investment property software
Software support Real estate investment analysis software Investment software


YAHOO! GROUPS LINKS