Skip to content

Read and change your strategy

A TradeScript file answers four questions: what to trade, when to check, how much to allocate, and what opens or closes the position.

Instrument and schedule

symbol: TCS
run: daily

symbol identifies one instrument. run describes the schedule. Indicator lookbacks count bars: a 20-period indicator on daily data differs from one on 15-minute data.

Position size

size: 5% of portfolio per instrument

This targets a percentage allocation. Capacity and whole-unit rounding may reduce the admitted amount. A continuing independent holding is not automatically topped up whenever the condition stays true. Read position sizing before changing allocation.

Conditions

long when: rsi(14) > 45 and ema(50) > ema(200)

and means both tests must be true; or means at least one must be true. A long position benefits from a rise in price. A short benefits from a fall, subject to instrument and account support.

The 14 in rsi(14) is a lookback, while 45 is a threshold. The numbers in ema(50) and ema(200) are lookbacks too.

Add a note

# Enter only when the shorter trend is above the longer trend.

Use # for a line comment or /* ... */ for a block comment. Ordinary // is not a comment. The //@version=1 line is optional; leaving it out uses version 1. If included, keep it before declarations.

Make a controlled change

  1. Describe the change in words.
  2. Edit the corresponding line or condition.
  3. Check diagnostics.
  4. Backtest with comparable settings and inspect the trades.

Keep an earlier copy so you can compare what changed.

Entry and exit are separate decisions

Changing an entry threshold does not change the exit threshold. If your rule enters above RSI 50 and exits below 45, a reading of 48 can leave an existing position open while preventing a new entry. Write an exit for the behaviour you intend rather than assuming the opposite of entry happens automatically.

For a conditional universe, the same expression uses each instrument's own data. The scope supplies the eligible list; sizing determines whether positions have independent targets or share a budget. A hold: strategy instead describes a target selection and allocation.

Change the matching part of the document

Desired change Edit Check afterwards
Trade another instrument symbol: or the fixed list Identifier, available history and account support.
Use a shorter horizon run: and/or indicator periods Which bar interval each lookback counts.
Increase allocation size: Basis, scope, combined exposure and capital limits.
Enter only on a transition Comparison → crosses over / crosses under A crossing is a one-bar event.
Close on a price move stop: / target: Units and long/short direction.
Reuse a rule A named define Valid names and definition dependencies.

Comments explain intent and do not affect orders. Remove or update a comment if the nearby rule changes; an old comment can be as misleading as an old threshold.