backtrader.indicators.wma module

WMA Indicator Module - Weighted Moving Average.

This module provides the WMA (Weighted Moving Average) indicator which gives more weight to recent prices.

Classes:

WeightedMovingAverage: WMA indicator (alias: WMA).

Example

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

self.wma = bt.indicators.WMA(self.data.close, period=20)

def next(self):

# Price above WMA indicates uptrend if self.data.close[0] > self.wma[0]:

self.buy()

# Price below WMA indicates downtrend elif self.data.close[0] < self.wma[0]:

self.sell()

class backtrader.indicators.wma.WeightedMovingAverage[source]

Bases: MovingAverageBase

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))

alias = ('WMA', 'MovingAverageWeighted')
__init__(*args, **kwargs)
next()[source]

Calculate WMA for the current bar.

Applies arithmetic weighting with newest values having more weight.

once(start, end)[source]

Calculate WMA in runonce mode.

Applies weighted average calculation across all bars.

frompackages = ()
packages = ()
backtrader.indicators.wma.WMA

alias of WeightedMovingAverage