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, defaultrequired): Price data (pandas Series or numpy array)period(int, defaultrequired): 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 otherta.*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, defaultrequired): Price dataperiod(int, defaultrequired): 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, defaultrequired): Price dataperiod(int, defaultrequired): 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, defaultrequired): Price dataperiod(int, default14): 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, defaultrequired): Price datafast(int, default12): Fast EMA periodslow(int, default26): Slow EMA periodsignal(int, default9): 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, defaultrequired): High priceslow(array-like, defaultrequired): Low pricesclose(array-like, defaultrequired): Close pricesk_period(int, default14): %K lookback periodd_period(int, default3): %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, defaultrequired): Price dataperiod(int, default20): SMA periodstd(float, default2.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, defaultrequired): High priceslow(array-like, defaultrequired): Low pricesclose(array-like, defaultrequired): Close pricesperiod(int, default14): 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, defaultrequired): Input dataperiod(int, defaultrequired): 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, defaultrequired): Input dataperiod(int, defaultrequired): 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, defaultrequired): Input dataperiod(int, defaultrequired): 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, defaultrequired): Input datalength(int, default1): Lookback distance
Returns
numpy array
Example
momentum = ta.change(close, 10)
Notes
- Use this instead of
.diff()on numpy arrays fromta.*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, defaultrequired): Input datalength(int, default1): 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.