Skip to main content

ta.atr#

Wilder's Average True Range over the last length bars ending at i.

SYNTAX#

function ta.atr(high: (number | null)[], low: (number | null)[], close: (number | null)[], length: number, i: number): number | null

ARGUMENTS#

  • high ((number | null)[]) — High series, oldest-first.
  • low ((number | null)[]) — Low series, oldest-first.
  • close ((number | null)[]) — Close series, oldest-first.
  • length (number) — Smoothing length. Must be positive.
  • i (number) — Current bar index. First valid output at i = length.

RETURNS#

number | null — ATR value, or null during warmup or on any missing input.

REMARKS#

Maintains an oldest-first columnar copy of high/low/close in your script (or pull them out of candles per call) — the helper expects three independent arrays.

EXAMPLE#

const high = [], low = [], close = [];
function onBar(i, ctx) {
  high[i] = candles[i].high;
  low[i]  = candles[i].low;
  close[i] = candles[i].close;
  const a = ta.atr(high, low, close, 14, i);
  if (a !== null) plot('atr', a, { color: '#fbbf24' });
}

SEE ALSO#

ta.stdev, ta.highest, ta.lowest