Overlap Studies

Overlap Studies — Moving averages and bands that overlay directly on the price chart.

Functions

SMA — Simple Moving Average EMA — Exponential Moving Average WMA — Weighted Moving Average DEMA — Double Exponential Moving Average TEMA — Triple Exponential Moving Average TRIMA — Triangular Moving Average KAMA — Kaufman Adaptive Moving Average T3 — Triple Exponential Moving Average (Tillson T3) BBANDS — Bollinger Bands MACD — Moving Average Convergence/Divergence MACDFIX — MACD with fixed 12/26 periods MACDEXT — MACD with controllable MA types SAR — Parabolic SAR SAREXT — Parabolic SAR Extended MA — Generic Moving Average (dispatches on matype) MAVP — Moving Average with Variable Period MAMA — MESA Adaptive Moving Average MIDPOINT — MidPoint over period MIDPRICE — MidPrice over period (High/Low) ALMA — Arnaud Legoux Moving Average ZLEMA — Zero-Lag EMA FRAMA — Fractal Adaptive Moving Average MCGINLEY — McGinley Dynamic VIDYA — Variable Index Dynamic Average ALLIGATOR — Bill Williams Alligator (jaw / teeth / lips) MA_ENVELOPES — Moving-average envelopes CHANDE_KROLL_STOP — Chande Kroll Stop

ferro_ta.overlap.ALLIGATOR(high, low, jaw_period=13, jaw_shift=8, teeth_period=8, teeth_shift=5, lips_period=5, lips_shift=3)[source]

Bill Williams Alligator (jaw, teeth, lips).

Each line is an SMMA of the median price (high + low) / 2, shifted forward by the given offset.

Parameters:
  • high (array-like) – High and low price series.

  • low (array-like) – High and low price series.

  • jaw_period (int, optional) – SMMA periods (defaults 13, 8, 5).

  • teeth_period (int, optional) – SMMA periods (defaults 13, 8, 5).

  • lips_period (int, optional) – SMMA periods (defaults 13, 8, 5).

  • jaw_shift (int, optional) – Forward displacements (defaults 8, 5, 3).

  • teeth_shift (int, optional) – Forward displacements (defaults 8, 5, 3).

  • lips_shift (int, optional) – Forward displacements (defaults 8, 5, 3).

Returns:

jaw, teeth, lips

Return type:

numpy.ndarray

ferro_ta.overlap.ALMA(close, timeperiod=21, offset=0.85, sigma=6.0)[source]

Arnaud Legoux Moving Average.

Gaussian-weighted moving average. The peak sits at floor(offset * (timeperiod - 1)) from the oldest bar in the window; the width is timeperiod / sigma. Leading timeperiod - 1 values are NaN.

Parameters:
  • close (array-like) – Sequence of closing prices.

  • timeperiod (int, optional) – Window length (default 21).

  • offset (float, optional) – Gaussian peak location in [0, 1] (default 0.85).

  • sigma (float, optional) – Gaussian width control (default 6.0). Must be > 0.

Returns:

ALMA values.

Return type:

numpy.ndarray

ferro_ta.overlap.BBANDS(close, timeperiod=5, nbdevup=2.0, nbdevdn=2.0, matype=0, *, nan_policy='propagate')[source]

Bollinger Bands.

The middle band is a moving average of type matype; the outer bands are offset from it by nbdevup / nbdevdn population standard deviations of the same window.

