How to restrict trades to only a specific number — Tradetron Community
← Community

How to restrict trades to only a specific number

Strategy 1,449 views

Nand Kapadia

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?

Tradetron Team Tradetron team

Use Open Positions Detail instead of Positions Detail. Positions Detail counts every trade including closed ones, which is why it stops at X. Open Positions Detail counts only positions open now and is the default for “only N open at a time”:

  • Entry (list strategy): Open Positions Detail('All', 'All', |YOUR LIST|, 'count') < Number(X) AND your setup. count is the number of distinct instruments open right now.

As one stock exits, the count drops and a new one can enter. No Python needed. One limit: if several stocks signal in the same check, they can all enter before the count updates, so you may briefly hold more than X. A smaller list is the only fix for that case.

Example: X = 3, you hold 3 stocks. One hits its exit, the count drops to 2, and the next stock that meets your entry is bought. Test in Live Offline first. Keyword reference: Keyword Documentation — Tradetron

:sparkles: Answer written with AI from Tradetron docs (Oct 2026). Original replies are kept above. Spot something wrong? Reply below.

Tradetron अब हिन्दी में भी उपलब्ध है हिन्दी में देखें Continue in English