Module backtrader.indicators.mabase
Expand source code
#!/usr/bin/env python
# -*- coding: utf-8; py-indent-offset:4 -*-
###############################################################################
#
# Copyright (C) 2015-2023 Daniel Rodriguez
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################
from __future__ import (absolute_import, division, print_function,
unicode_literals)
from ..utils.py3 import with_metaclass
from . import Indicator
class MovingAverage(object):
'''MovingAverage (alias MovAv)
A placeholder to gather all Moving Average Types in a single place.
Instantiating a SimpleMovingAverage can be achieved as follows::
sma = MovingAverage.Simple(self.data, period)
Or using the shorter aliases::
sma = MovAv.SMA(self.data, period)
or with the full (forwards and backwards) names:
sma = MovAv.SimpleMovingAverage(self.data, period)
sma = MovAv.MovingAverageSimple(self.data, period)
'''
_movavs = []
@classmethod
def register(cls, regcls):
if getattr(regcls, '_notregister', False):
return
cls._movavs.append(regcls)
clsname = regcls.__name__
setattr(cls, clsname, regcls)
clsalias = ''
if clsname.endswith('MovingAverage'):
clsalias = clsname.split('MovingAverage')[0]
elif clsname.startswith('MovingAverage'):
clsalias = clsname.split('MovingAverage')[1]
if clsalias:
setattr(cls, clsalias, regcls)
class MovAv(MovingAverage):
pass # alias
class MetaMovAvBase(Indicator.__class__):
# Register any MovingAverage with the placeholder to allow the automatic
# creation of envelopes and oscillators
def __new__(meta, name, bases, dct):
# Create the class
cls = super(MetaMovAvBase, meta).__new__(meta, name, bases, dct)
MovingAverage.register(cls)
# return the class
return cls
class MovingAverageBase(with_metaclass(MetaMovAvBase, Indicator)):
params = (('period', 30),)
plotinfo = dict(subplot=False)
Classes
class MetaMovAvBase (name, bases, dct)
-
Dirty job manager for a LineSeries
-
During new (class creation), it reads "lines", "plotinfo", "plotlines" class variable definitions and turns them into Classes of type Lines or AutoClassInfo (plotinfo/plotlines)
-
During "new" (instance creation) the lines/plotinfo/plotlines classes are substituted in the instance with instances of the aforementioned classes and aliases are added for the "lines" held in the "lines" instance
Additionally and for remaining kwargs, these are matched against args in plotinfo and if existent are set there and removed from kwargs
Remember that this Metaclass has a MetaParams (from metabase) as root class and therefore "params" defined for the class have been removed from kwargs at an earlier state
Class has already been created … register subclasses
Expand source code
class MetaMovAvBase(Indicator.__class__): # Register any MovingAverage with the placeholder to allow the automatic # creation of envelopes and oscillators def __new__(meta, name, bases, dct): # Create the class cls = super(MetaMovAvBase, meta).__new__(meta, name, bases, dct) MovingAverage.register(cls) # return the class return cls
Ancestors
- MetaIndicator
- MetaLineIterator
- MetaLineSeries
- MetaLineRoot
- MetaParams
- MetaBase
- builtins.type
Inherited members
-
class MovAv
-
MovingAverage (alias MovAv)
A placeholder to gather all Moving Average Types in a single place.
Instantiating a SimpleMovingAverage can be achieved as follows::
sma = MovingAverage.Simple(self.data, period)
Or using the shorter aliases::
sma = MovAv.SMA(self.data, period)
or with the full (forwards and backwards) names:
sma = MovAv.SimpleMovingAverage(self.data, period)
sma = MovAv.MovingAverageSimple(self.data, period)
Expand source code
class MovAv(MovingAverage): pass # alias
Ancestors
Inherited members
MovingAverage
:Adaptive
AdaptiveMovingAverage
Base
DEMA
DMA
Dickson
DicksonMA
DicksonMovingAverage
DoubleExponential
DoubleExponentialMovingAverage
EC
EMA
ErrorCorrecting
Exponential
ExponentialMovingAverage
HMA
Hull
HullMA
HullMovingAverage
KAMA
Modified
ModifiedMovingAverage
MovingAverageAdaptive
MovingAverageBase
MovingAverageDoubleExponential
MovingAverageExponential
MovingAverageSimple
MovingAverageSmoothed
MovingAverageTripleExponential
MovingAverageWeighted
MovingAverageWilder
SMA
SMMA
Simple
SimpleMovingAverage
Smoothed
SmoothedMovingAverage
TEMA
TripleExponential
TripleExponentialMovingAverage
WMA
Weighted
WeightedMovingAverage
Wilder
WilderMA
ZLEMA
ZLInd
ZLIndicator
ZeroLagEma
ZeroLagExponential
ZeroLagExponentialMovingAverage
ZeroLagIndicator
class MovingAverage
-
MovingAverage (alias MovAv)
A placeholder to gather all Moving Average Types in a single place.
Instantiating a SimpleMovingAverage can be achieved as follows::
sma = MovingAverage.Simple(self.data, period)
Or using the shorter aliases::
sma = MovAv.SMA(self.data, period)
or with the full (forwards and backwards) names:
sma = MovAv.SimpleMovingAverage(self.data, period)
sma = MovAv.MovingAverageSimple(self.data, period)
Expand source code
class MovingAverage(object): '''MovingAverage (alias MovAv) A placeholder to gather all Moving Average Types in a single place. Instantiating a SimpleMovingAverage can be achieved as follows:: sma = MovingAverage.Simple(self.data, period) Or using the shorter aliases:: sma = MovAv.SMA(self.data, period) or with the full (forwards and backwards) names: sma = MovAv.SimpleMovingAverage(self.data, period) sma = MovAv.MovingAverageSimple(self.data, period) ''' _movavs = [] @classmethod def register(cls, regcls): if getattr(regcls, '_notregister', False): return cls._movavs.append(regcls) clsname = regcls.__name__ setattr(cls, clsname, regcls) clsalias = '' if clsname.endswith('MovingAverage'): clsalias = clsname.split('MovingAverage')[0] elif clsname.startswith('MovingAverage'): clsalias = clsname.split('MovingAverage')[1] if clsalias: setattr(cls, clsalias, regcls)
Subclasses
Class variables
var Adaptive
-
Defined by Perry Kaufman in his book
"Smarter Trading"
.It is A Moving Average with a continuously scaled smoothing factor by taking into account market direction and volatility. The smoothing factor is calculated from 2 ExponetialMovingAverage smoothing factors, a fast one and slow one.
If the market trends the value will tend to the fast ema smoothing period. If the market doesn't trend it will move towards the slow EMA smoothing period.
It is a subclass of SmoothingMovingAverage, overriding once to account for the live nature of the smoothing factor
Formula
- direction = close - close_period
- volatility = sumN(abs(close - close_n), period)
- effiency_ratio = abs(direction / volatility)
- fast = 2 / (fast_period + 1)
-
slow = 2 / (slow_period + 1)
-
smfactor = squared(efficienty_ratio * (fast - slow) + slow)
-
smfactor1 = 1.0 - smfactor
-
The initial seed value is a SimpleMovingAverage
See also: - http://fxcodebase.com/wiki/index.php/Kaufman's_Adaptive_Moving_Average_(KAMA) - http://www.metatrader5.com/en/terminal/help/analytics/indicators/trend_indicators/ama - http://help.cqg.com/cqgic/default.htm#!Documents/adaptivemovingaverag2.htm
var AdaptiveMovingAverage
-
Defined by Perry Kaufman in his book
"Smarter Trading"
.It is A Moving Average with a continuously scaled smoothing factor by taking into account market direction and volatility. The smoothing factor is calculated from 2 ExponetialMovingAverage smoothing factors, a fast one and slow one.
If the market trends the value will tend to the fast ema smoothing period. If the market doesn't trend it will move towards the slow EMA smoothing period.
It is a subclass of SmoothingMovingAverage, overriding once to account for the live nature of the smoothing factor
Formula
- direction = close - close_period
- volatility = sumN(abs(close - close_n), period)
- effiency_ratio = abs(direction / volatility)
- fast = 2 / (fast_period + 1)
-
slow = 2 / (slow_period + 1)
-
smfactor = squared(efficienty_ratio * (fast - slow) + slow)
-
smfactor1 = 1.0 - smfactor
-
The initial seed value is a SimpleMovingAverage
See also: - http://fxcodebase.com/wiki/index.php/Kaufman's_Adaptive_Moving_Average_(KAMA) - http://www.metatrader5.com/en/terminal/help/analytics/indicators/trend_indicators/ama - http://help.cqg.com/cqgic/default.htm#!Documents/adaptivemovingaverag2.htm
var Base
-
Base class for LineXXX instances that hold more than one line
var DEMA
-
DEMA was first time introduced in 1994, in the article "Smoothing Data with Faster Moving Averages" by Patrick G. Mulloy in "Technical Analysis of Stocks & Commodities" magazine.
It attempts to reduce the inherent lag associated to Moving Averages
Formula
- dema = (2.0 - ema(data, period) - ema(ema(data, period), period)
See
(None)
var DMA
-
By Nathan Dickson
The Dickson Moving Average combines the
ZeroLagIndicator
(aka ErrorCorrecting or EC) by Ehlers, and theHullMovingAverage
to try to deliver a result close to that of the Jurik Moving AveragesFormula
- ec = ZeroLagIndicator(period, gainlimit)
-
hma = HullMovingAverage(hperiod)
-
dma = (ec + hma) / 2
-
The default moving average for the ZeroLagIndicator is EMA, but can be changed with the parameter
_movav
!!! note "Note: the passed moving average must calculate alpha (and 1 -" alpha) and make them available as attributes
alpha
andalpha1
- The 2nd moving averag can be changed from Hull to anything else with the param _hma
See also: - https://www.reddit.com/r/algotrading/comments/4xj3vh/dickson_moving_average
var Dickson
-
By Nathan Dickson
The Dickson Moving Average combines the
ZeroLagIndicator
(aka ErrorCorrecting or EC) by Ehlers, and theHullMovingAverage
to try to deliver a result close to that of the Jurik Moving AveragesFormula
- ec = ZeroLagIndicator(period, gainlimit)
-
hma = HullMovingAverage(hperiod)
-
dma = (ec + hma) / 2
-
The default moving average for the ZeroLagIndicator is EMA, but can be changed with the parameter
_movav
!!! note "Note: the passed moving average must calculate alpha (and 1 -" alpha) and make them available as attributes
alpha
andalpha1
- The 2nd moving averag can be changed from Hull to anything else with the param _hma
See also: - https://www.reddit.com/r/algotrading/comments/4xj3vh/dickson_moving_average
var DicksonMA
-
By Nathan Dickson
The Dickson Moving Average combines the
ZeroLagIndicator
(aka ErrorCorrecting or EC) by Ehlers, and theHullMovingAverage
to try to deliver a result close to that of the Jurik Moving AveragesFormula
- ec = ZeroLagIndicator(period, gainlimit)
-
hma = HullMovingAverage(hperiod)
-
dma = (ec + hma) / 2
-
The default moving average for the ZeroLagIndicator is EMA, but can be changed with the parameter
_movav
!!! note "Note: the passed moving average must calculate alpha (and 1 -" alpha) and make them available as attributes
alpha
andalpha1
- The 2nd moving averag can be changed from Hull to anything else with the param _hma
See also: - https://www.reddit.com/r/algotrading/comments/4xj3vh/dickson_moving_average
var DicksonMovingAverage
-
By Nathan Dickson
The Dickson Moving Average combines the
ZeroLagIndicator
(aka ErrorCorrecting or EC) by Ehlers, and theHullMovingAverage
to try to deliver a result close to that of the Jurik Moving AveragesFormula
- ec = ZeroLagIndicator(period, gainlimit)
-
hma = HullMovingAverage(hperiod)
-
dma = (ec + hma) / 2
-
The default moving average for the ZeroLagIndicator is EMA, but can be changed with the parameter
_movav
!!! note "Note: the passed moving average must calculate alpha (and 1 -" alpha) and make them available as attributes
alpha
andalpha1
- The 2nd moving averag can be changed from Hull to anything else with the param _hma
See also: - https://www.reddit.com/r/algotrading/comments/4xj3vh/dickson_moving_average
var DoubleExponential
-
DEMA was first time introduced in 1994, in the article "Smoothing Data with Faster Moving Averages" by Patrick G. Mulloy in "Technical Analysis of Stocks & Commodities" magazine.
It attempts to reduce the inherent lag associated to Moving Averages
Formula
- dema = (2.0 - ema(data, period) - ema(ema(data, period), period)
See
(None)
var DoubleExponentialMovingAverage
-
DEMA was first time introduced in 1994, in the article "Smoothing Data with Faster Moving Averages" by Patrick G. Mulloy in "Technical Analysis of Stocks & Commodities" magazine.
It attempts to reduce the inherent lag associated to Moving Averages
Formula
- dema = (2.0 - ema(data, period) - ema(ema(data, period), period)
See
(None)
var EC
-
By John Ehlers and Ric Way
The zero-lag indicator (ZLIndicator) is a variation of the EMA which modifies the EMA by trying to minimize the error (distance price - error correction) and thus reduce the lag
Formula
-
EMA(data, period)
-
For each iteration calculate a best-error-correction of the ema (see the paper and/or the code) iterating over
-bestgain
->+bestgain
for the error correction factor (both incl.) -
The default moving average is EMA, but can be changed with the parameter
_movav
!!! note "Note: the passed moving average must calculate alpha (and 1 -" alpha) and make them available as attributes
alpha
andalpha1
in the instanceSee also: - http://www.mesasoftware.com/papers/ZeroLag.pdf
-
var EMA
-
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
See also: - http://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average
var ErrorCorrecting
-
By John Ehlers and Ric Way
The zero-lag indicator (ZLIndicator) is a variation of the EMA which modifies the EMA by trying to minimize the error (distance price - error correction) and thus reduce the lag
Formula
-
EMA(data, period)
-
For each iteration calculate a best-error-correction of the ema (see the paper and/or the code) iterating over
-bestgain
->+bestgain
for the error correction factor (both incl.) -
The default moving average is EMA, but can be changed with the parameter
_movav
!!! note "Note: the passed moving average must calculate alpha (and 1 -" alpha) and make them available as attributes
alpha
andalpha1
in the instanceSee also: - http://www.mesasoftware.com/papers/ZeroLag.pdf
-
var Exponential
-
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
See also: - http://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average
var ExponentialMovingAverage
-
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
See also: - http://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average
var HMA
-
By Alan Hull
The Hull Moving Average solves the age old dilemma of making a moving average more responsive to current price activity whilst maintaining curve smoothness. In fact the HMA almost eliminates lag altogether and manages to improve smoothing at the same time.
Formula
- hma = wma(2 * wma(data, period // 2) - wma(data, period), sqrt(period))
See also: - http://alanhull.com/hull-moving-average
Note
- Please note that the final minimum period is not the period passed with
the parameter
period
. A final moving average on moving average is done in which the period is the square root of the original.
In the default case of
30
the final minimum period before the moving average produces a non-NAN value is34
var Hull
-
By Alan Hull
The Hull Moving Average solves the age old dilemma of making a moving average more responsive to current price activity whilst maintaining curve smoothness. In fact the HMA almost eliminates lag altogether and manages to improve smoothing at the same time.
Formula
- hma = wma(2 * wma(data, period // 2) - wma(data, period), sqrt(period))
See also: - http://alanhull.com/hull-moving-average
Note
- Please note that the final minimum period is not the period passed with
the parameter
period
. A final moving average on moving average is done in which the period is the square root of the original.
In the default case of
30
the final minimum period before the moving average produces a non-NAN value is34
var HullMA
-
By Alan Hull
The Hull Moving Average solves the age old dilemma of making a moving average more responsive to current price activity whilst maintaining curve smoothness. In fact the HMA almost eliminates lag altogether and manages to improve smoothing at the same time.
Formula
- hma = wma(2 * wma(data, period // 2) - wma(data, period), sqrt(period))
See also: - http://alanhull.com/hull-moving-average
Note
- Please note that the final minimum period is not the period passed with
the parameter
period
. A final moving average on moving average is done in which the period is the square root of the original.
In the default case of
30
the final minimum period before the moving average produces a non-NAN value is34
var HullMovingAverage
-
By Alan Hull
The Hull Moving Average solves the age old dilemma of making a moving average more responsive to current price activity whilst maintaining curve smoothness. In fact the HMA almost eliminates lag altogether and manages to improve smoothing at the same time.
Formula
- hma = wma(2 * wma(data, period // 2) - wma(data, period), sqrt(period))
See also: - http://alanhull.com/hull-moving-average
Note
- Please note that the final minimum period is not the period passed with
the parameter
period
. A final moving average on moving average is done in which the period is the square root of the original.
In the default case of
30
the final minimum period before the moving average produces a non-NAN value is34
var KAMA
-
Defined by Perry Kaufman in his book
"Smarter Trading"
.It is A Moving Average with a continuously scaled smoothing factor by taking into account market direction and volatility. The smoothing factor is calculated from 2 ExponetialMovingAverage smoothing factors, a fast one and slow one.
If the market trends the value will tend to the fast ema smoothing period. If the market doesn't trend it will move towards the slow EMA smoothing period.
It is a subclass of SmoothingMovingAverage, overriding once to account for the live nature of the smoothing factor
Formula
- direction = close - close_period
- volatility = sumN(abs(close - close_n), period)
- effiency_ratio = abs(direction / volatility)
- fast = 2 / (fast_period + 1)
-
slow = 2 / (slow_period + 1)
-
smfactor = squared(efficienty_ratio * (fast - slow) + slow)
-
smfactor1 = 1.0 - smfactor
-
The initial seed value is a SimpleMovingAverage
See also: - http://fxcodebase.com/wiki/index.php/Kaufman's_Adaptive_Moving_Average_(KAMA) - http://www.metatrader5.com/en/terminal/help/analytics/indicators/trend_indicators/ama - http://help.cqg.com/cqgic/default.htm#!Documents/adaptivemovingaverag2.htm
var Modified
-
Smoothing Moving Average used by Wilder in his 1978 book
New Concepts in Technical Trading
Defined in his book originally as:
- new_value = (old_value * (period - 1) + new_data) / period
Can be expressed as a SmoothingMovingAverage with the following factors:
- self.smfactor -> 1.0 / period
- self.smfactor1 ->
1.0 - self.smfactor
Formula
- movav = prev * (1.0 - smoothfactor) + newdata * smoothfactor
See also: - http://en.wikipedia.org/wiki/Moving_average#Modified_moving_average
var ModifiedMovingAverage
-
Smoothing Moving Average used by Wilder in his 1978 book
New Concepts in Technical Trading
Defined in his book originally as:
- new_value = (old_value * (period - 1) + new_data) / period
Can be expressed as a SmoothingMovingAverage with the following factors:
- self.smfactor -> 1.0 / period
- self.smfactor1 ->
1.0 - self.smfactor
Formula
- movav = prev * (1.0 - smoothfactor) + newdata * smoothfactor
See also: - http://en.wikipedia.org/wiki/Moving_average#Modified_moving_average
var MovingAverageAdaptive
-
Defined by Perry Kaufman in his book
"Smarter Trading"
.It is A Moving Average with a continuously scaled smoothing factor by taking into account market direction and volatility. The smoothing factor is calculated from 2 ExponetialMovingAverage smoothing factors, a fast one and slow one.
If the market trends the value will tend to the fast ema smoothing period. If the market doesn't trend it will move towards the slow EMA smoothing period.
It is a subclass of SmoothingMovingAverage, overriding once to account for the live nature of the smoothing factor
Formula
- direction = close - close_period
- volatility = sumN(abs(close - close_n), period)
- effiency_ratio = abs(direction / volatility)
- fast = 2 / (fast_period + 1)
-
slow = 2 / (slow_period + 1)
-
smfactor = squared(efficienty_ratio * (fast - slow) + slow)
-
smfactor1 = 1.0 - smfactor
-
The initial seed value is a SimpleMovingAverage
See also: - http://fxcodebase.com/wiki/index.php/Kaufman's_Adaptive_Moving_Average_(KAMA) - http://www.metatrader5.com/en/terminal/help/analytics/indicators/trend_indicators/ama - http://help.cqg.com/cqgic/default.htm#!Documents/adaptivemovingaverag2.htm
var MovingAverageBase
-
Base class for LineXXX instances that hold more than one line
var MovingAverageDoubleExponential
-
DEMA was first time introduced in 1994, in the article "Smoothing Data with Faster Moving Averages" by Patrick G. Mulloy in "Technical Analysis of Stocks & Commodities" magazine.
It attempts to reduce the inherent lag associated to Moving Averages
Formula
- dema = (2.0 - ema(data, period) - ema(ema(data, period), period)
See
(None)
var MovingAverageExponential
-
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
See also: - http://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average
var MovingAverageSimple
-
Non-weighted average of the last n periods
Formula
- movav = Sum(data, period) / period
See also: - http://en.wikipedia.org/wiki/Moving_average#Simple_moving_average
var MovingAverageSmoothed
-
Smoothing Moving Average used by Wilder in his 1978 book
New Concepts in Technical Trading
Defined in his book originally as:
- new_value = (old_value * (period - 1) + new_data) / period
Can be expressed as a SmoothingMovingAverage with the following factors:
- self.smfactor -> 1.0 / period
- self.smfactor1 ->
1.0 - self.smfactor
Formula
- movav = prev * (1.0 - smoothfactor) + newdata * smoothfactor
See also: - http://en.wikipedia.org/wiki/Moving_average#Modified_moving_average
var MovingAverageTripleExponential
-
TEMA was first time introduced in 1994, in the article "Smoothing Data with Faster Moving Averages" by Patrick G. Mulloy in "Technical Analysis of Stocks & Commodities" magazine.
It attempts to reduce the inherent lag associated to Moving Averages
Formula
- ema1 = ema(data, period)
- ema2 = ema(ema1, period)
- ema3 = ema(ema2, period)
- tema = 3 * ema1 - 3 * ema2 + ema3
See
(None)
var MovingAverageWeighted
-
A Moving Average which gives an arithmetic weighting to values with the newest having the more weight
Formula
- weights = range(1, period + 1)
- coef = 2 / (period * (period + 1))
- movav = coef * Sum(weight[i] * data[period - i] for i in range(period))
See also: - http://en.wikipedia.org/wiki/Moving_average#Weighted_moving_average
var MovingAverageWilder
-
Smoothing Moving Average used by Wilder in his 1978 book
New Concepts in Technical Trading
Defined in his book originally as:
- new_value = (old_value * (period - 1) + new_data) / period
Can be expressed as a SmoothingMovingAverage with the following factors:
- self.smfactor -> 1.0 / period
- self.smfactor1 ->
1.0 - self.smfactor
Formula
- movav = prev * (1.0 - smoothfactor) + newdata * smoothfactor
See also: - http://en.wikipedia.org/wiki/Moving_average#Modified_moving_average
var SMA
-
Non-weighted average of the last n periods
Formula
- movav = Sum(data, period) / period
See also: - http://en.wikipedia.org/wiki/Moving_average#Simple_moving_average
var SMMA
-
Smoothing Moving Average used by Wilder in his 1978 book
New Concepts in Technical Trading
Defined in his book originally as:
- new_value = (old_value * (period - 1) + new_data) / period
Can be expressed as a SmoothingMovingAverage with the following factors:
- self.smfactor -> 1.0 / period
- self.smfactor1 ->
1.0 - self.smfactor
Formula
- movav = prev * (1.0 - smoothfactor) + newdata * smoothfactor
See also: - http://en.wikipedia.org/wiki/Moving_average#Modified_moving_average
var Simple
-
Non-weighted average of the last n periods
Formula
- movav = Sum(data, period) / period
See also: - http://en.wikipedia.org/wiki/Moving_average#Simple_moving_average
var SimpleMovingAverage
-
Non-weighted average of the last n periods
Formula
- movav = Sum(data, period) / period
See also: - http://en.wikipedia.org/wiki/Moving_average#Simple_moving_average
var Smoothed
-
Smoothing Moving Average used by Wilder in his 1978 book
New Concepts in Technical Trading
Defined in his book originally as:
- new_value = (old_value * (period - 1) + new_data) / period
Can be expressed as a SmoothingMovingAverage with the following factors:
- self.smfactor -> 1.0 / period
- self.smfactor1 ->
1.0 - self.smfactor
Formula
- movav = prev * (1.0 - smoothfactor) + newdata * smoothfactor
See also: - http://en.wikipedia.org/wiki/Moving_average#Modified_moving_average
var SmoothedMovingAverage
-
Smoothing Moving Average used by Wilder in his 1978 book
New Concepts in Technical Trading
Defined in his book originally as:
- new_value = (old_value * (period - 1) + new_data) / period
Can be expressed as a SmoothingMovingAverage with the following factors:
- self.smfactor -> 1.0 / period
- self.smfactor1 ->
1.0 - self.smfactor
Formula
- movav = prev * (1.0 - smoothfactor) + newdata * smoothfactor
See also: - http://en.wikipedia.org/wiki/Moving_average#Modified_moving_average
var TEMA
-
TEMA was first time introduced in 1994, in the article "Smoothing Data with Faster Moving Averages" by Patrick G. Mulloy in "Technical Analysis of Stocks & Commodities" magazine.
It attempts to reduce the inherent lag associated to Moving Averages
Formula
- ema1 = ema(data, period)
- ema2 = ema(ema1, period)
- ema3 = ema(ema2, period)
- tema = 3 * ema1 - 3 * ema2 + ema3
See
(None)
var TripleExponential
-
TEMA was first time introduced in 1994, in the article "Smoothing Data with Faster Moving Averages" by Patrick G. Mulloy in "Technical Analysis of Stocks & Commodities" magazine.
It attempts to reduce the inherent lag associated to Moving Averages
Formula
- ema1 = ema(data, period)
- ema2 = ema(ema1, period)
- ema3 = ema(ema2, period)
- tema = 3 * ema1 - 3 * ema2 + ema3
See
(None)
var TripleExponentialMovingAverage
-
TEMA was first time introduced in 1994, in the article "Smoothing Data with Faster Moving Averages" by Patrick G. Mulloy in "Technical Analysis of Stocks & Commodities" magazine.
It attempts to reduce the inherent lag associated to Moving Averages
Formula
- ema1 = ema(data, period)
- ema2 = ema(ema1, period)
- ema3 = ema(ema2, period)
- tema = 3 * ema1 - 3 * ema2 + ema3
See
(None)
var WMA
-
A Moving Average which gives an arithmetic weighting to values with the newest having the more weight
Formula
- weights = range(1, period + 1)
- coef = 2 / (period * (period + 1))
- movav = coef * Sum(weight[i] * data[period - i] for i in range(period))
See also: - http://en.wikipedia.org/wiki/Moving_average#Weighted_moving_average
var Weighted
-
A Moving Average which gives an arithmetic weighting to values with the newest having the more weight
Formula
- weights = range(1, period + 1)
- coef = 2 / (period * (period + 1))
- movav = coef * Sum(weight[i] * data[period - i] for i in range(period))
See also: - http://en.wikipedia.org/wiki/Moving_average#Weighted_moving_average
var WeightedMovingAverage
-
A Moving Average which gives an arithmetic weighting to values with the newest having the more weight
Formula
- weights = range(1, period + 1)
- coef = 2 / (period * (period + 1))
- movav = coef * Sum(weight[i] * data[period - i] for i in range(period))
See also: - http://en.wikipedia.org/wiki/Moving_average#Weighted_moving_average
var Wilder
-
Smoothing Moving Average used by Wilder in his 1978 book
New Concepts in Technical Trading
Defined in his book originally as:
- new_value = (old_value * (period - 1) + new_data) / period
Can be expressed as a SmoothingMovingAverage with the following factors:
- self.smfactor -> 1.0 / period
- self.smfactor1 ->
1.0 - self.smfactor
Formula
- movav = prev * (1.0 - smoothfactor) + newdata * smoothfactor
See also: - http://en.wikipedia.org/wiki/Moving_average#Modified_moving_average
var WilderMA
-
Smoothing Moving Average used by Wilder in his 1978 book
New Concepts in Technical Trading
Defined in his book originally as:
- new_value = (old_value * (period - 1) + new_data) / period
Can be expressed as a SmoothingMovingAverage with the following factors:
- self.smfactor -> 1.0 / period
- self.smfactor1 ->
1.0 - self.smfactor
Formula
- movav = prev * (1.0 - smoothfactor) + newdata * smoothfactor
See also: - http://en.wikipedia.org/wiki/Moving_average#Modified_moving_average
var ZLEMA
-
The zero-lag exponential moving average (ZLEMA) is a variation of the EMA which adds a momentum term aiming to reduce lag in the average so as to track current prices more closely.
Formula
- lag = (period - 1) / 2
- zlema = ema(2 * data - data(-lag))
See also: - http://user42.tuxfamily.org/chart/manual/Zero_002dLag-Exponential-Moving-Average.html
var ZLInd
-
By John Ehlers and Ric Way
The zero-lag indicator (ZLIndicator) is a variation of the EMA which modifies the EMA by trying to minimize the error (distance price - error correction) and thus reduce the lag
Formula
-
EMA(data, period)
-
For each iteration calculate a best-error-correction of the ema (see the paper and/or the code) iterating over
-bestgain
->+bestgain
for the error correction factor (both incl.) -
The default moving average is EMA, but can be changed with the parameter
_movav
!!! note "Note: the passed moving average must calculate alpha (and 1 -" alpha) and make them available as attributes
alpha
andalpha1
in the instanceSee also: - http://www.mesasoftware.com/papers/ZeroLag.pdf
-
var ZLIndicator
-
By John Ehlers and Ric Way
The zero-lag indicator (ZLIndicator) is a variation of the EMA which modifies the EMA by trying to minimize the error (distance price - error correction) and thus reduce the lag
Formula
-
EMA(data, period)
-
For each iteration calculate a best-error-correction of the ema (see the paper and/or the code) iterating over
-bestgain
->+bestgain
for the error correction factor (both incl.) -
The default moving average is EMA, but can be changed with the parameter
_movav
!!! note "Note: the passed moving average must calculate alpha (and 1 -" alpha) and make them available as attributes
alpha
andalpha1
in the instanceSee also: - http://www.mesasoftware.com/papers/ZeroLag.pdf
-
var ZeroLagEma
-
The zero-lag exponential moving average (ZLEMA) is a variation of the EMA which adds a momentum term aiming to reduce lag in the average so as to track current prices more closely.
Formula
- lag = (period - 1) / 2
- zlema = ema(2 * data - data(-lag))
See also: - http://user42.tuxfamily.org/chart/manual/Zero_002dLag-Exponential-Moving-Average.html
var ZeroLagExponential
-
The zero-lag exponential moving average (ZLEMA) is a variation of the EMA which adds a momentum term aiming to reduce lag in the average so as to track current prices more closely.
Formula
- lag = (period - 1) / 2
- zlema = ema(2 * data - data(-lag))
See also: - http://user42.tuxfamily.org/chart/manual/Zero_002dLag-Exponential-Moving-Average.html
var ZeroLagExponentialMovingAverage
-
The zero-lag exponential moving average (ZLEMA) is a variation of the EMA which adds a momentum term aiming to reduce lag in the average so as to track current prices more closely.
Formula
- lag = (period - 1) / 2
- zlema = ema(2 * data - data(-lag))
See also: - http://user42.tuxfamily.org/chart/manual/Zero_002dLag-Exponential-Moving-Average.html
var ZeroLagIndicator
-
By John Ehlers and Ric Way
The zero-lag indicator (ZLIndicator) is a variation of the EMA which modifies the EMA by trying to minimize the error (distance price - error correction) and thus reduce the lag
Formula
-
EMA(data, period)
-
For each iteration calculate a best-error-correction of the ema (see the paper and/or the code) iterating over
-bestgain
->+bestgain
for the error correction factor (both incl.) -
The default moving average is EMA, but can be changed with the parameter
_movav
!!! note "Note: the passed moving average must calculate alpha (and 1 -" alpha) and make them available as attributes
alpha
andalpha1
in the instanceSee also: - http://www.mesasoftware.com/papers/ZeroLag.pdf
-
Static methods
def register(regcls)
-
Expand source code
@classmethod def register(cls, regcls): if getattr(regcls, '_notregister', False): return cls._movavs.append(regcls) clsname = regcls.__name__ setattr(cls, clsname, regcls) clsalias = '' if clsname.endswith('MovingAverage'): clsalias = clsname.split('MovingAverage')[0] elif clsname.startswith('MovingAverage'): clsalias = clsname.split('MovingAverage')[1] if clsalias: setattr(cls, clsalias, regcls)
class MovingAverageBase (*args, **kwargs)
-
Base class for LineXXX instances that hold more than one line
Expand source code
class MovingAverageBase(with_metaclass(MetaMovAvBase, Indicator)): params = (('period', 30),) plotinfo = dict(subplot=False)
Ancestors
Subclasses
- DoubleExponentialMovingAverage
- TripleExponentialMovingAverage
- DicksonMovingAverage
- ExponentialMovingAverage
- HullMovingAverage
- AdaptiveMovingAverage
- MovingAverageSimple
- SmoothedMovingAverage
- WeightedMovingAverage
- ZeroLagExponentialMovingAverage
- ZeroLagIndicator
Class variables
var alias
var aliased
var frompackages
var linealias
var packages
var params
var plotinfo
var plotlines
Inherited members