Skip to content

mintalib.functions

Calculation functions for technical analysis indicators.

These functions are thin wrappers around core calculation routines that handle input and output type conversion.

The function names are all lower case like sma, ema, etc. Some names like abs, min, max, sum shadow Python builtins. It is advised to import the module with a short alias rather than importing names directly:

import mintalib.functions as ta

abs

abs(series)

Absolute Value

adx

adx(prices, period: int = 14)

Average Directional Index

Arguments: - period (int): time period, default 14

alma

alma(series, period: int = 9, offset: float = 0.85, sigma: float = 6.0)

Arnaud Legoux Moving Average

atr

atr(prices, period: int = 14)

Average True Range

Arguments: - period (int): time period, default 14

avgprice

avgprice(prices)

Average Price

Value of (open + high + low + close) / 4

bbands

bbands(series, period: int = 20, nbdev: float = 2.0)

Bollinger Bands

Arguments: - period (int): time period, default 20 - nbdev (float): bands width in number of standard deviations

bbp

bbp(series, period: int = 20, nbdev: float = 2.0)

Bollinger Bands Percent (%B)

Arguments: - period (int): time period, default 20 - nbdev (float): bands width in number of standard deviations

bbw

bbw(series, period: int = 20, nbdev: float = 2.0)

Bollinger Bands Width

Arguments: - period (int): time period, default 20 - nbdev (float): bands width in number of standard deviations

bop

bop(prices, period: int = 20)

Balance of Power

Arguments: - period (int): time period, default 20

cci

cci(prices, period: int = 20)

Commodity Channel Index

Arguments: - period (int): time period, default 20

clag

clag(series, period: int = 1)

Confirmation Lag

Changes value only after a confirmation period

Arguments: - period (int): time period, default 1

cmf

cmf(prices, period: int = 20)

Chaikin Money Flow

Arguments: - period (int): time period, default 20

crossover

crossover(series, level: float = 0.0)

Cross Over

Yields a value of 1 at the point where series crosses over level

Arguments: - level (float): level to cross, default 0.0

crossunder

crossunder(series, level: float = 0.0)

Cross Under

Yields a value of 1 at the point where series crosses under level

Arguments: - level (float): level to cross, default 0.0

dema

dema(series, period: int)

Double Exponential Moving Average

Arguments: - period (int): time period, required

diff

diff(series, period: int = 1)

Difference

Difference between current value and the one offset by period

Arguments: - period (int): time period, default 1

dmi

dmi(prices, period: int = 14)

Directional Movement Indicator

Arguments: - period (int): time period, default 14

donchian

donchian(prices, period: int = 20)

Donchian Channel

Arguments: - period (int): time period, default 20

ema

ema(series, period: int, *, adjust: bool = False)

Exponential Moving Average

Arguments: - period (int): time period, required - adjust (bool): whether to adjust weights, default False when true update ratio increases gradually (see formula)

Formula:

EMA is calculated as a recursive formula The standard formula is ema += alpha * (value - ema) with alpha = 2.0 / (period + 1.0) The adjusted formula is ema = num/div where num = value + rho * num, div = 1.0 + rho * div with rho = 1.0 - alpha

exp

exp(series)

Exponential

flag

flag(series)

Flag Value

Flag value of 1 for positive, 0 for zero or negative, and NaN otherwize

hma

hma(series, period: int)

Hull Moving Average

Arguments: - period (int): time period, required

kama

kama(series, period: int = 10, fastn: int = 2, slown: int = 30)

Kaufman Adaptive Moving Average

Arguments: - period (int): time period for efficiency ratio, default 10 - fastn (int): time period for fast moving average, default, 2 - slown (int): time period for slow moving average, default 30

keltner

keltner(prices, period: int = 20, nbatr: float = 2.0)

Keltner Channel

Arguments: - period (int): time period, default 20 - nbatr (float): channel width in number of atrs, default 2.0

ker

ker(series, period: int = 10)

Kaufman Efficiency Ratio

Arguments: - period (int): time period, default 10

lag

lag(series, period: int)

Lag Function

Arguments: - period (int): time period, required

linreg

linreg(series, period: int = 20, offset: int = 0)

Linear Regression (least squares moving average)

Value of the regression line at the current bar, with offset projecting the line forward.

Arguments: - period (int): time period, default 20 - offset (int): forecast offset, default 0

linreg_rmse

linreg_rmse(series, period: int = 20)

Linear Regression Root Mean Square Error

Arguments: - period (int): time period, default 20

linreg_rvalue

linreg_rvalue(series, period: int = 20)

Linear Regression R-Value

Arguments: - period (int): time period, default 20

linreg_slope

linreg_slope(series, period: int = 20)

Linear Regression Slope

Arguments: - period (int): time period, default 20

log

log(series)

Logarithm

lroc

lroc(series, period: int = 1)

Logarithmic Rate of Change

Equivalent to the difference of log values

Arguments: - period (int): time period, default 1 when negative the calculation is shifted back

macd

macd(series, n1: int = 12, n2: int = 26, n3: int = 9)

Moving Average Convergence Divergence

Arguments: - n1 (int): short time period, default 12 - n2 (int): long time period, default 26 - n3 (int): signal time period, default 9

Outputs:

macd, macdsignal, macdhist

macdv

macdv(prices, n1: int = 12, n2: int = 26, n3: int = 9)

Moving Average Convergence Divergence - Volatility Normalized

