backtrader.indicators.envelope module

Envelope Indicator Module - Envelope bands around indicators.

This module provides envelope indicators that create upper and lower bands around an indicator at a specified percentage.

Classes:

EnvelopeMixIn: MixIn class for creating envelope bands. _EnvelopeBase: Base class for envelope indicators. Envelope: Envelope bands around data source.

Example

class MyStrategy(bt.Strategy):
def __init__(self):

self.sma_env = bt.indicators.SMAEnvelope(self.data.close, period=20, perc=2.5)

def next(self):
if self.data.close[0] < self.sma_env.bot[0]:

self.buy()

elif self.data.close[0] > self.sma_env.top[0]:

self.sell()

class backtrader.indicators.envelope.PlotLineAttr[source]

Bases: object

Plot line attribute container for envelope visualization.

__init__(**kwargs)[source]

Initialize plot line attributes.

Parameters:

**kwargs – Arbitrary plot line attributes.

get(key, default=None)[source]

Standard get method for compatibility.

Parameters:
  • key – Attribute name to retrieve.

  • default – Default value if key not found.

Returns:

Attribute value or default.

__contains__(key)[source]

Check if attribute exists.

Parameters:

key – Attribute name to check.

Returns:

True if attribute exists, False otherwise.

class backtrader.indicators.envelope.EnvelopeMixIn[source]

Bases: object

MixIn class to create a subclass with another indicator. The main line of that indicator will be surrounded by an upper and lower band separated a given “percentage” from the input main line

The usage is:

  • Class XXXEnvelope(XXX, EnvelopeMixIn)

Formula:
  • ‘line’ (inherited from XXX)

  • top = ‘line’ * (1 + perc)

  • bot = ‘line’ * (1 - perc)

lines = ('top', 'bot')
params = (('perc', 2.5),)
class PlotLinesObj[source]

Bases: object

Plot lines configuration object for envelope visualization.

__init__()[source]

Initialize plot lines with top and bot attributes.

get(key, default=None)[source]

Standard get method for compatibility.

Parameters:
  • key – Attribute name.

  • default – Default value if not found.

Returns:

Attribute value or default.

__contains__(key)[source]

Check if attribute exists.

Parameters:

key – Attribute name to check.

Returns:

True if attribute exists, False otherwise.

plotlines = <backtrader.indicators.envelope.EnvelopeMixIn.PlotLinesObj object>
class PlotInfoObj[source]

Bases: object

Plot information configuration object for envelope visualization.

__init__()[source]

Initialize plot info with default envelope settings.

get(key, default=None)[source]

Standard get method for compatibility.

Parameters:
  • key – Attribute name.

  • default – Default value if not found.

Returns:

Attribute value or default.

__contains__(key)[source]

Check if attribute exists.

Parameters:

key – Attribute name to check.

Returns:

True if attribute exists, False otherwise.

plotinfo = <backtrader.indicators.envelope.EnvelopeMixIn.PlotInfoObj object>
__init__()[source]

Initialize the envelope mix-in.

Calculates percentage value for band width.

next()[source]

Calculate envelope bands for the current bar.

top = base * (1 + perc) bot = base * (1 - perc)

once(start, end)[source]

Calculate envelope bands in runonce mode.

Computes top and bot bands as percentage of base value.

class backtrader.indicators.envelope.Envelope[source]

Bases: _EnvelopeBase, EnvelopeMixIn

It creates envelope bands separated from the source data by a given percentage

Formula:
  • src = datasource

  • top = src * (1 + perc)

  • bot = src * (1 - perc)

frompackages = ()
packages = ()
class backtrader.indicators.envelope.AdaptiveMovingAverageEnvelope

Bases: AdaptiveMovingAverage, EnvelopeMixIn

AdaptiveMovingAverage and envelope bands separated “perc” from it

Formula:
  • kama (from AdaptiveMovingAverage)

  • top = kama * (1 + perc)

  • bot = kama * (1 - perc)

alias = ['KAMAEnvelope', 'MovingAverageAdaptiveEnvelope']
frompackages = ()
packages = ()
class backtrader.indicators.envelope.DicksonMovingAverageEnvelope

Bases: DicksonMovingAverage, EnvelopeMixIn

DicksonMovingAverage and envelope bands separated “perc” from it

Formula:
  • dma (from DicksonMovingAverage)

  • top = dma * (1 + perc)

  • bot = dma * (1 - perc)

alias = ['DMAEnvelope', 'DicksonMAEnvelope']
frompackages = ()
packages = ()
class backtrader.indicators.envelope.DoubleExponentialMovingAverageEnvelope

