I’m trying to make a rotational system with a market regime filter, that when the market filter turns off, the positions exit only when they drop below the worst rank. In the example below, the system buy four stocks from a watchlist. I can have the market filter work, with the Iif statement and the scoreNoRotate or scoreExitAll functions. With scoreNoRotate, when the market filter turns off, it will continue to hold the same four positions until the market filter turns back on. With scoreExitAll, it will exit all four positions when the market filter turns off. What I would like it to do, is when the market filter turns off, to only exit each of the four positions when they fall below the WorstRankHeld set at 6 in my example. It shouldn’t enter any new positions until the market filter turns back on.
Does anyone know of a way that I might be able to do this?
//Exits each position once it rises a number of positions
_SECTION_BEGIN("Rotational System with Filter");
Float = 100000;
SetPositionSize( 100 / 4, spsPercentOfEquity );
// trade on close
SetTradeDelays( 0, 0, 0, 0 );
BuyPrice = Close;
//Market regime filter
SetForeign( "SPY" );
SetBacktestMode( backtestRotational );
//PositionScore = IIf( MarketIsGood, Score ,scoreNoRotate);//if this is uncommented it holds the same stocks while market filter is off
PositionScore = IIf( MarketIsGood, Score ,scoreExitAll);//if this is uncommented it sells all the stocks while market filter is off
//is there a way to have the code, when the market filter turns off, to only sell the stocks when they have dropped below the worst rank