EnableRotationalTrading
- Turns on rotational-trading mode of the backtester

Trading system toolbox
(AFL 2.5)


SYNTAX EnableRotationalTrading()
RETURNS NOTHING
FUNCTION When placed on the top of system formula it turns on rotational-trading (aka. fund-switching) mode of the backtester.

Note: this function is now marked as obsolete. Use SetBacktestMode( backtestRotational ) in new formulas.

IMPORTANT NOTE: Unless you specifically want to implement fund-switching/rotational trading system you should NOT use this mode.

Rotational trading is popular method for trading mutual funds. It is also known as fund-switching or scoring&ranking. Its basic permise is to rotate symbols all the time so only top N issues ranked according to some user-definable score are traded. The number of positions open depend on "Max. open positions" setting and available funds / position size. Once position is entered in remains in place until security's rank drops below WorstRankHeld (settable via SetOption("WorstRankHeld", 5 ) ). Regular buy/sell/short/cover signals are not used at all.

The rotational mode uses only score variable (PositionScore) to rank and rotate securities. This idea has been implemented earlier in PortfolioTrader AFL formula written by Fred Tonetti with GUI written by Dale Wingo.

To enter this mode you have to call EnableRotationalTrading() function at the very beginning of your formula. From then on using of buy/sell/short/cover variables is not allowed. Only PositionScore variable will be used to rank securities and trade top N securities..

A simple rotational trading formula (stocks with high RSI are best candidates for shorting while stocks with low RSI are best candidates for long positions):

EnableRotationalTrading();
SetOption("WorstRankHeld",5);

PositionSize = -25; // invest 25% of equity in single security
PositionScore = 50 - RSI(); // PositionScore has the same meaning as rScore in PT

The score (PositionScore) for all securities is calculated first. Then all scores are sorted according to absolute value of PositionScore. Then top N are choosen to be traded. N depends on available funds and "max. open positions" setting. Backtester successively enters the trades starting from highest ranked security until the number of positions open reaches "max. open positions" or there are no more funds available. The score has the following meaning:

  • higher positive score means better candidate for entering long trade
  • lower negative score means better candidate for entering short trade
  • the score of zero means no trade (exit the trade if there is already open position on given symbol)
  • the score equal to scoreNoRotate constant means that already open trades should be kept and no new trades entered
  • the score equal to scoreExitAll constant causes rotational mode backtester to exit all positions regardless of HoldMinBars. Note that this is global flag and it is enough to set it for just any single symbol to exit all currently open positions, no matter on which symbol you use scoreExitAll (it may be even on symbol that is not currently held). By setting PositionScore to scoreExitAll you exit all positions immediatelly regardless of HoldMinBars setting

Exits are generated automatically when security's rank drops below "worst rank held". There is no real control over when exits happen except of setting low score to force exits. You can also set the score on any (at least one) security to value of scoreNoRotate to prevent rotation (so already open positions are kept). But this is global and does not give you individual control.

Important:
The rotational trading mode uses "buy price" and "buy delay" from the Settings | Trade page as trade price and delay for both entries and exits (long and short)

EXAMPLE EnableRotationalTrading();
SetOption("WorstRankHeld",5);

PositionSize = -25; // invest 25% of equity in single security
PositionScore = 50 - RSI(); // PositionScore has the same meaning as rScore in PT
SEE ALSO SetBacktestMode() function

References:

The EnableRotationalTrading function is used in the following formulas in AFL on-line library:

More information:

Updated on-line reference