I've always been quite sceptic about EnableRotationalTrading() and I've often 
preferred to go through the more flexible standard backtest mode including my 
rotational logic within the buy/sell/short/cover conditions.

This time I wanted to give it a try since I wanted to test a quite simple 
rotational strategy.

The logic is: buy the 2 stocks with the lowest RSI and short the 2 with the 
highest with a quarterly rebalancing, as simple as that.

Unfortunately the below code doesn't provide the expected quarterly rebalancing 
even if the ranking is correctly updated quarterly (blue line in the chart).

I believe this is related to the EnableRotationalTrading logic since I had 
correct results with standard backtest mode when using similar quarterly 
rebalancing with such ranking variable.

Anyone had similar issues?

----------------------------------------
//Test AB Rotational.afl

SetChartOptions( 0, chartShowArrows );
SetChartOptions( 0, chartShowDates );
SetChartOptions( 2, chartWrapTitle );
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, 
Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

Plot( C, Name(), ParamColor( "Color", colorWhite ), ParamStyle( "Style" ) | 
styleCandle );

SetBacktestMode(backtestRotational); 

MaxOP = Param("Open Positions", 4, 1, 600, 1);

SetOption("SeparateLongShortRank", True );
SetOption("MaxOpenPositions", MaxOP );
SetOption("MaxOpenLong", MaxOP/2 );
SetOption("MaxOpenShort", MaxOP/2 );

SetOption("WorstRankHeld", MaxOP/2); 

Ranking = ValueWhen(Month() != Ref(Month(),1) AND (Month() == 12 OR Month() == 
3 OR Month() == 6  OR Month() == 9) , 50-RSI(14));

PositionSize = -(100/MaxOP);

PositionScore = Ranking;

Plot(Ranking, "Ranking", colorLightBlue, styleLine|styleOwnScale);


Reply via email to