Parameters:
  • close (array-like) – Sequence of closing prices.

  • timeperiod (int, optional) – Moving average window (default 5).

  • nbdevup (float, optional) – Number of standard deviations above the middle band (default 2.0).

  • nbdevdn (float, optional) – Number of standard deviations below the middle band (default 2.0).

  • matype (int, optional) –

    Middle-band moving average type, as in MA() (default 0 = SMA, which is both TA-Lib’s default and this function’s historical behaviour):

    • 0 = SMA (Simple)

    • 1 = EMA (Exponential)

    • 2 = WMA (Weighted)

    • 3 = DEMA (Double EMA)

    • 4 = TEMA (Triple EMA)

    • 5 = TRIMA (Triangular)

    • 6 = KAMA (Kaufman Adaptive)

    • 7 = T3 (Tillson)

    • 8 = T3 (Tillson; exact alias of 7)

    Values 0-6 and 8 match TA-Lib’s numbering, but 7 is T3 here where TA-Lib’s 7 is MAMA. MAMA is not reachable through any matype value – call ferro_ta.MAMA() directly. A value outside 0-8 raises ValueError.

  • nan_policy ({"propagate", "skip"}, optional) – "propagate" (default, TA-Lib semantics): a NaN input poisons every later value. "skip": rows with a non-finite input are dropped, the indicator runs on the remaining rows, and NaN is written back at the dropped rows (matches the streaming classes tick for tick).

Returns:

(upperband, middleband, lowerband) — three arrays of equal length.

Return type:

tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray]

Notes

The deviation is always measured about the SMA, whatever matype is. TA-Lib centres the bands on the selected MA but computes the half-width from a standard deviation that is never told about matype (ta_BBANDS.c passes optInMAType to TA_MA for the middle band, but its TA_STDDEV call does not receive it), and ferro-ta matches that. So for matype != 0 the centre and the deviation reference are different series: the half-width is nbdev × the window’s sigma about the window mean, while the centre is elsewhere.

The bands are therefore not a nbdev-sigma envelope of the series they are centred on, and the usual statistical reading of the nbdev multiplier does not carry over. How often price closes outside the bands changes substantially with matype – on a random walk, a lagging centre such as matype=8 (T3) can put several times as many bars outside the bands as matype=0 does at the same nbdev, and a well-centred one such as matype=4 (TEMA) far fewer. Whenever the selected MA sits further from the window SMA than nbdev × that sigma, the whole envelope stops bracketing the SMA at all. Band ordering is unaffected (upperband >= middleband >= lowerband still holds for non-negative nbdev, since both outer bands are offsets from the same centre); it is the bands’ meaning relative to the price distribution that shifts.

Warm-up depends on matype, and is the selected MA’s lookback (writing p for timeperiod), identical in all three output arrays so index alignment is preserved:

matype

leading NaN count

0, 1, 2, 5 (SMA/EMA/WMA/TRIMA)

p - 1

3 (DEMA)

2 * (p - 1)

4 (TEMA)

3 * (p - 1)

6 (KAMA)

p

7, 8 (T3)

6 * (p - 1)

All three arrays are entirely NaN if that warm-up runs past the end of close.

ferro_ta.overlap.CHANDE_KROLL_STOP(high, low, close, timeperiod=10, multiplier=1.0, stop_period=9)[source]

Chande Kroll Stop.

First stops are HH(high, p) - x * ATR(p) and LL(low, p) + x * ATR(p). The published stops are the stop_period-bar highest first-long and lowest first-short.

Parameters:
  • high (array-like) – OHLC series of equal length.

  • low (array-like) – OHLC series of equal length.

  • close (array-like) – OHLC series of equal length.

  • timeperiod (int, optional) – p — HH/LL and ATR lookback (default 10).

  • multiplier (float, optional) – x — ATR multiplier (default 1.0).

  • stop_period (int, optional) – q — stop confirmation window (default 9).

Returns:

long_stop, short_stop

Return type:

numpy.ndarray

ferro_ta.overlap.DEMA(close, timeperiod=30, *, nan_policy='propagate')[source]

Double Exponential Moving Average.

Parameters:
  • close (array-like) – Sequence of closing prices.

  • timeperiod (int, optional) – Number of periods (default 30).

  • nan_policy ({"propagate", "skip"}, optional) – "propagate" (default, TA-Lib semantics): a NaN input poisons every later value. "skip": rows with a non-finite input are dropped, the indicator runs on the remaining rows, and NaN is written back at the dropped rows (matches the streaming classes tick for tick).

