How to restrict trades to only a specific number

Hello!

I want to create a strategy that only trades in a given number of stocks at a time, e.g., it can only have the given number of stocks being held at a given point in time. If an exit condition is met and a stock position is closed, it should continue to pick up one more stock if it meets the strategy. If I use Position Details with a count <= X, it does not continue to pick up more stocks if it has already picked up X stocks even though the current positions of stocks are less than X (i.e., it considers zero holdings when I don’t want it to consider zero holding).

When I asked the Tradetron chat, they said we need to write custom Python code to do that. This seems a bit too complex. Do you have any ideas on how this can be done?

One solution I thought of is to use a runtime variable, increment it every time it meets an entry condition, and decrease it by one when the exit condition is met. Would this work?