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

Re: [amibroker] Adding Column to Backtester



PureBytes Links

Trading Reference Links

tks Graham - I am trying to pass the string so I guess the Foreign
might not work, right?

On 6/18/06, Graham <kavemanperth@xxxxxxxxx> wrote:
> You have 2 ways to add normal values to the advanced code as far as I
> ahve worked out
> Use staticvarset and staticvarsettext in your normal code and then the
> gets in the advanced code
> The other is to create composites of the values you want to transfer
> to the advanced code in your normal formula. You can then use the
> foreign to pull this data into the advanced code. This may also
> require the use of a function that tomasz provided for finding equity
> at a certain date. Here is a part of the code, this is a astarting
> point only, youi will need to deternine how to actually use it
>
>
> from response by Tomasz............................
> /*Hello,
>
> I have been asked how to access portfolio Equity to calculate some
> trade statistics
> in new portfolio backtester interface, so I have modified the code
> from example 3,
> to show you how. the calculations remain the same, all I did it to add 2 extra
> columns with per-trade metrics: "equity at entry" AND "Risk as % of
> equity at entry".
>
> The code follows. Newly added lines are marked with // ADDED LINE
> comment.
> Refer to http://www.amibroker.com/newsletter/01-2005.html for more details.
>
> /* First we need to enable custom backtest procedure and
> ** tell AmiBroker to use current formula
> */
>
> SetCustomBacktestProc("");
>
> function FindEquityAtDateTime( eq, dt, Value )
> {
>   found = -1;
>   for( i = 0; i < BarCount AND found == -1; i++ )
>   {
>      if( dt[ i ] == Value ) found = i;
>   }
>
>   return IIf( found != -1, eq[ found  - 1 ], Null );
> }
>
> /* Now custom-backtest procedure follows */
> if( Status("action") == actionPortfolio )
> {
>    bo = GetBacktesterObject();
>
>    bo.Backtest(1); // run default backtest procedure
>
>   // ADDED LINE
>    dt = DateTime();
>
>   // ADDED LINE
>   // at this stage (after Backtest() call) portfolio equity symbol is updated
>   // so we can use it to obtain current values
>   eq = Foreign("~~~EQUITY", "C" );
>
>   // iterate through closed trades first
>   for( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() )
>   {
>       // ADDED LINE
>      EquityAtEntry = FindEquityAtDateTime( eq, dt, trade.EntryDateTime );
> }
> }
>
>
>
> --
> Cheers
> Graham
> AB-Write >< Professional AFL Writing Service
> Yes, I write AFL code to your requirements
> http://e-wire.net.au/~eb_kavan/ab_write.htm
>
>
> On 18/06/06, PKJR <TradingIQ@xxxxxxxxx> wrote:
> > Hi All - small dilemma here.. I would like to add a column to the
> > backtester results..I know I can us a custom metric that is derived
> > from backtester results and add a column this way but how about adding
> > a column that contains data not derived from backtester object but
> > rather from an array in your main AFL code?
> >
> > is there a way to pass an outside array to custom backtester object?
> > BTW my custom backtesting procedure is in a separate AFL file
> >
> > Paul
> >
> >
> >
> > 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
> >
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> >
> >
>
>
>
> 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
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>