Skip to content

mplchart.indicators

Technical analysis indicators — pandas pipeline only.

An indicator instance is a callable applied to a prices DataFrame: SMA(50)(prices). In charts, indicators are passed to chart.plot(...) directly (auto-plotted) or bound to a renderer primitive via @, as in SMA(50) @ LinePlot(). For the polars pipeline, use the equivalent factories in mplchart.expressions.


SMA

SMA(period: int = 20)

Simple Moving Average.

Computes the arithmetic mean of the close price over a rolling window. Plotted on the same scale as the price series.

Arguments:

  • period (int): Number of bars in the rolling window. Defaults to 20.

EMA

EMA(period: int = 20)

Exponential Moving Average.

Computes the EMA using a smoothing factor of 2 / (period + 1). Plotted on the same scale as the price series.

Arguments:

  • period (int): Span for the exponential smoothing. Defaults to 20.

WMA

WMA(period: int = 20)

Weighted Moving Average.

Computes a linearly weighted moving average giving more weight to recent bars. Plotted on the same scale as the price series.

Arguments:

  • period (int): Number of bars in the rolling window. Defaults to 20.

HMA

HMA(period: int = 20)

Hull Moving Average.

A weighted moving average that reduces lag by combining WMAs of different periods. Plotted on the same scale as the price series.

Arguments:

  • period (int): Number of bars in the rolling window. Defaults to 20.

RMA

RMA(period: int = 14)

