Steve,
This will rotate your funds at the beginning of the month if SPY is above it's
200 day moving average. It will pick the 3 strongest performers over the last
120 days.
SetBacktestMode(backtestRotational);
SetTradeDelays(1,1,1,1); // everything delayed 1 day
SetOption("UsePrevBarEquityForPosSizing", True);
SetOption("MinShares", 10);
SetOption("AllowPositionShrinking",True);
SetOption("AccountMargin",100);
Totalpositions = 3;
MAFilter = Foreign("SPY","C") > MA(Foreign("SPY","C"),200);
PositionScore = MAFilter * ROC(C,120);
PositionSize = -100/Totalpositions;
SetOption("WorstRankHeld", Totalpositions + 1);
SetOption("MaxOpenPositions", Totalpositions );
m = Month();
newMonth = m != Ref( m, -1);
PositionScore = IIf(PositionScore < 0, 0, PositionScore); // Long only
PositionScore = IIf(newMonth, PositionScore, scoreNoRotate);
--- In [email protected], "Steve_Almond" <m...@...> wrote:
>
> I'm able to use the backtester for Fund rotation (and I understand the use of
> 'Foreign' symbols.
> I cannot seem to combine the two, though.
>
> I want to invest in 3 funds from a group of 10 using the best 6 month return
> to select the top 3. I use PositionScore = C/Ref(C,-6);
>
> BUT, I only want to invest in those funds if the ETF SPY is above its 10
> month MA.
>
> Can anyone suggest how to accomplish this?
>
> Below is my attempt. It correctly invests only when SPY is above its 10 month
> MA, but ALWAYS selects the first 3 funds in the list.
>
> Steve
>
> EnableRotationalTrading();
> SetOption("WorstRankHeld",3);
>
> j=Foreign("SPY","C");
> PositionSize = -100/3;
> PositionScore = C/Ref(C,-6)AND j>MA(j,10);
>