Returns:

Array of DEMA values; leading 2 * (timeperiod - 1) entries are NaN.

Return type:

numpy.ndarray

ferro_ta.overlap.EMA(close, timeperiod=30, *, nan_policy='propagate')[source]

Exponential Moving Average.

Parameters:
  • close (array-like) – Sequence of closing prices.

  • timeperiod (int, optional) – Number of periods (default 30).

  • nan_policy ({"propagate", "skip"}, optional) – "propagate" (default, TA-Lib semantics): a NaN input poisons every later value. "skip": rows with a non-finite input are dropped, the indicator runs on the remaining rows, and NaN is written back at the dropped rows (matches the streaming classes tick for tick).

Returns:

Array of EMA values; leading timeperiod - 1 entries are NaN.

Return type:

numpy.ndarray

ferro_ta.overlap.FRAMA(close, timeperiod=16)[source]

Fractal Adaptive Moving Average.

Adaptive EMA whose smoothing follows the fractal dimension of close over timeperiod (two half-windows versus the full window). alpha = exp(-4.6 * (dim - 1)) clipped to [0.01, 1]. Prefer an even timeperiod.

Parameters:
  • close (array-like) – Sequence of closing prices.

  • timeperiod (int, optional) – Fractal lookback (default 16). Must be >= 2.

Returns:

FRAMA values; leading timeperiod - 1 entries are NaN.

Return type:

numpy.ndarray

ferro_ta.overlap.KAMA(close, timeperiod=30, *, nan_policy='propagate')[source]

Kaufman Adaptive Moving Average.

Parameters:
  • close (array-like) – Sequence of closing prices.

  • timeperiod (int, optional) – Efficiency Ratio lookback period (default 30).

  • nan_policy ({"propagate", "skip"}, optional) – "propagate" (default, TA-Lib semantics): a NaN input poisons every later value. "skip": rows with a non-finite input are dropped, the indicator runs on the remaining rows, and NaN is written back at the dropped rows (matches the streaming classes tick for tick).

Returns:

Array of KAMA values; leading timeperiod - 1 entries are NaN.

Return type:

numpy.ndarray

ferro_ta.overlap.MA(close, timeperiod=30, matype=0)[source]

Generic Moving Average.

Dispatches to the appropriate MA implementation based on matype.

Parameters:
  • close (array-like) – Sequence of closing prices.

  • timeperiod (int, optional) – Number of periods (default 30).

  • matype (int, optional) –

    Moving average type (default 0):

    • 0 = SMA (Simple)

    • 1 = EMA (Exponential)

    • 2 = WMA (Weighted)

    • 3 = DEMA (Double EMA)

    • 4 = TEMA (Triple EMA)

    • 5 = TRIMA (Triangular)

    • 6 = KAMA (Kaufman Adaptive)

    • 7 = T3 (Tillson)

    • 8 = T3 (Tillson; exact alias of 7)

    Values 0-6 and 8 match TA-Lib’s numbering, but 7 is T3 here where TA-Lib’s 7 is MAMA. MAMA is not reachable through any matype value – call ferro_ta.MAMA() directly.

Returns:

Array of MA values.

Return type:

numpy.ndarray

ferro_ta.overlap.MACD(close, fastperiod=12, slowperiod=26, signalperiod=9, *, nan_policy='propagate')[source]

Moving Average Convergence/Divergence.

Parameters:
  • close (array-like) – Sequence of closing prices.

  • fastperiod (int, optional) – Fast EMA period (default 12).

  • slowperiod (int, optional) – Slow EMA period (default 26).

  • signalperiod (int, optional) – Signal EMA period (default 9).

  • nan_policy ({"propagate", "skip"}, optional) – "propagate" (default, TA-Lib semantics): a NaN input poisons every later value. "skip": rows with a non-finite input are dropped, the indicator runs on the remaining rows, and NaN is written back at the dropped rows (matches the streaming classes tick for tick).

