Hello everybody

I make pretty good process in transferring my trading models to AmiBroker and learn a lot about mistakes I made in the past because I wasn't able to backtest then.

Now I have a question for which I can't find any answer in the manual nor in the community forum. Could you help me, please?

First, I created the following rotating model (My Formula 17):

```
SetBacktestMode( backtestRotational );
SetOption("MaxOpenPositions",10);
// SetOption("WorstRankHeld",10);
SetPositionSize( 10, spsPercentOfEquity );
// Rebalancing, in trading days ;
SetOption("HoldMinBars", 127);
Rise = C > MA (Close, 200);
TotalRise = sum (Rise, 1280);
GDSum = (TotalRise*100/1280);
// Filter = GDSum > 78 ; // This filter seems not to work
PositionScore = ROC(CLOSE,1280);
```

Running through the S&P 500 from 1.1.2015 to 20.12.2020 to have two difficult periods in the test gives an annual profit of 21,7 %.

I tried to further refine the title list with a function only trading the equities with Close > MA200 during at least 78 % of the time in the past five years. But the "filter" function seems not to work in rotational backtesting.

To force the system to work with daily data but to rotate only twice a year I inserted "HoldMinBars", 127. This is not perfect, but it works and it shows the direction what this model could achieve.

Question: Is there a way to work with daily data in rotational backtest and to define an option when to rotate? Monthly, quarterly, halfyear etc as in the model further below?

In the next step I made a similar model but in "classical" AFL Code (my formula 21). Instead of ROC I use RSL.

```
// Is trading this month allowed?
// Switch to S&P symbol to calculate broad-market timing
SetForeign( "A0AET0" );
// now we can calculate, based on S&P 500
MarketIsUp = C > MA( C, 200 ); // here C represents closing price of S&P 500
//
// now go back to origiginal data (current symbol)
RestorePriceArrays();
//
NumPos = 10;
SetOption( "MaxOpenPositions", NumPos );
PositionSize = -100 / NumPos;
// Close during at least 78 % of time > MA 200?
Rise = C > MA (Close, 200);
TotalRise = sum (Rise, 1280);
GDSum = (TotalRise*100/1280);
// Filter = GDSum >= 78; // This filter function seems not to work.
// Ranking with highest RSL during past 5 years
PositionScore = Close / MA (Close, 1280);
mth = Month();
dow = DayOfWeek();
mth_mod3 = mth % 3;
hy = mth % 6;
NewWeek = dow < Ref(dow,-1);
NewMonth = mth != Ref(mth,-1);
NewQuarter = mth_mod3 * !Ref(mth_mod3,-1);
NewHalfyear = hy * !Ref(hy,-1);
NewYear = Year() != Ref(Year(), -1);
// PeriodStart = NewWeek;
// PeriodStart = NewMonth;
// PeriodStart = NewQuarter;
PeriodStart = NewHalfyear;
// PeriodStart = NewYear;
TradingDay = BarsSince(PeriodStart) == 1; // Second day in period
Bcond7 = TradingDay;
Bcond8 = GDSum >= 78;
// Buy = Bcond7 AND Bcond8;
Buy = Bcond7 ;
Scond3 = TradingDay;
Scond4 = C < MA(C,200);
Sell = Scond3 AND Scond4 ;
// Sell = TradingDay ;
```

The results of this model are encouraging too (16,5 % yearly, same time period as above), but I would like to further refine them.

Here I have the following question: Is there an elegant solution to sell all shares every trading day (in the model above every half year) and to build up the portfolio new with the most promising shares as defined in the "Buy" rules?

When I use the expression Sell = Close < 0 as a workaround, the system sells the shares the same day when bought.

I would appreciate to get some input what solutions might exist to solve these challenges.