Hello,

BarIndex will start from zero and since first bar in test has index zero you are getting correct result.
As Bruce told you, custom backtest phase runs on ~~~EQUITY ticker that by definition contains
ONLY bars that were within test range.

Best regards,
Tomasz Janeczko
amibroker.com

On 2010-07-27 18:54, Edward Pottasch wrote:
hi Bruce,
 
thanks for your reply. Funny that I just tried this. Writing the value into a static variable and calling it within the CBT. Gives me a result of 0 again.
 
Can you conform this or is it just me Glimlach
            Emoticon
 
thanks, Ed
 
 

From: Bruce
Sent: Tuesday, July 27, 2010 6:46 PM
Subject: [amibroker] Re: question for Custom Backter specialists

 



Ed -

I was going to answer your prior question about running the portfolio backtester from an indicator, when I saw this one. It is fairly straightforward.

In a backtest pass, arrays are calculated over the entire range of the data, irrespective of the AA range (ignoring QuickAFL special cases for this example).

The CBT pass is run on a ticker called ~~~EQUITY which is defined for the test with a start AND end date that corresponds to the AA range specified.

So, by definition, the first bar in the test is 0. If you store the size info in static arrays, you can read them in the CBT pass an the alignment will be taken care of.

-- Bruce

--- In [email protected], "Edward Pottasch" <empotta...@...> wrote:
>
> hi Mike,
>
> thanks for your reply. Yes I tried that. Also tried to define it as global. But I keep getting a value 0 when defined in or outside the CBT code.
>
> or bi_start, defined as: bi_start = LastValue(ValueWhen(Status("firstbarintest"),BarIndex()));
>
> whether defined inside or outside CBT code when I try to access its value inside the CBT code it gives me 0. Outside the CBT code I get the proper value. I am puzzled. Asked helpdesk but no answer (yet). Trying to solve it another way.
>
> regards, Ed
>
>
>
>
>
> From: Mike
> Sent: Tuesday, July 27, 2010 5:40 PM
> To: [email protected]
> Subject: [amibroker] Re: question for Custom Backter specialists
>
>
>
> Ed,
>
> Try moving the calculation of bi_start inside the CBT code.
>
> if (Status("action") == actionPortfolio)
> {
> bi_start = ...;
> }
>
> Mike
>
> --- In [email protected], "Edward Pottasch" <empottasch@> wrote:
> >
> > hi,
> >
> > I am working on code that allows for the combination of multiple systems. Combining signals leads to situations that you need to cover 1 position and buy 3 positions at the same bar. Therefor in high level AFL you can not define the positionSize properly since it needs a separate size for the cover and buy but you are only allowed to fill 1 array element in the positionSize array.
> >
> > So what I did is first define the buy/sell etc arrays and then I defined separate positionSize arrays, positionSizeBuy, PositionSizeSell etc.
> >
> > Then I define a dummy positionSize array so that the proper signals are calculated except that in some cases the positionSize is at fault.
> >
> > Then I use the "Custom Backtester" CBT to change the positionSize, see code below.
> >
> > My question: the CBT starts to loop through the bars starting at i = 0. However, this index coincides with the start bar of the backtest which you set in the AA window. The arrays in which I have set the positionSize I calculated outside the CBT and have their index starting at the true starting index of the complete data array.
> >
> > So then I calculate the index at which the backtest starts and call that bi_start, using:
> >
> > bi_start = LastValue(ValueWhen(Status("firstbarintest"),bi));
> >
> > This number I want to use inside the CBT code, for instance like: positionSizeBuy[ bi_start + i ], to access the proper positionSize for a certain element.
> >
> > But once inside the CBT it does not recognise bi_start, it is set to 0. Why is this?
> >
> > thanks, Ed
> >
> >
> > snippet of code:
> >
> >
> > bi_start = LastValue(ValueWhen(Status("firstbarintest"),bi));
> > "";
> > "bi_start: " + WriteVal(bi_start);
> > "barindex backtest test: " + WriteVal(bi - bi_start);
> > "BarIndex(): " + WriteVal(bi);
> >
> > // custom backtest. Replace dummy positionSize
> > SetCustomBacktestProc("");
> > if (Status("action") == actionPortfolio)
> > {
> >
> > bo = GetBacktesterObject();
> > bo.PreProcess();
> >
> > for (i = 0; i < BarCount; i++)
> > {
> >
> > //_TRACE("bi_start");// + " " + bi_start[ i ];
> >
> > for (sig = bo.GetFirstSignal(i); sig; sig = bo.GetNextSignal(i))
> > {
> >
> > _TRACE("sig: " + sig.IsEntry() + " " + sig.IsExit() + " " + sig.IsLong() + " " + sig.IsScale() + " " + i + " bi_start: " + bi_start);
> >
> > // buy -1,0,-1,0
> > if (sig.IsEntry() AND !sig.IsExit() AND sig.IsLong() AND !sig.IsScale())
> > {
> > //_TRACE("Buy" + i);
> > sig.PosSize = positionSizeBuy[ bi_start + i ];
> > }
> > // short -1,0,0,0
> > else if (sig.IsEntry() AND !sig.IsExit() AND !sig.IsLong() AND !sig.IsScale())
> > {
> > //_TRACE("Short" + i);
> > sig.PosSize = positionSizeShort[ bi_start + i ];
> > }
> > // ScaleIn (long or short) 0,0,-1,-1
> > else if (!sig.IsEntry() AND !sig.IsExit() AND sig.IsLong() AND sig.IsScale())
> > {
> > //_TRACE("ScaleIn Long/Short" + i);
> > sig.PosSize = Max(positionSizeBuy[ bi_start + i ],positionSizeShort[ bi_start + i ]);
> > }
> > // sell 0,-1,-1,0
> > else if (!sig.IsEntry() AND sig.IsExit() AND sig.IsLong() AND !sig.IsScale())
> > {
> > //_TRACE("Sell" + i);
> > sig.PosSize = positionSizeSell[ bi_start + i ];
> > }
> > // cover 0,-1,0,0
> > else if (!sig.IsEntry() AND sig.IsExit() AND !sig.IsLong() AND !sig.IsScale())
> > {
> > //_TRACE("Cover" + i);
> > sig.PosSize = positionSizeCover[ bi_start + i ];
> > }
> > // ScaleOut (long or short) 0,0,0,-1
> > else if (!sig.IsEntry() AND !sig.IsExit() AND !sig.IsLong() AND sig.IsScale())
> > {
> > //_TRACE("ScaleOut Long/Short" + i);
> > sig.PosSize = Max(positionSizeBuy[ bi_start + i ],positionSizeShort[ bi_start + i ]);
> > }
> > }
> > bo.ProcessTradeSignals(i);
> > }
> > bo.PostProcess();
> > }
> >
>

Reply via email to