Can you have 2 different entry rules and position sizes in the same system?

I'm trying to test a simple system that owns 75% SPY and then uses a momentum rule to buy an ETF with the remaining 25%. The 25% position should use rotational trading or maybe PositionScore for selection. I can't tell if the position sizes can be changed in the code but my test so far indicates that it cannot.

Ideally, the system would use Rotational Trading so worstrankheld can generate the exit of the non-SPY ETF but I can't figure out how to structure that. The code below is a poor attempt using PositionScore and never buys SPY as I planned.

Many thanks to all for your input.

SetOption("InitialEquity", 100000 ); // set initial equity = 100K
//Note position size is less than 100% with the rest used for SPY
BuyPrice = Open;
SellPrice = Open;

//Buy large position in SPY
SetForeign( "SPY" );
Buy = C>0;

//Buy momentum based ETF position
SetOption( "MaxOpenPositions", 1 );
Mmtm = (ROC(C,13) + ROC(C,52))/2; 
Trend_cond = MA(C,20) > Ref( MA(C,20), -2);
Buy = Trend_cond;
Sell = !Trend_cond;
PositionScore = IIf(Trend_cond, 1000+mmtm, 0); //1000+mmtm; 
NumPos = 1; 	//Number of allowed positions
//Exit after 8 weeks and find new position based on momentum
bars = 8; // exit after 8 bars
ApplyStop( stopTypeNBar, stopModeBars, bars, True );

If you write down all the steps chronologically (using pen & paper), chalking a code won't be far.

You want to park 75% in SPY, and, play rotationally on remaining 25% basis PositionScore. And not a penny from this 25% should go into SPY again.

Simply create a watchlist (excluding SPY) with the universe of instruments where you want to deploy 25% and run backtest on it.

Please ensure:

SetBacktestMode( backtestRotational );



There's a KB - How to exclude top ranked symbol(s) in rotational backtest. It fairly introduces CBT application. Learning CBT is important, as after few endeavors you would feel the need of it.

Moreover, this example code shows how to liquidate 50% on first profit target, 50% on next profit target and everything at trailing stop. That underlying logic will help you further meticulously set-up entry, exit, stop-loss.

1 Like

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