Returns:

(macd, signal, histogram) — three arrays of equal length. Leading values that cannot be computed are NaN.

Return type:

tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray]

ferro_ta.overlap.MACDEXT(close, fastperiod=12, fastmatype=1, slowperiod=26, slowmatype=1, signalperiod=9, signalmatype=1)[source]

MACD with Controllable MA Types.

Like MACD() but allows specifying the moving average type for each of the fast, slow, and signal lines independently.

Parameters:
  • close (array-like) – Sequence of closing prices.

  • fastperiod (int, optional) – Fast MA period (default 12).

  • fastmatype (int, optional) – MA type for the fast line (default 1 = EMA).

  • slowperiod (int, optional) – Slow MA period (default 26).

  • slowmatype (int, optional) – MA type for the slow line (default 1 = EMA).

  • signalperiod (int, optional) – Signal MA period (default 9).

  • signalmatype (int, optional) – MA type for the signal line (default 1 = EMA).

  • codes (MA type)

Returns:

(macd, signal, histogram) — three arrays of equal length.

Return type:

tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray]

ferro_ta.overlap.MACDFIX(close, signalperiod=9)[source]

Moving Average Convergence/Divergence Fix 12/26.

Parameters:
  • close (array-like) – Sequence of closing prices.

  • signalperiod (int, optional) – Signal EMA period (default 9).

Returns:

(macd, signal, histogram) — three arrays of equal length.

Return type:

tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray]

ferro_ta.overlap.MAMA(close, fastlimit=0.5, slowlimit=0.05)[source]

MESA Adaptive Moving Average.

Returns the MAMA and FAMA (Following Adaptive MA) lines. The adaptive alpha is derived from the rate of phase change of the Hilbert Transform.

Parameters:
  • close (array-like) – Sequence of closing prices.

  • fastlimit (float, optional) – Upper bound on the adaptive smoothing factor (default 0.5).

  • slowlimit (float, optional) – Lower bound on the adaptive smoothing factor (default 0.05).

Returns:

(mama, fama) — two arrays; first 32 entries are NaN.

Return type:

tuple[numpy.ndarray, numpy.ndarray]

ferro_ta.overlap.MAVP(close, periods, minperiod=2, maxperiod=30, matype=0)[source]

Moving Average with Variable Period.

Computes a moving average at each bar using the period given by the corresponding element of periods. Periods are clamped to [minperiod, maxperiod].

Parameters:
  • close (array-like) – Sequence of closing prices.

  • periods (array-like) – Sequence of period values (one per bar, same length as close).

  • minperiod (int, optional) – Minimum allowed period (default 2).

  • maxperiod (int, optional) – Maximum allowed period (default 30).

  • matype (int, optional) –

    Moving average type, as in MA() (default 0 = SMA):

    • 0 = SMA (Simple)

    • 1 = EMA (Exponential)

    • 2 = WMA (Weighted)

    • 3 = DEMA (Double EMA)

    • 4 = TEMA (Triple EMA)

    • 5 = TRIMA (Triangular)

    • 6 = KAMA (Kaufman Adaptive)

    • 7 = T3 (Tillson)

    • 8 = T3 (Tillson; exact alias of 7)

    Values 0-6 and 8 match TA-Lib’s numbering, but 7 is T3 here where TA-Lib’s 7 is MAMA. MAMA is not reachable through any matype value – call ferro_ta.MAMA() directly.

Returns:

Array of variable-period MA values. Leading entries are NaN for the maxperiod MA’s lookback, which depends on matype.

Return type:

numpy.ndarray

ferro_ta.overlap.MA_ENVELOPES(close, timeperiod=20, percent=2.5, matype=0)[source]

Moving-average envelopes.

upper = MA * (1 + percent / 100), lower = MA * (1 - percent / 100).