Arguments: - n1 (int): short time period, default 12 - n2 (int): long time period, default 26 - n3 (int): signal time period, default 9

Outputs:

macdv, macdvsignal, macdvhist

mad

mad(series, period: int = 14)

Rolling Mean Absolute Deviation

mav

mav(series, period: int = 20, *, ma_type: str = 'SMA')

Generic Moving Average

Moving average computed according to ma_type

Arguments: - ma_type (str): one of 'SMA', 'EMA', 'WMA', 'HMA', 'DEMA', 'TEMA' defaults to 'SMA'

max

max(series, period: int)

Rolling Maximum

mdi

mdi(prices, period: int = 14)

Minus Directional Index

Arguments: - period (int): time period, default 14

medprice

medprice(prices)

Median Price

Value of (high + low) / 2

mfi

mfi(prices, period: int = 14)

Money Flow Index

Arguments: - period (int): time period, default 14

min

min(series, period: int)

Rolling Minimum

Arguments: - period (int): time period, required

natr

natr(prices, period: int = 14)

Normalized Average True Range

Arguments: - period (int): time period, default 14

pdi

pdi(prices, period: int = 14)

Plus Directional Index

Arguments: - period (int): time period, default 14

ppo

ppo(series, n1: int = 12, n2: int = 26, n3: int = 9)

Price Percentage Oscillator

Arguments: - n1 (int): short time period, default 12 - n2 (int): long time period, default 26 - n3 (int): signal time period, default 9

Outputs:

ppo, pposignal, ppohist

price

price(prices, item: str | None = None)

Generic Price

Arguments: - item (str): price type, one of: 'open', 'high', 'low', 'close' (default), 'avg' or 'ohlc4' — average price (open + high + low + close) / 4, 'med' or 'hl2' — median price (high + low) / 2, 'typ' or 'hlc3' — typical price (high + low + close) / 3, 'wcl' or 'hlcc4' — weighted close (high + low + 2 * close) / 4

quadreg

quadreg(series, period: int = 20, offset: int = 0)

Quadratic Regression (parabolic moving average)

Value of the regression parabola at the current bar, with offset projecting the parabola forward.

Arguments: - period (int): time period, default 20 - offset (int): forecast offset, default 0

quadreg_curve

quadreg_curve(series, period: int = 20)

Quadratic Regression Curve

Arguments: - period (int): time period, default 20

quadreg_rmse

quadreg_rmse(series, period: int = 20)

Quadratic Regression Root Mean Square Error

Arguments: - period (int): time period, default 20

quadreg_rvalue

quadreg_rvalue(series, period: int = 20)

Quadratic Regression R-Value

Partial correlation of the quadratic term, given the linear term.

Arguments: - period (int): time period, default 20

quadreg_slope

quadreg_slope(series, period: int = 20, offset: int = 0)

Quadratic Regression Slope

Slope of the regression parabola at the current bar, with offset projecting the slope forward.

Arguments: - period (int): time period, default 20 - offset (int): forecast offset, default 0

rma

rma(series, period: int)

Rolling Moving Average (RSI style)

Exponential moving average with alpha = 2 / period, that starts as a simple moving average until number of bars is equal to period.

roc

roc(series, period: int = 1)

Rate of Change

Arguments: - period (int): time period, default 1 when negative the calculation is shifted back

rsi

rsi(series, period: int = 14)

Relative Strength Index

Arguments: - period (int): time period, default 14

sar

sar(prices, afs: float = 0.02, maxaf: float = 0.2)

Parabolic Stop and Reverse

Arguments: - afs (float): starting acceleration factor, default 0.02 - maxaf (float): maximum acceleration factor, default 0.2

sign

sign(series)

Sign

sma

sma(series, period: int)

Simple Moving Average

Arguments: - period (int): time period, required

stdev

stdev(series, period: int = 20)

Standard Deviation

Arguments: - period (int): time period, default 20

step

step(series, threshold: float = 1.0)

Step Function

Limit value changes to threshold (in absolute value)

Arguments: - threshold (float): threshold value, default 1.0

stoch

stoch(prices, period: int = 14, fastn: int = 3, slown: int = 3)

Stochastic Oscillator

Arguments: - period (int): time period of window, default, 14 - fastn (int): time period of fast average, default 3 - slown (int): time period of slow average, default 3

streak

streak(series)

Consecutive streak of values above zero

sum

sum(series, period: int)

Rolling sum

Arguments: - period (int): time period, required

tema

tema(series, period: int = 20)

Triple Exponential Moving Average

Arguments: - period (int): time period, default 20

trange

trange(prices, *, log_prices: bool = False, percent: bool = False)

True Range

Arguments: - log_prices (bool): whether to apply log to prices before calculation - percent (bool): result as percentage of price

typprice

typprice(prices)

Typical Price

Value of (high + low + close ) / 3

updown

updown(series, up_level: float = 0.0, down_level: float = 0.0)

Flag for value crossing up & down levels

Arguments: - up_level (float): flag set at 1 above that level - down_level (float): flag set at 0 below that level

wclprice

wclprice(prices)

Weighted Close Price

Value of (high + low + 2 * close) / 4

wma

wma(series, period: int)

Weighted Moving Average

Arguments: - period (int): time period, required

zlema

zlema(series, period: int)

Zero-Lag Exponential Moving Average

Arguments: - period (int): time period, required

Formula:

ZLEMA is an EMA applied to a de-lagged series data = 2 * value - value[lag] with lag = (period - 1) // 2