> ## Documentation Index
> Fetch the complete documentation index at: https://docs.0xarchive.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Indicators (ta)

> Moving averages, oscillators, bands and the rest of the ta library, matching TradingView.

Instances with their own state. Create at the top level, update in a handler. Update an instance once per run, on every bar: an instance only advances when `update` runs, so updating inside an `if` gives a different result (Pine's call-site rule, made visible). Values match TradingView's built-ins, including their seeds and how they treat `na`.

## ta

<ResponseField name="sma()" type="(length: number): Average">
  Simple moving average of the last `length` values.
</ResponseField>

<ResponseField name="ema()" type="(length: number): Average">
  Seeded with the simple average of the first `length` values, as TradingView's `ta.ema`.
</ResponseField>

<ResponseField name="rma()" type="(length: number): Average">
  Wilder's average, seeded like `ema`.
</ResponseField>

<ResponseField name="wma()" type="(length: number): Average">
  Linearly weighted moving average: the newest value weighs `length`, the oldest 1.
</ResponseField>

<ResponseField name="hma()" type="(length: number): Average">
  Hull moving average, a weighted average of weighted averages that lags less.
</ResponseField>

<ResponseField name="vwma()" type="(length: number): Indicator<[value: number, volume: number], number>">
  Volume-weighted moving average of the last `length` values.
</ResponseField>

<ResponseField name="stdev()" type="(length: number): Average">
  Standard deviation of the last `length` values, over `length` as TradingView divides (not `length - 1`).
</ResponseField>

<ResponseField name="variance()" type="(length: number): Average">
  Variance of the last `length` values, the square of `stdev`.
</ResponseField>

<ResponseField name="highest()" type="(length: number): Average">
  The highest of the last `length` values, the current one included.
</ResponseField>

<ResponseField name="lowest()" type="(length: number): Average">
  The lowest of the last `length` values, the current one included.
</ResponseField>

<ResponseField name="highestBars()" type="(length: number): Average">
  Bars since the highest or lowest value in the window, as a negative offset like TradingView's.
</ResponseField>

<ResponseField name="lowestBars()" type="(length: number): Average" />

<ResponseField name="change()" type="(length?: number): Average">
  value − value `length` bars ago.
</ResponseField>

<ResponseField name="mom()" type="(length: number): Average">
  Momentum: the value less the value `length` bars ago.
</ResponseField>

<ResponseField name="roc()" type="(length: number): Average">
  Rate of change: the percent change from the value `length` bars ago.
</ResponseField>

<ResponseField name="rsi()" type="(length: number): Average">
  Relative strength index, 0 to 100, on Wilder's averages.
</ResponseField>

<ResponseField name="cci()" type="(length: number): Average">
  Commodity channel index: the distance from the `length`-bar average in units of mean deviation, over 0.015.
</ResponseField>

<ResponseField name="linreg()" type="(length: number, offset?: number): Average">
  The least-squares line through the last `length` values, read `offset` bars back from its end (0, the default, is the current bar).
</ResponseField>

<ResponseField name="percentRank()" type="(length: number): Average">
  The percent of the previous `length` values that are at or below the current one.
</ResponseField>

<ResponseField name="cum()" type="(): Average">
  The running sum of every value since the first bar.
</ResponseField>

<ResponseField name="rising()" type="(length: number): Indicator<[value: number], boolean>">
  True when the value has risen on each of the last `length` bars (a step within 1e-10 does not count).
</ResponseField>

<ResponseField name="falling()" type="(length: number): Indicator<[value: number], boolean>">
  True when the value has fallen on each of the last `length` bars.
</ResponseField>

<ResponseField name="crossover()" type="(): Indicator<[a: number, b: number], boolean>">
  True on the bar where `a` goes from at or below `b` to above it.
</ResponseField>

<ResponseField name="crossunder()" type="(): Indicator<[a: number, b: number], boolean>">
  True on the bar where `a` goes from at or above `b` to below it.
</ResponseField>

<ResponseField name="cross()" type="(): Indicator<[a: number, b: number], boolean>">
  True on the bar where `a` crosses `b` either way.
</ResponseField>

<ResponseField name="barsSince()" type="(): Indicator<[condition: boolean], number>">
  Bars since `condition` was last true: 0 on a bar where it is, `na` until the first time.
</ResponseField>

<ResponseField name="valueWhen()" type="(occurrence?: number): Indicator<[condition: boolean, value: number], number>">
  `value` on the bar where `condition` was true, the `occurrence`-th time back (0, the default, is the latest).
</ResponseField>

<ResponseField name="pivotHigh()" type="(left: number, right: number): Indicator<[value: number], number>">
  A pivot high: a value higher than the `left` before it and the `right` after it. It is known
  only `right` bars later, so it is returned on that bar, `na` on every other.
</ResponseField>

<ResponseField name="pivotLow()" type="(left: number, right: number): Indicator<[value: number], number>">
  A pivot low, as `pivotHigh`: returned `right` bars after the low, `na` on every other bar.
</ResponseField>

<ResponseField name="macd()" type="(fast: number, slow: number, signal: number): Indicator<[value: number], MacdValue>">
  MACD: the fast EMA less the slow EMA, its `signal`-bar EMA, and the difference of the two as the histogram.
</ResponseField>

<ResponseField name="bb()" type="(length: number, mult: number): Indicator<[value: number], BandsValue>">
  Bollinger Bands: the `length`-bar SMA, and bands `mult` standard deviations either side.
</ResponseField>

<ResponseField name="kc()" type="(length: number, mult: number, useTrueRange?: boolean): Indicator<[bar: BarView], BandsValue>">
  Keltner Channels: the `length`-bar EMA of the close, and bands `mult` times the `length`-bar EMA of the true range (or of the bar's range) either side.
</ResponseField>

<ResponseField name="stoch()" type="(length: number): Indicator<[close: number, high: number, low: number], number>">
  Stochastic: where the close sits in the `length`-bar range of highs and lows, 0 to 100. Smooth it with `ta.sma` for %K and %D.
</ResponseField>

<ResponseField name="mfi()" type="(length: number): Indicator<[bar: BarView], number>">
  Money flow index, 0 to 100: an RSI of the typical price weighted by volume.
</ResponseField>

<ResponseField name="obv()" type="(): Indicator<[bar: BarView], number>">
  On-balance volume: the running sum of volume, added on up closes and taken away on down closes.
</ResponseField>

<ResponseField name="tr()" type="(handleNa?: boolean): Indicator<[bar: BarView], number>">
  True range. `handleNa` as TradingView: on the first bar, high − low.
</ResponseField>

<ResponseField name="atr()" type="(length: number): Indicator<[bar: BarView], number>">
  Average true range: Wilder's average of the true range over `length` bars.
</ResponseField>

<ResponseField name="dmi()" type="(diLength: number, adxSmoothing: number): Indicator<[bar: BarView], DmiValue>">
  Directional movement: +DI, -DI and the ADX, which measures trend strength whatever its direction.
</ResponseField>

<ResponseField name="supertrend()" type="(factor: number, atrLength: number): Indicator<[bar: BarView], SupertrendValue>">
  Supertrend: a trailing line `factor` ATRs from the price that flips side when the close crosses it, with its direction.
</ResponseField>

<ResponseField name="vwap()" type="(anchor?: VwapAnchor): Indicator<[bar: BarView], number>">
  Volume-weighted average price from quote and base volume, reset at each anchor (UTC).
</ResponseField>

## Indicator

<ResponseField name="update()" type="(...values: In): Out" />

<ResponseField name="value" type="Out">
  The value after the latest update in this run.
</ResponseField>

<ResponseField name="confirmed" type="Out">
  The value as of this stream's last closed bar. Read it from other streams' handlers.
</ResponseField>

## Average

```ts theme={"theme":"github-dark"}
type Average = Indicator<[value: number], number>;
```

## MacdValue

<ResponseField name="macd" type="number" />

<ResponseField name="signal" type="number" />

<ResponseField name="histogram" type="number" />

## BandsValue

<ResponseField name="basis" type="number" />

<ResponseField name="upper" type="number" />

<ResponseField name="lower" type="number" />

## DmiValue

<ResponseField name="plus" type="number" />

<ResponseField name="minus" type="number" />

<ResponseField name="adx" type="number" />

## SupertrendValue

<ResponseField name="line" type="number" />

<ResponseField name="direction" type="number">
  1 up, -1 down
</ResponseField>

## VwapAnchor

```ts theme={"theme":"github-dark"}
type VwapAnchor = 'session' | 'week' | 'month' | 'quarter' | 'year' | Time;
```

## Next step

Continue with [Plots](/terminal/reference/plots).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.