Parameters:
  • close (array-like) – Sequence of closing prices.

  • timeperiod (int, optional) – Moving-average window (default 20).

  • percent (float, optional) – Envelope width in percent (default 2.5).

  • matype (int, optional) – Moving-average type, same as MA() (default 0 = SMA).

Returns:

upper, middle, lower

Return type:

numpy.ndarray

ferro_ta.overlap.MCGINLEY(close, timeperiod=14)[source]

McGinley Dynamic.

MD = MD[1] + (close - MD[1]) / (timeperiod * (close / MD[1]) ** 4), seeded with the SMA of the first timeperiod bars.

Parameters:
  • close (array-like) – Sequence of closing prices.

  • timeperiod (int, optional) – Smoothing period (default 14).

Returns:

McGinley Dynamic values.

Return type:

numpy.ndarray

ferro_ta.overlap.MIDPOINT(close, timeperiod=14)[source]

MidPoint over period — (max + min) / 2 of close.

Parameters:
  • close (array-like) – Sequence of closing prices.

  • timeperiod (int, optional) – Number of periods (default 14).

Returns:

Array of MIDPOINT values; leading timeperiod - 1 entries are NaN.

Return type:

numpy.ndarray

ferro_ta.overlap.MIDPRICE(high, low, timeperiod=14)[source]

MidPrice over period — (highest high + lowest low) / 2.

Parameters:
  • high (array-like) – Sequence of high prices.

  • low (array-like) – Sequence of low prices.

  • timeperiod (int, optional) – Number of periods (default 14).

Returns:

Array of MIDPRICE values; leading timeperiod - 1 entries are NaN.

Return type:

numpy.ndarray

ferro_ta.overlap.SAR(high, low, acceleration=0.02, maximum=0.2)[source]

Parabolic SAR.

Parameters:
  • high (array-like) – Sequence of high prices.

  • low (array-like) – Sequence of low prices.

  • acceleration (float, optional) – Acceleration factor step (default 0.02).

  • maximum (float, optional) – Maximum acceleration factor (default 0.2).

Returns:

Array of SAR values; first entry is NaN.

Return type:

numpy.ndarray

ferro_ta.overlap.SAREXT(high, low, startvalue=0.0, offsetonreverse=0.0, accelerationinitlong=0.02, accelerationlong=0.02, accelerationmaxlong=0.2, accelerationinitshort=0.02, accelerationshort=0.02, accelerationmaxshort=0.2)[source]

Parabolic SAR Extended.

An extended version of the Parabolic SAR that allows independent acceleration parameters for long and short positions, plus an optional fixed start value and a gap-on-reverse offset.

Parameters:
  • high (array-like) – Sequence of high prices.

  • low (array-like) – Sequence of low prices.

  • startvalue (float, optional) – Fixed initial SAR value (0 = auto-detect, default 0.0).

  • offsetonreverse (float, optional) – Multiplier applied to the SAR on trend reversal (default 0.0).

  • accelerationinitlong (float, optional) – Initial acceleration factor for long positions (default 0.02).

  • accelerationlong (float, optional) – Acceleration step for long positions (default 0.02).

  • accelerationmaxlong (float, optional) – Maximum acceleration for long positions (default 0.2).

  • accelerationinitshort (float, optional) – Initial acceleration factor for short positions (default 0.02).

  • accelerationshort (float, optional) – Acceleration step for short positions (default 0.02).

  • accelerationmaxshort (float, optional) – Maximum acceleration for short positions (default 0.2).

Returns:

Array of SAREXT values; first entry is NaN.

Return type:

numpy.ndarray

ferro_ta.overlap.SMA(close, timeperiod=30, *, nan_policy='propagate')[source]

Simple Moving Average.

Parameters:
  • close (array-like) – Sequence of closing prices.

  • timeperiod (int, optional) – Number of periods (default 30).

  • nan_policy ({"propagate", "skip"}, optional) – "propagate" (default, TA-Lib semantics): a NaN input poisons every later value. "skip": rows with a non-finite input are dropped, the indicator runs on the remaining rows, and NaN is written back at the dropped rows (matches the streaming classes tick for tick).