Rolling Moving Average (Wilder's).

Exponential moving average using a smoothing factor of 1 / period (slower decay than EMA). Used internally by RSI and ATR. Plotted on the same scale as the price series.

Arguments:

  • period (int): Smoothing period in bars. Defaults to 14.

ROC

ROC(period: int = 1)

Rate of Change.

Measures the fractional change in price over a given number of bars (e.g. 0.05 for a 5% move). Positive values indicate upward momentum; negative values indicate downward momentum.

Arguments:

  • period (int): Lookback period in bars. Defaults to 1.

MOM

MOM(period: int = 1)

Momentum.

Raw price change over a given number of bars: close - close[period]. Positive values indicate upward momentum; negative values indicate downward momentum.

Arguments:

  • period (int): Lookback period in bars. Defaults to 1.

ATR

ATR(period: int = 14)

Average True Range.

Measures market volatility as the rolling mean of the true range (the greatest of: current high minus low, absolute high minus previous close, absolute low minus previous close).

Arguments:

  • period (int): Smoothing period in bars. Defaults to 14.

NATR

NATR(period: int = 14)

Normalized Average True Range (percent).

ATR expressed as a percentage of the closing price, making it comparable across instruments with different price levels.

Arguments:

  • period (int): Smoothing period in bars. Defaults to 14.

RSI

RSI(period: int = 14)

Relative Strength Index.

Momentum oscillator that measures the speed and magnitude of recent price changes. Values range from 0 to 100. Traditionally, readings above 70 indicate overbought conditions and readings below 30 indicate oversold conditions. Displayed in a separate pane above the main chart by default.

Arguments:

  • period (int): Smoothing period in bars. Defaults to 14.

BOP

BOP(period: int = 14)

Balance of Power.

Measures the strength of buyers versus sellers by comparing the close-to-open move against the high-low range, smoothed over the given period.

Arguments:

  • period (int): Smoothing period in bars. Defaults to 14.

CMF

CMF(period: int = 20)

Chaikin Money Flow.

Oscillator that combines price and volume to measure the buying and selling pressure over a rolling window. Positive values indicate accumulation; negative values indicate distribution.

Arguments:

  • period (int): Lookback period in bars. Defaults to 20.

MFI

MFI(period: int = 14)

Money Flow Index.

Volume-weighted RSI that measures buying and selling pressure. Values range from 0 to 100. Readings above 80 may indicate overbought conditions; readings below 20 may indicate oversold conditions.

Arguments:

  • period (int): Lookback period in bars. Defaults to 14.

ADX

ADX(period: int = 14)

Average Directional Index.

Measures trend strength regardless of direction. Values range from 0 to 100. Readings above 20–25 are typically considered trending; above 40 indicate a strong trend.

Arguments:

  • period (int): Smoothing period in bars. Defaults to 14.

DMI

DMI(period: int = 14)

Directional Movement Index.

Plots the positive (+DI) and negative (-DI) directional indicators together with the ADX. Crossovers of +DI and -DI signal potential trend changes.

Arguments:

  • period (int): Smoothing period in bars. Defaults to 14.

PPO

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

Price Percentage Oscillator.

Measures the percentage difference between two EMAs of price. Returns a DataFrame with columns ppo (the oscillator line), pposignal (EMA of PPO), and ppohist (PPO minus signal).

Arguments:

  • n1 (int): Period of the faster EMA. Defaults to 12.
  • n2 (int): Period of the slower EMA. Defaults to 26.
  • n3 (int): Period of the signal line EMA. Defaults to 9.

MACD

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

Moving Average Convergence Divergence.

Trend-following momentum indicator showing the relationship between two EMAs of price. Returns a DataFrame with columns macd (the difference between the fast and slow EMAs), macdsignal (EMA of MACD), and macdhist (MACD minus signal).

Arguments:

  • n1 (int): Period of the faster EMA. Defaults to 12.
  • n2 (int): Period of the slower EMA. Defaults to 26.
  • n3 (int): Period of the signal line EMA. Defaults to 9.

MACDV

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

Moving Average Convergence Divergence — Volatility Normalized.

MACD variant where the histogram is normalized by the ATR, making it comparable across instruments with different volatility levels. Returns a DataFrame with columns macd, macdsignal, and macdhist.

Arguments:

  • n1 (int): Period of the faster EMA. Defaults to 12.
  • n2 (int): Period of the slower EMA. Defaults to 26.
  • n3 (int): Period of the signal line EMA. Defaults to 9.

STOCH

STOCH(period: int = 14, fastn: int = 3, slown: int = 3)

Stochastic Oscillator.

Momentum indicator comparing the closing price to its price range over a lookback period. Returns a DataFrame with columns slowk (the smoothed %K line) and slowd (the %D signal line, a smoothed version of %K). Values range from 0 to 100.

Arguments:

  • period (int): Lookback period for the %K calculation. Defaults to 14.
  • fastn (int): Smoothing period for the fast %K line. Defaults to 3.
  • slown (int): Smoothing period for the slow %D signal line. Defaults to 3.

BBANDS

BBANDS(period: int = 20, nbdev: float = 2.0)

Bollinger Bands.

Volatility bands placed above and below a simple moving average. Returns a DataFrame with columns upperband, middleband (the SMA), and lowerband. Plotted on the same scale as the price series.

Arguments:

  • period (int): Period for the middle SMA and standard deviation calculation. Defaults to 20.
  • nbdev (float): Number of standard deviations for the upper and lower bands. Defaults to 2.0.

BBP

BBP(period: int = 20, nbdev: float = 2.0)

Bollinger Bands Percent (%B).

Measures where price sits within the Bollinger Bands, on a 0-100 scale. A value of 100 means price is at the upper band; 0 means price is at the lower band; 50 means price is at the middle band.

Arguments:

  • period (int): Period for the SMA and standard deviation. Defaults to 20.
  • nbdev (float): Number of standard deviations for the bands. Defaults to 2.0.

BBW

BBW(period: int = 20, nbdev: float = 2.0)

Bollinger Bands Width.

Measures the width of the Bollinger Bands as a percentage of the middle band. Expanding width indicates increasing volatility; contracting width indicates a squeeze (low volatility period).

Arguments:

  • period (int): Period for the SMA and standard deviation. Defaults to 20.
  • nbdev (float): Number of standard deviations for the bands. Defaults to 2.0.

KELTNER

KELTNER(period: int = 20, nbatr: float = 2.0)

Keltner Channel.

Volatility-based envelope using an EMA as the middle band and ATR multiples as the upper and lower bands. Returns a DataFrame with columns upperband, middleband, and lowerband. Plotted on the same scale as the price series.

Arguments:

  • period (int): Period for the EMA middle band and ATR calculation. Defaults to 20.
  • nbatr (float): ATR multiplier for the upper and lower bands. Defaults to 2.0.

DONCHIAN

DONCHIAN(period: int = 20)

Donchian Channel.

Price envelope based on the highest high and lowest low over a rolling window. Returns a DataFrame with columns upperband, middleband, and lowerband. Plotted on the same scale as the price series.

Arguments:

  • period (int): Lookback period in bars. Defaults to 20.

DEMA

DEMA(period: int = 20)

Double Exponential Moving Average.

Reduces lag compared to a standard EMA by combining a single EMA and a double-smoothed EMA. Plotted on the same scale as the price series.

Arguments:

  • period (int): Span for the exponential smoothing. Defaults to 20.

TEMA

TEMA(period: int = 20)

Triple Exponential Moving Average.

Further reduces lag compared to DEMA by combining single, double, and triple-smoothed EMAs. Plotted on the same scale as the price series.

Arguments:

  • period (int): Span for the exponential smoothing. Defaults to 20.

TRANGE

TRANGE()

True Range.

The greatest of: current high minus low, absolute high minus previous close, absolute low minus previous close. Building block for ATR.

MEDPRICE

MEDPRICE()

Median Price.

The arithmetic mean of the high and low: (high + low) / 2.

AVGPRICE

AVGPRICE()

Average Price.

The arithmetic mean of open, high, low and close: (O + H + L + C) / 4.

TYPPRICE

TYPPRICE()

Typical Price.

The average of high, low, and close: (high + low + close) / 3.

WCLPRICE

WCLPRICE()

Weighted Close Price.

Close-weighted average: (high + low + close * 2) / 4.