Skip to content

Indicator library

Find a calculation, understand its inputs, and use it directly in your strategy. No imports or setup code are needed in TradeScript.

If you are new to indicators, start with SMA and EMA for price trends or RSI for momentum. Then read conditions and indicators to combine them into entry and exit rules.

Find an indicator by task

I want to… Open Common functions
Smooth price or compare trends Moving averages sma, ema, wma, hull_ma, kama
Measure momentum or a change in momentum Momentum and oscillators rsi, macd, roc, stochastic
Measure trend strength or direction Trend strength adx, plus_di, minus_di, aroon
Measure volatility or locate price within a range Volatility and channels atr, bb_upper, donchian_upper, keltner_upper
Include traded volume in a signal Volume indicators vwap, vwma, obv, mfi, cmf
Detect a crossing, change or recent extreme Series helpers crossover, highest, change, rising

Each topic gives usable calls, argument order, defaults, result units and example conditions. Search for a function name to jump to its explanation.

Read a call

rsi(14) > 50 means: calculate RSI from the close prices using a 14-bar period, then compare the current reading with 50. The period and the threshold do different jobs.

Form Meaning
sma(20) A 20-bar simple moving average of close.
sma(close, 20) The same calculation with its input written explicitly.
sma(high, 20) Average the high prices instead.
sma(close) Use the default SMA period of 20.
sma(20)[1] The moving-average reading one bar ago.
atr(14) Use high, low and close together to calculate ATR.

For close-based indicators, give a numeric period or an explicit input. An empty call such as sma() or rsi() does not automatically select close. Calls such as obv() and vwap() have their own documented empty-call form.

Arguments are positional: write rsi(14), not rsi(period=14). A custom period held in a definition needs an explicit input, such as sma(close, length); the period-only shorthand recognises a literal number. bars means the instrument's complete price-and-volume history, used by the few functions documented with an explicit bars argument. It is not an import.

Know what the result means

Moving averages and channel levels are prices. ATR is a price distance. RSI is a 0–100 reading. roc(14) returns percentage points, so 5 means a 5% price change; pct_change(close, 14) returns a fraction, so the same change is 0.05. These are not position sizes.

Series-returning indicators can be compared directly in TradeScript. Use [1] for their previous reading. Helpers such as highest and mean instead return one value now; they do not have a [1] history of their own. The individual entries make this distinction explicit.

Multi-line indicators have a function for each usable line. Write macd_signal(12, 26, 9) or bb_upper(20, 2) rather than trying to access .signal or .upper on an object. See availability and special cases.

Use an indicator in a strategy

//@version=1
symbol: TCS
run: daily
size: 5% per instrument
entry:
    long when: rsi(14) > 50 and close > sma(20)
exit:
    long when: close < sma(20)

The entry requires both RSI above 50 and price above its 20-bar average. The exit checks price against that same average. This is a state test: use crossing syntax if the rule should be true only on the transition bar.

Periods count the bars used by the calculation, not calendar days. Twenty daily bars and twenty 15-minute bars describe different windows. A scheduled evaluation does not itself convert the underlying bars to that interval; check your instruments and schedule.

History and availability

A calculation needs its input fields and enough history. Volume indicators need meaningful volume; OHLC indicators need high and low as well as close. A crossing also needs a previous indicator reading. Some functions produce partial or initialised values before a full lookback; others produce missing values. Do not treat the first finite number as proof that your intended window is complete.

These guides cover TradeScript's current indicator selection and core series helpers, rather than every calculation in the broader analysis library. Availability explains that scope, the few container-only names, recognised names without a standard binding, and current multi-instrument limitations. For ranking and external data fields, use the separate functions catalog.