Returns:

Array of SMA values; leading timeperiod - 1 entries are NaN.

Return type:

numpy.ndarray

ferro_ta.overlap.T3(close, timeperiod=5, vfactor=0.7, *, nan_policy='propagate')[source]

Triple Exponential Moving Average (Tillson T3).

Parameters:
  • close (array-like) – Sequence of closing prices.

  • timeperiod (int, optional) – Number of periods (default 5).

  • vfactor (float, optional) – Volume factor (default 0.7).

  • nan_policy ({"propagate", "skip"}, optional) – "propagate" (default, TA-Lib semantics): a NaN input poisons every later value. "skip": rows with a non-finite input are dropped, the indicator runs on the remaining rows, and NaN is written back at the dropped rows (matches the streaming classes tick for tick).

Returns:

Array of T3 values.

Return type:

numpy.ndarray

ferro_ta.overlap.TEMA(close, timeperiod=30, *, nan_policy='propagate')[source]

Triple Exponential Moving Average.

Parameters:
  • close (array-like) – Sequence of closing prices.

  • timeperiod (int, optional) – Number of periods (default 30).

  • nan_policy ({"propagate", "skip"}, optional) – "propagate" (default, TA-Lib semantics): a NaN input poisons every later value. "skip": rows with a non-finite input are dropped, the indicator runs on the remaining rows, and NaN is written back at the dropped rows (matches the streaming classes tick for tick).

Returns:

Array of TEMA values; leading 3 * (timeperiod - 1) entries are NaN.

Return type:

numpy.ndarray

ferro_ta.overlap.TRIMA(close, timeperiod=30, *, nan_policy='propagate')[source]

Triangular Moving Average.

Parameters:
  • close (array-like) – Sequence of closing prices.

  • timeperiod (int, optional) – Number of periods (default 30).

  • nan_policy ({"propagate", "skip"}, optional) – "propagate" (default, TA-Lib semantics): a NaN input poisons every later value. "skip": rows with a non-finite input are dropped, the indicator runs on the remaining rows, and NaN is written back at the dropped rows (matches the streaming classes tick for tick).

Returns:

Array of TRIMA values; leading timeperiod - 1 entries are NaN.

Return type:

numpy.ndarray

ferro_ta.overlap.VIDYA(close, timeperiod=14, cmo_period=9)[source]

Variable Index Dynamic Average.

EMA whose smoothing constant is scaled by |CMO(cmo_period)| / 100.

Parameters:
  • close (array-like) – Sequence of closing prices.

  • timeperiod (int, optional) – Base EMA period (default 14).

  • cmo_period (int, optional) – Chande Momentum Oscillator lookback (default 9).

Returns:

VIDYA values.

Return type:

numpy.ndarray

ferro_ta.overlap.WMA(close, timeperiod=30, *, nan_policy='propagate')[source]

Weighted Moving Average.

Parameters:
  • close (array-like) – Sequence of closing prices.

  • timeperiod (int, optional) – Number of periods (default 30).

  • nan_policy ({"propagate", "skip"}, optional) – "propagate" (default, TA-Lib semantics): a NaN input poisons every later value. "skip": rows with a non-finite input are dropped, the indicator runs on the remaining rows, and NaN is written back at the dropped rows (matches the streaming classes tick for tick).

Returns:

Array of WMA values; leading timeperiod - 1 entries are NaN.

Return type:

numpy.ndarray

ferro_ta.overlap.ZLEMA(close, timeperiod=14)[source]

Zero-Lag Exponential Moving Average.

Applies an EMA to the error-corrected series close + (close - close[lag]) where lag = floor((timeperiod - 1) / 2).

Parameters:
  • close (array-like) – Sequence of closing prices.

  • timeperiod (int, optional) – EMA period (default 14).

Returns:

ZLEMA values.

Return type:

numpy.ndarray