Staggered trade entry

I want to design a system that holds multiple positions for a fixed time-period and makes only one entry and one exit per day. The idea is to avoid having the entire portfolio change at the same time. Instead, only one position changes each day. How can this be implemented?

If you’re comfortable writing a low-level CBT, it would be quite straightforward: each day, only open a trade for the first entry signal that you encounter which does not correspond to a trade that’s already open.

Without a CBT, I’m not sure you can accomplish this in a robust manner. For example, you could use StaticVarGenerateRanks on your trading universe, and then require a rank of 1 to generate the Buy signal. But this wouldn’t work on days where the top rank is for a trading instrument that already has an open trade – you would just have no entry on that day.

Thank you Matt. I'll have a look at the CBT documentation.

I believe that you can do this without CBT. You just need to use Nbar stop via ApplyStop, backtestRegularRaw mode and limit the number of positions via SetOption.

1 Like

Thank you for the reply Tomasz. I was wondering about that. Is the MaxOpenPositions option a scalar or an array? To clarify my intent, during the first part of the backtest, I want to increment the number of open positions by one each day until the max is reached. Then maintain the maximum number of open positions for the rest of the backtest.

MaxOpenPos is scalar. But you don't need to increment it day by day. Instead time your entries at the beginning of backtest it is easy using Status("stocknum") that gives consecutive symbol number. You can simply fill N first bars in Buy arrays with False, where N is symbol number. This way you will enter one symbol at a time at the beginning.

1 Like

If I'm not mistaken, that approach will only work if there are no other Buy criteria. What happens if on Day 1 of the backtest, only symbols #7 and #22 generate a Buy signal, and #22 has the higher position score and should therefore be the only trade opened on Day 1? Using the "stocknum solution", you won't enter any trade on Day 1, and symbol #22 won't be eligible for entry until Day 22 of the backtest.

Yes, I should have mentioned this in my first post. The positions are ranked by position score and the universe of symbols under test is much larger than MaxOpenPositions.

There are many ways, you can use CBT or you can use StaticVarGenerateRanks and then use ranked order instead of stocknum order. CBT has advantage of getting signals already ranked by position score so it can be actually easier in that case.

1 Like

Thanks for following up. The CBT seems to be most sensible approach. I'll probably find other uses for the CBT as I get deeper into this.