Technical Analysis

Vectorized ta.* namespace: moving averages, RSI, MACD, Bollinger, ATR, and friends.

ta.sma

ta.sma(source, period)

Simple Moving Average.

Calculates the arithmetic mean of source over a rolling window of period bars. Uses Numba JIT compilation for datasets > 10,000 values.

Parameters

  • source (array-like, default required): Price data (pandas Series or numpy array)
  • period (int, default required): Number of bars in the lookback window

Returns

numpy array

Example

from quant_charts import ta, close
sma = ta.sma(close, 20)
# Smooth an existing result (numpy -> numpy)
smoothed = ta.sma(sma, 5)

Notes

  • Returns a numpy array, NOT a pandas Series.
  • Use ta.sma() to smooth other ta.* results instead of .rolling().mean().

ta.ema

ta.ema(source, period)

Exponential Moving Average.

Gives more weight to recent values. Faster to react than SMA.

Parameters

  • source (array-like, default required): Price data
  • period (int, default required): Lookback period (span)

Returns

numpy array

Example

ema = ta.ema(close, 12)

ta.wma

ta.wma(source, period)

Weighted Moving Average.

Linearly weights recent values more heavily than older ones.

Parameters

  • source (array-like, default required): Price data
  • period (int, default required): Lookback period

Returns

numpy array

Example

wma = ta.wma(close, 20)

ta.rsi

ta.rsi(source, period)

Relative Strength Index (0-100).

Momentum oscillator that measures the speed and magnitude of price changes. Values above 70 indicate overbought, below 30 oversold.

Parameters

  • source (array-like, default required): Price data
  • period (int, default 14): Lookback period

Returns

numpy array

Example

rsi = ta.rsi(close, 14)
# Smooth RSI with SMA (correct numpy approach)
smooth_rsi = ta.sma(rsi, 5)

Notes

  • The result is a numpy array. Do NOT call .rolling() on it.

ta.macd

ta.macd(source, fast?, slow?, signal?)

Moving Average Convergence Divergence.

Returns a tuple of three numpy arrays: MACD line, signal line, and histogram. Use tuple unpacking.

Parameters

  • source (array-like, default required): Price data
  • fast (int, default 12): Fast EMA period
  • slow (int, default 26): Slow EMA period
  • signal (int, default 9): Signal line EMA period

Returns

tuple: (macd_line, signal_line, histogram), all numpy arrays

Example

macd_line, signal_line, histogram = ta.macd(close)
buy = cross_above(macd_line, signal_line)

ta.stochastic

ta.stochastic(high, low, close, k_period?, d_period?)

Stochastic Oscillator (%K and %D).

Parameters

  • high (array-like, default required): High prices
  • low (array-like, default required): Low prices
  • close (array-like, default required): Close prices
  • k_period (int, default 14): %K lookback period
  • d_period (int, default 3): %D smoothing period

Returns

tuple: (k, d), both numpy arrays

Example

k, d = ta.stochastic(high, low, close, 14, 3)
buy = cross_above(k, d) & below(k, 20)

ta.bollinger_bands

ta.bollinger_bands(source, period?, std?)

Bollinger Bands (upper, middle, lower).

Parameters

  • source (array-like, default required): Price data
  • period (int, default 20): SMA period
  • std (float, default 2.0): Standard deviation multiplier

Returns

tuple: (upper, middle, lower), all numpy arrays

Example

upper, mid, lower = ta.bollinger_bands(close, 20, 2.0)
plot(upper, "Upper BB")
plot(lower, "Lower BB")
fill("Upper BB", "Lower BB", color="#2962FF", opacity=10)

ta.atr

ta.atr(high, low, close, period?)

Average True Range, a volatility measure.

Parameters

  • high (array-like, default required): High prices
  • low (array-like, default required): Low prices
  • close (array-like, default required): Close prices
  • period (int, default 14): Lookback period

Returns

numpy array

Example

atr = ta.atr(high, low, close, 14)
avg_atr = ta.sma(atr, 50)
high_vol = atr > avg_atr

ta.stddev

ta.stddev(source, period)

Rolling standard deviation.

Parameters

  • source (array-like, default required): Input data
  • period (int, default required): Lookback window

Returns

numpy array

Example

vol = ta.stddev(close, 20)

ta.highest

ta.highest(source, period)

Rolling maximum over a lookback window.

Parameters

  • source (array-like, default required): Input data
  • period (int, default required): Lookback window

Returns

numpy array

Example

resistance = ta.highest(high, 20)

ta.lowest

ta.lowest(source, period)

Rolling minimum over a lookback window.

Parameters

  • source (array-like, default required): Input data
  • period (int, default required): Lookback window

Returns

numpy array

Example

support = ta.lowest(low, 20)

ta.change

ta.change(source, length?)

Difference between current and N bars ago.

Equivalent to pandas .diff(length) but works on numpy arrays.

Parameters

  • source (array-like, default required): Input data
  • length (int, default 1): Lookback distance

Returns

numpy array

Example

momentum = ta.change(close, 10)

Notes

  • Use this instead of .diff() on numpy arrays from ta.* results.

ta.roc

ta.roc(source, length?)

Rate of change in percent.

Calculates 100 * (current - previous) / previous. Equivalent to pandas .pct_change() * 100.

Parameters

  • source (array-like, default required): Input data
  • length (int, default 1): Lookback distance

Returns

numpy array (percentage values)

Example

pct_change = ta.roc(close, 5)

Notes

  • Returns percentage (e.g. 2.5 not 0.025). Divide by 100 for decimal.