Ed,

Try moving the calculation of bi_start inside the CBT code.

if (Status("action") == actionPortfolio)
{
  bi_start = ...;
}

Mike

--- In [email protected], "Edward Pottasch" <empotta...@...> 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