Skip to main content

TypeScript Stdlib

TradeScript plotted indicator output produced with typed authoring helpers
Use the smallest helper that directly expresses the calculation, then verify the plotted series and warm-up behavior on the chart.

Custom indicators read the market series supplied by the chart, calculate values, and emit plots, markers, alerts, or drawing commands. Load secondary market data in your application, then use security(...) to read it in the indicator. The standard helpers cover moving averages, oscillators, series math, cross detection, and NaN handling.

Find a helper by task

Start from what you are trying to do — each row links to the matching section below:

TaskReach forSection
Read price / volume dataclose, high, low, volume, hl2, hlc3Market series
Smooth a series / follow trendsma, ema, rma, wma, vwma, almaMoving averages
Measure momentum or overbought/oversoldrsi, stoch, macd, cci, mfi, willr, tsiOscillators / stats
Measure volatility / build bandsstdev, atr, tr, bbands, supertrendVolatility
Detect signal crossingscrossover, crossunder, crossCrosses
Find extremes and swingshighest, lowest, pivothigh, pivotlowSeries ops / Pivots
Combine or compare two seriesadd, sub, mul, div, gt, lt, iffMath
Handle warm-up gaps (NaN)na, nz, fixnanNaN helpers
Read the latest valuelastMath — utility
Branch on session / timeframeyear, month, hour, isintraday, isdailyCalendar, Authoring surface

The standard library is modular. Import the authoring API, technical analysis, and series math from the paths below.

Imports

ImportContents
@tradescript/pro/sdk/indicatorsAuthoring: indicator, input, plot, marker, alert, draw, market series, security, context helpers
@tradescript/pro/sdk/indicators/taTechnical analysis
@tradescript/pro/sdk/indicators/mathSeries arithmetic, comparisons, trig
import { indicator, input, plot, close } from '@tradescript/pro/sdk/indicators'
import * as ta from '@tradescript/pro/sdk/indicators/ta'
import { add, sub, mul } from '@tradescript/pro/sdk/indicators/math'

export default indicator('Bollinger', () => {
const length = input.int('Length', 20, { id: 'length', min: 1 })
const mult = input.number('Multiplier', 2, { id: 'mult', step: 0.1 })
const basis = ta.sma(close, length)
const dev = mul(ta.stdev(close, length), mult)
plot.line(basis, { title: 'Basis', color: '#94a3b8' })
plot.band(add(basis, dev), sub(basis, dev), { color: '#8b5cf6', fillOpacity: 0.15 })
}, { pane: 'price' })

Editor support

Use the TypeScript language service in your application editor for autocomplete, signatures, hover information, and go-to-definition.

Market series

When to use: these are your raw data — every calculation starts by reading one of them. All are full-length arrays aligned to the loaded bars.

ExportMeaning
time / open / high / low / closeOHLC + time
volume / turnoverSize
takerBuyVolume / openInterest / fundingRateCrypto extras
hl2 / hlc3 / ohlc4Composites

Math (@tradescript/pro/sdk/indicators/math)

When to use: element-wise arithmetic and logic across whole series — combining bands, building conditions, avoiding hand-written loops.

Arithmetic

add, sub, mul, div, abs, neg, pow, sqrt, log, log10, exp, sign, floor, ceil, round

Aggregates

max2, min2, max(...), min(...), avg(...)

Trig

sin, cos, tan, asin, acos, atan

Comparisons / conditionals

eq, neq, gt, ge, lt, le, isZero, toBool, iff

Utility

last — read the most recent value of any series (for alerts, logging, labels).

Root package re-exports common math helpers for short demos; prefer the /math subpath in production code.

TA (@tradescript/pro/sdk/indicators/ta)

When to use: classic technical analysis over whole series — smoothing, momentum, volatility, volume flow, extremes, and signal crossings. Prefer these over manual loops; they handle warm-up windows consistently.

Moving averages

Smooth a series or build a trend baseline. sma, ema, rma, wma, vwma, swma, alma

Volatility

Size moves, stops, and band widths. stdev, variance, dev, tr, atr

Oscillators / stats

Momentum, mean reversion, and statistical relationships. rsi, stoch, percentrank, correlation, linreg, sar, dmi, tsi, cci, mfi, willr, macd, bbands, supertrend

Volume / price

Flow and volume-weighted baselines. accdist, obv, vwap, sessionVwap, mom

Pivots

Local swing highs and lows. pivothigh, pivotlow

Series ops

Windows, extremes, accumulation, and change over time. highest, lowest, highestbars, lowestbars, change, roc, cum, sum, offset, rising, falling

Crosses

Turn two series into entry/exit signals. crossover, crossunder, cross Both arguments must be series. For a constant level, map a flat series first:

const level = rsi.map(() => 70)
const overbought = ta.crossunder(rsi, level)

NaN helpers

Deal with warm-up gaps before plotting or comparing. na, nz, fixnan

Calendar (UTC from time)

Branch on time-of-day, day-of-week, or seasonality. year, month, dayofmonth, dayofweek, hour, minute, second, weekofyear

Warm-up positions are NaN for numeric series and false for boolean signals.

Authoring surface (root package)

When to use: everything that is not a calculation — declaring the indicator, its inputs, outputs, secondary symbols, and runtime context.

GroupAPIs
Factoryindicator, builtIn, isBuiltInIndicatorReference
Inputsinput.int / number / bool / source / color / select / text / symbol
PlotsSee Indicator language — Plots
Outputsmarker, alert, draw
Multi-seriessecurity, listSecurities
Contextruntime, period, interval, ticker, tickerid, isintraday, isdaily, isweekly, ismonthly, isdwm
Errorserror(message)IndicatorError

TypeScript support

The published types cover plot kinds, shapes, security map modes, context helpers, and every function listed on this page.