Bases: DoubleExponentialMovingAverage, EnvelopeMixIn

DoubleExponentialMovingAverage and envelope bands separated “perc” from it

Formula:
  • dema (from DoubleExponentialMovingAverage)

  • top = dema * (1 + perc)

  • bot = dema * (1 - perc)

alias = ['DEMAEnvelope', 'MovingAverageDoubleExponentialEnvelope']
frompackages = ()
packages = ()
class backtrader.indicators.envelope.ExponentialMovingAverageEnvelope

Bases: ExponentialMovingAverage, EnvelopeMixIn

ExponentialMovingAverage and envelope bands separated “perc” from it

Formula:
  • ema (from ExponentialMovingAverage)

  • top = ema * (1 + perc)

  • bot = ema * (1 - perc)

alias = ['EMAEnvelope', 'MovingAverageExponentialEnvelope']
frompackages = ()
packages = ()
class backtrader.indicators.envelope.HullMovingAverageEnvelope

Bases: HullMovingAverage, EnvelopeMixIn

HullMovingAverage and envelope bands separated “perc” from it

Formula:
  • hma (from HullMovingAverage)

  • top = hma * (1 + perc)

  • bot = hma * (1 - perc)

alias = ['HMAEnvelope', 'HullMAEnvelope']
frompackages = ()
packages = ()
class backtrader.indicators.envelope.MovingAverageSimpleEnvelope

Bases: MovingAverageSimple, EnvelopeMixIn

MovingAverageSimple and envelope bands separated “perc” from it

Formula:
  • sma (from MovingAverageSimple)

  • top = sma * (1 + perc)

  • bot = sma * (1 - perc)

alias = ['SMAEnvelope', 'SimpleMovingAverageEnvelope']
frompackages = ()
packages = ()
class backtrader.indicators.envelope.SmoothedMovingAverageEnvelope

Bases: SmoothedMovingAverage, EnvelopeMixIn

SmoothedMovingAverage and envelope bands separated “perc” from it

Formula:
  • smma (from SmoothedMovingAverage)

  • top = smma * (1 + perc)

  • bot = smma * (1 - perc)

alias = ['SMMAEnvelope', 'WilderMAEnvelope', 'MovingAverageSmoothedEnvelope', 'MovingAverageWilderEnvelope', 'ModifiedMovingAverageEnvelope']
frompackages = ()
packages = ()
class backtrader.indicators.envelope.TripleExponentialMovingAverageEnvelope

Bases: TripleExponentialMovingAverage, EnvelopeMixIn

TripleExponentialMovingAverage and envelope bands separated “perc” from it

Formula:
  • tema (from TripleExponentialMovingAverage)

  • top = tema * (1 + perc)

  • bot = tema * (1 - perc)

alias = ['TEMAEnvelope', 'MovingAverageTripleExponentialEnvelope']
frompackages = ()
packages = ()
class backtrader.indicators.envelope.WeightedMovingAverageEnvelope

Bases: WeightedMovingAverage, EnvelopeMixIn

WeightedMovingAverage and envelope bands separated “perc” from it

Formula:
  • wma (from WeightedMovingAverage)

  • top = wma * (1 + perc)

  • bot = wma * (1 - perc)

alias = ['WMAEnvelope', 'MovingAverageWeightedEnvelope']
frompackages = ()
packages = ()
class backtrader.indicators.envelope.ZeroLagExponentialMovingAverageEnvelope

Bases: ZeroLagExponentialMovingAverage, EnvelopeMixIn

ZeroLagExponentialMovingAverage and envelope bands separated “perc” from it

Formula:
  • zlema (from ZeroLagExponentialMovingAverage)

  • top = zlema * (1 + perc)

  • bot = zlema * (1 - perc)

alias = ['ZLEMAEnvelope', 'ZeroLagEmaEnvelope']
frompackages = ()
packages = ()
class backtrader.indicators.envelope.ZeroLagIndicatorEnvelope

Bases: ZeroLagIndicator, EnvelopeMixIn

ZeroLagIndicator and envelope bands separated “perc” from it

Formula:
  • ec (from ZeroLagIndicator)

  • top = ec * (1 + perc)

  • bot = ec * (1 - perc)

alias = ['ZLIndicatorEnvelope', 'ZLIndEnvelope', 'ECEnvelope', 'ErrorCorrectingEnvelope']
frompackages = ()
packages = ()
backtrader.indicators.envelope.newcls

alias of DicksonMovingAverageEnvelope