Moving Average Envelopes

get_ma_envelopes(quotes, lookback_periods, percent_offset=2.5, ma_type=MAType.SMA)


name type notes
quotes Iterable[Quote] Iterable of the Quote class or its sub-class.
See here for usage with pandas.DataFrame
lookback_periods int Number of periods (N) in the moving average. Must be greater than 1.
percent_offset float, default 2.5 Percent offset for envelope width. Example: 3.5% would be entered as 3.5 (not 0.035). Must be greater than 0. Typical values range from 2 to 10.
ma_type MAType, default MAType.SMA Type of moving average (e.g. SMA, EMA, HMA). See MAType options below.

Historical quotes requirements

See links in the supported MAType options section below for details on the inherited requirements for quotes and lookback_periods.

quotes is an Iterable[Quote] collection of historical price quotes. It should have a consistent frequency (day, hour, minute, etc). See the Guide for more information.

MAType options

from stock_indicators.indicators.common.enums import MAType
type description
MAType.ALMA Arnaud Legoux Moving Average
MAType.DEMA Double Exponential Moving Average
MAType.EPMA Endpoint Moving Average
MAType.EMA Exponential Moving Average
MAType.HMA Hull Moving Average
MAType.SMA Simple Moving Average (default)
MAType.SMMA Smoothed Moving Average
MAType.TEMA Triple Exponential Moving Average
MAType.WMA Weighted Moving Average

🚩 Warning: For ALMA, default values are used for offset and sigma.



Convergence warning: Some moving average variants have decreasing magnitude, convergence-related precision errors that can be as high as ~5% deviation in indicator values for earlier periods. See links in the supported MAType options section above for more information.


name type notes
date datetime Date
center_line float, Optional Moving average
upper_envelope float, Optional Upper envelope band
lower_envelope float, Optional Lower envelope band

The moving average center_line is based on the ma_type type specified.


See Utilities and Helpers for more information.


from stock_indicators import indicators
from stock_indicators import MAType     # Short path, version >= 0.8.1

# This method is NOT a part of the library.
quotes = get_historical_quotes("SPY")

# Calculate 20-period SMA envelopes with 2.5% offset
results = indicators.get_ma_envelopes(quotes, 20, 2.5, MAType.SMA);

About Moving Average Envelopes

Moving Average Envelopes is a price band overlay that is offset from the moving average of Close price over a lookback window. [Discuss] 💬