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();
> > }
> >
>