Weekly Regime filter + monthly rotation

Help needed please with the following rotation system:

I am trying to code my momentum rotation system to check at the end of every week if it should move to 100% cash or not based on a simple MA Index Filter. And to check only at the end of month to rebalance the stocks based on ranking and worstrank.

So weekly decision if cash call or not. And monthly decision on rebalancing the stocks.

OrigPositionSize = -100 / Totalpositions ;
SPX = Foreign("NIFTY 500","C");
Level = 50;
BullMarket = SPX>MA(SPX,Level);
BearMarket = SPX<MA(SPX,Level);LastDayOfWeek = TimeFrameExpand(1, inweekly, expandPoint);
TradeDay = LastDayOfWeek;
LastDayOfMonth = TimeFrameExpand(1, inmonthly, expandPoint);
MonthEnd = LastDayOfMonth;
PositionScore = IIf(TradeDay && BearMarket, 0, IIf(MonthEnd && BullMarket, IIf (MyFilter,0,Score) , scoreNoRotate));
PositionSize = IIF(TradeDay && BearMarket,0, OrigPositionSize); (edited)

The issue I am facing with this code: It is moving to cash correctly if the index filter is bearish at the end of the week. It is also correctly rebalancing the stocks based on the ranking at the end of the month.

However in case i am in cash and the weekly index filter turns bullish, It does not move to equity till the end of month. Could some ami expert please help me how to modify this code?

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.