Testing a Strategy - Any mistakes in the coding? — Tradetron Community
← Community

Testing a Strategy - Any mistakes in the coding?

Strategy 1,864 views

Morning Star

Hello experts,
I want to buy or sell TSLA based on a simple strategy. In Set 1 I have conditions for buy(close above or below 5EMA in 1 minute) and exit(Leg exit or Leg TSL). In Set 2 I have conditions for sell and exit. I want the strategy to take second set position only if the first set is exited. So I used Net Qty keyword. Please can anyone let me know if there are any errors in this.

Lion Algos

Looks good.
If it is not working you can try use ‘Net Quantity =! 0’ in exit conditions instead of ‘Traded instrument’

RK GUPTA

USE ; open position=0 in AND mode

Abhijit Bhattacherjee

In the first line of exit condition, there is just one condition on the left side which traded instrument name, nothing on the right side. Will this work?

Lion Algos

Not sure. Try paper trading

Abhijit Bhattacherjee

As per my understanding, this condition will not work. Not sure why you kept traded instrument name in your exit condition without qualifying it with a value on the right side.

Abhijit Bhattacherjee

Yes, this is the correct way of checking. Better to use open position rather than net quantity.

Tradetron Team Tradetron team

A few things to check in these sets.

1. Every condition line needs both sides

A Traded Instrument with nothing on the right side compares nothing, so it may never be true. Each line needs a left value, an operator and a right value, e.g. LTP ( TSLA ) > Position ( EMA ( CLOSE ( Symbol ( TSLA, 1m ) ), 5 ), -1 ).

2. “Set 2 only after Set 1 has exited”

  • Net Quantity gives the open quantity of an instrument across the whole strategy. Both sets trade TSLA, so it nets their positions together.
  • Net Quantity ( TSLA ) == Number ( 0 ) in Set 2’s entry works only if nothing else is open in TSLA.
  • A cleaner way is a runtime flag: Set 1 entry runtime s1open = Number(2), Set 1 exit runtime s1open = Number(1), and Set 2 entry checks Get Runtime ( s1open ) == Number ( 1 ). Initialize it to Number(1).

3. Exits

Use Leg Exit or Leg TSL inside a Repair Once pointed at the leg (Entry, set, condition, leg), or compare LTP with Traded Instrument ( Entry, price, ... ) in the Set Exit.

Test in Live Offline and read the Notification Log. 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.