The problem is in the change in entry and exit in the classic rotation script. Your Positions exit only when they meet Cond1 or Cond2, but they don't get "rotated out" due to their rsi being greater than 3 other symbols. At the same time, new entries can be created due to the rsi criteria.
So, you can either:
1. add the rsi exit criteria, like in the original rotation script. This favors new entries (vs. existing Positions) based on rsi .
- or -
2. add another entry condition to take new Positions only if the number of "symbols" having Positions is less than 3, i.e.,
number. This method favors existing Positions vs. new Positions with lower rsi.
Assuming you want #2, do this -
CODE:
Please log in to see this code.
Finally, note that it's possible for this script to be holding fewer than
number Positions since the exit logic can knock out the symbols that happen to have the lowest rsi. Conceivably you could have a bar here and there where there are 0 Positions.
-----
Edit:
I just realized that the ActiveSymbols() solution won't generate the proper exits in realtime since it requires that the Positions actually exit on the next bar; i.e., it needs to peek, though legally. Anyway, this can be worked out too, just with different logic that doesn't rely othe ActivePositions list.