Skip to content

What is TradeScript?

TradeScript is a language for describing trading strategies. You write the instrument, schedule, position size, and rules for entering and exiting.

You do not need to learn Python to start. A strategy is a short text document, with named sections that read from top to bottom.

Begin with a trading rule

For example: “Buy TCS when RSI is above 50 and the shorter moving average is above the longer one. Exit when RSI falls below 45.”

//@version=1
symbol: TCS
run: daily
size: 5% of portfolio per instrument
entry:
    long when: rsi(14) > 50 and ema(50) > ema(200)
exit:
    long when: rsi(14) < 45

What you need to know

  • Instrument: the symbol you want to trade.
  • Schedule: how often you check your rules.
  • Position size: how much to allocate when a rule opens a position.
  • Entry and exit: conditions for opening and closing.

An indicator is a calculation over market data. rsi(14) means a 14-period RSI; ema(50) means a 50-period exponential moving average. A bar is one interval of price data. On daily data, 14 periods means 14 daily bars.

Learn or look up a detail

If you want to… Open…
Start from zero Write your first strategy
Understand a script Read and change a strategy
Check historical behaviour Backtest your strategy
Find exact syntax Language reference
Write in Python instead Python guide

Examples teach language and structure. They do not establish that a rule will make money.

What changes as you learn?

Start with one instrument and explicit rules. Once you can explain a trade, add protection, then decide whether multiple instruments should trade independently or share a budget.

Strategy you want to describe Shape to learn
Enter and exit one instrument on signals symbol: with entry: / exit:.
Apply the same rules to a fixed list universe: with conditional entries.
Maintain a selected portfolio universe: with hold:.
Write imperative logic or custom Python calculations The separate Python guide.

A TradeScript file describes intent. A valid script still needs instruments, data, capital and execution support in the selected environment. You can learn the language using a draft and historical backtest before creating a running deployment.

A few terms you will meet

A condition is a true-or-false test. A lookback is the number of bars a calculation uses. A target is a desired quantity or allocation; a fill is an executed trade. A rebalance adjusts holdings toward a target portfolio. These distinctions explain why a signal can match without producing the exact holding you expected.