backtrader.indicators.ema module

EMA Indicator Module - Exponential Moving Average.

This module provides the EMA (Exponential Moving Average) indicator which applies weighting factors that decrease exponentially.

Classes:

ExponentialMovingAverage: EMA indicator (alias: EMA).

Example

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

self.ema = bt.indicators.EMA(self.data.close, period=20)

def next(self):
if self.data.close[0] > self.ema[0]:

self.buy()

class backtrader.indicators.ema.ExponentialMovingAverage[source]

Bases: MovingAverageBase

A Moving Average that smoothes data exponentially over time.

It is a subclass of SmoothingMovingAverage.

  • self.smfactor -> 2 / (1 + period)

  • self.smfactor1 -> 1 - self.smfactor

Formula:
  • movav = prev * (1.0 - smoothfactor) + newdata * smoothfactor

alias = ('EMA', 'MovingAverageExponential')
__init__(*args, **kwargs)
nextstart()[source]

Seed the EMA with SMA of first period values.

next()[source]

Calculate EMA for the current bar.

Formula: EMA = previous_ema * alpha1 + current_price * alpha

once(start, end)[source]

Calculate EMA in runonce mode

frompackages = ()
packages = ()
backtrader.indicators.ema.EMA

alias of ExponentialMovingAverage