WiseTrader Toolbox

System Rotation

Background

Most trading systems work well in some market conditions and badly in others. A trend-following system does great while a stock trends and gives a lot of it back when the stock goes sideways; a mean-reversion system is the opposite. Rather than pick one and live with its bad patches, system rotation lets you run several systems side by side and, at any moment, trade whichever one has been doing best lately.

That is what these functions do. You give them the buy and sell signals from two or more of your own systems. Behind the scenes each system is back-tested on the current symbol, and at every bar the function looks at how much each system has made over a recent window of bars. It then trades the signals from whichever system has been most profitable over that window. When one system cools off and another heats up, it rotates to the hotter one. To avoid jumping out of a trade mid-position, it only switches while it is flat (not currently holding a long).

The Functions

There is one function per number of systems, from 2 up to 7. The number in the name is how many systems you are rotating between. Each system contributes a Buy/Sell pair of arrays, and the final argument is the LookBack window. So RotateSignals2 takes 4 signal arrays (2 pairs) plus LookBack, RotateSignals3 takes 6, and so on up to RotateSignals7 with 14 signal arrays.

RotateSignals2(Buy1, Sell1, Buy2, Sell2, LookBack)
RotateSignals3(Buy1, Sell1, Buy2, Sell2, Buy3, Sell3, LookBack)
RotateSignals4(Buy1, Sell1, Buy2, Sell2, Buy3, Sell3, Buy4, Sell4, LookBack)

The same pattern continues through RotateSignals5, RotateSignals6 and RotateSignals7. To rotate between more systems, just use the function whose number matches.

Parameters

ParameterDescription
Buy1, Sell1, Buy2, Sell2, …The buy and sell signal arrays for each of your systems, given in pairs. The buy and sell arrays for one system go next to each other.
LookBackThe number of bars used to judge how each system has been performing. At each bar the function compares the systems over this window and trades the best one. Must be at least 2.

Usage

You don't assign the result to anything. The function sets the Buy and Sell variables for you to the combined, rotated signals, so the formula can be back-tested directly. The example below rotates between a moving-average crossover system and a MACD system, judging them over the last 250 bars.

BuyMA  = Cross( C, EMA( C, 30 ) );
SellMA = Cross( EMA( C, 30 ), C );

BuyMACD  = Cross( MACD(), Signal() );
SellMACD = Cross( Signal(), MACD() );

RotateSignals2( BuyMA, SellMA, BuyMACD, SellMACD, 250 );

// Buy and Sell are now set to the rotated system and can be back-tested.
Note

For the first LookBack bars there isn't enough history to compare systems, so the function simply follows the first system until the window fills up. Because each system is back-tested internally to measure its performance, the symbol needs enough data for the LookBack window to be meaningful.