ETF Rotational Problem

Hi,

I would need some help for the following model I am trying to build, the model is as follows:
-In the model we have 2 portfolios:
-50% static portfolio: 25% in VTI and 25% in TLT
-50% In dynamic portfolio: Either the best 3 ETFs of a basket of 6 equity ETFs or the best 3 ETFs of a basket of 5 Fixed income ETFs
-The criteria for choosing the BEST 3 ETFs is 1 year performance
-The criteria for choosing Equity ETFs or Fixed Income ETFs is whether VTI regression slope is higher than TLT regression slope

So far this is what I have done:

  1. The buy condition is EquityStatic= Foreign("VTI","C"); and FixedIncomeStatic= Foreign("TLT","C");
  2. In order to assign 25% of capital to each (50% total), I have done this: PositionSize= IIf(Name()=="VTI", 25000, IIf(Name()=="TLT",25000,16000) );
  3. The condition to decide whether to go with Equity ETF basket or Fixed Income ETF basket is EquityPortfolio=LinRegSlope(EquityStatic,252)>LinRegSlope(FixedIncomStatic,252); and FixedIncomePortfolio=LinRegSlope(EquityStatic,252)<LinRegSlope(FixedIncomStatic,252);
  4. The problem is the following: once you decide to go with one of the baskets, how do you tell amibroker to only look in 1 list or another for a condition such as ROC(C,252) in order to choose the best 3 of that particular basket?

The baskets are the following:

Equity: XLK, XLE, XLV, XLF, XLU, PPA
Fiexed Income: LQD, IEF, HYG, BIL, VIXM

This is the code I am using, I dont think it can help much:

RV= Foreign("VTI","C");
RF= Foreign("TLT","C");
PositionSize= IIf(Name()=="VTI", 25000, IIf(Name()=="TLT",25000,16000) );

colDrv = log(RV); // the natural log of the close
colErv = LinRegSlope( colDrv, 250 ); // this gives the slope of the regression line
colFrv = ( ( exp( colErv ) ) ^ 250 ) - 1 ;
colGrv = ( Correlation( Cum( 1 ), colDrv, 250 ) ^ 2 ); // 90 day R-Squared of column D, the log(C)
AdjustedSloperv = colFrv * colGrv;

colDrf = log(RF); // the natural log of the close
colErf = LinRegSlope( colDrf, 250 ); // this gives the slope of the regression line
colFrf = ( ( exp( colErf ) ) ^ 250 ) - 1 ;
colGrf = ( Correlation( Cum( 1 ), colDrf, 250 ) ^ 2 ); // 90 day R-Squared of column D, the log(C)
AdjustedSloperf = colFrf * colGrf;

Rvariable=ROC(RV,100)>ROC(RF,100);
Rfija=ROC(RV,100)<ROC(RF,100);

IIf(Rvariable,Filter=InWatchListName("ETF RF"),Filter=0);
IIf(Rfija,Filter=InWatchListName("ETF RV"),Filter=0);

//watchlistCheck=IIf(Rvariable,Foreign("QQQ","C"),Foreign("SPY","C"));

Buy= Filter ;

Sell=0;

Filter=True;
AddColumn(AdjustedSloperv,"AdjustedSloperv");

ApplyStop(3,1,5);

Gracias,
Javier Chen