Rotational System with safe resort to GLD

I’m trying to code a simple rotational system that rotates between a dozen stocks. I can code what I want just by adapting the simple code that comes with Amibroker (in the systems folder entitled ExampleRotational)

I’d like to add a market filter, that when the market is falling, will give a high positonscore to GLD (or a similar equity). Does anyone have a suggestion how I could do that?

Something along these lines… you name it…

...
SetBacktestMode( backtestRotational );

/// @link https://www.amibroker.com/guide/afl/setforeign.html
SetForeign( "^GSPC" );
// your market filter
MarketIsFalling = C < MA( C, 200 ) AND ROC(C, 250) < 0;// just some basic market filter EXAMPLE
RestorePriceArrays();

PositionScore = Iif( MarketIsFalling, /*then prefer weakened symbols*/ 10000 - ROC( C, 60 ), scoreNoRotate );
...

etc…

3 Likes

That looks perfect, thanks very much fxshrat!