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

[amibroker] Re: Is is possible to add custom columns to the backtest results screen?



PureBytes Links

Trading Reference Links

Thanks a bunch.  I finally found the post addressing this.  Here is
the code for anyone following this thread:

/********************* 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 ************************/


--- In amibroker@xxxxxxxxxxxxxxx, "vlanschot" <vlanschot@xxx> wrote:
>
> You can use the following function, originally based on a version by 
> TJ:
> 
> function FindStatAtEndTrade (Stat, dt, Value)
> {
> 	found = -1;
> 	for( i = 0; i < BarCount AND found==-1; i++ ) 
>    { 
>       if( dt[ i ] == Value ) found = i; 
>    } 
> 
> 	result = Null;
> 	if( found > 1 ) result = Stat[ found ];
> 
> 	return result;
>    //return IIf( found != -1, Stat[ found], Null ); // Stat at 
> end /close of trade
> } 
> 
> Also, look at message #83288 for Paul's example, and Graham also has 
> posted examples on this (I think).
> 
> PS
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "gp_sydney" <gp.investment@> 
> wrote:
> >
> > You need to pass your indicator arrays, or at least the values on 
> the
> > entry days, to the custom backtest procedure. For the whole arrays, 
> I
> > think you need to use AddToComposite and Foreign, or for individual
> > values you can use dynamic/static variables with appropriate names
> > (eg. including stock code plus entry date/time).
> > 
> > No idea about fundamental data though.
> > 
> > Regards,
> > GP
> > 
> > 
> > 
> > --- In amibroker@xxxxxxxxxxxxxxx, "trustdnb" <trustdnb@> wrote:
> > >
> > > Thanks for the tip GP, but I am still coming up a little short for
> > > what I am trying to accomplish. What I want to do is show the 
> value of
> > > chosen indicators (e.g. RSI, ROC, etc.) for each trade that was
> > > entered. I would also like to add a few columns that display
> > > fundamental indicators (mkt cap, EPS, etc.). The problem is that 
> the
> > > arrays that hold the "bar-by-bar" RSI values are not directly
> > > available to the backtester on a "trade-by-trade" basis.  
> > > 
> > > The only workaround I have been able to come up with is to use
> > > PositionScore.  If I want to see the RSI values for each trade. I
> > > simply set PositionScore = RSI (14) and then show the RSI value by
> > > using trade.score().  There are two problems however:  (1) I cant 
> show
> > > more than one value this way and (2) Using PositionScore will 
> change
> > > the trades that my system takes.  
> > > 
> > > Is there a better way to do this?  Here is my current code:
> > > 
> > > PositionScore = RSI (14);
> > > SetCustomBacktestProc(""); 
> > > 
> > > if( Status("action") == actionPortfolio ) 
> > > { 
> > >     bo = GetBacktesterObject(); 
> > >     bo.Backtest(1); 
> > >  
> > >    NumTrades = 0; 
> > >  
> > >    for( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade
> () ) 
> > >    { 
> > >  
> > >        trade.AddCustomMetric("RSI", trade.score() ); 
> > >        NumTrades++; 
> > >    } 
> > > 
> > >     bo.ListTrades(); 
> > > 
> > > }
> > > 
> > > --- In amibroker@xxxxxxxxxxxxxxx, "gp_sydney" <gp.investment@> 
> wrote:
> > > >
> > > > You can do this with the high-level custom backtester interface.
> > > > 
> > > > See example 3 in the help section "Adding custom backtest 
> metrics".
> > > > 
> > > > Regards,
> > > > GP
> > > >  
> > > > 
> > > > --- In amibroker@xxxxxxxxxxxxxxx, "trustdnb" <trustdnb@> wrote:
> > > > >
> > > > > Is is possible to add custom columns to the backtest results
> > screen? 
> > > > > What I would like to be able to do is sort my trade results 
> by net
> > > > > profit or by winners/losers and see if the winners all have 
> low RSI,
> > > > > high relative strength, etc. Alternatively, is there a way to
> > add per
> > > > > trade profit or win/loss to the exploration screen?  The 
> exploration
> > > > > doesn't seem to have access to the trade variables (e.g.
> > > > > Buyprice/Sellprice).
> > > > > 
> > > > > Thanks,
> > > > > Muhammad
> > > > >
> > > >
> > >
> >
>




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 NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html
 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/