backtrader.indicators.priceoscillator module

Price Oscillator Module - Price oscillators.

This module provides Price Oscillator indicators that measure the difference between two moving averages.

Classes:

_PriceOscBase: Base class for price oscillators. PriceOscillator: Price difference (aliases: PriceOsc, APO, AbsPriceOsc). PercentagePriceOscillator: Percentage price oscillator (aliases: PPO, PercPriceOsc). PercentagePriceOscillatorShort: PPO with short denominator (aliases: PPOShort).

Example

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

self.ppo = bt.indicators.PPO(self.data, period1=12, period2=26)

def next(self):
if self.ppo.ppo[0] > self.ppo.signal[0]:

self.buy()

elif self.ppo.ppo[0] < self.ppo.signal[0]:

self.sell()

class backtrader.indicators.priceoscillator.PriceOscillator[source]

Bases: _PriceOscBase

Shows the difference between a short and long exponential moving averages expressed in points.

Formula:
  • po = ema(short) - ema(long)

See:
alias = ('PriceOsc', 'AbsolutePriceOscillator', 'APO', 'AbsPriceOsc')
frompackages = ()
packages = ()
class backtrader.indicators.priceoscillator.PercentagePriceOscillator[source]

Bases: _PriceOscBase

Shows the difference between a short and long exponential moving averages expressed in percentage. The MACD does the same but expressed in absolute points.

Expressing the difference in percentage allows to compare the indicator at different points in time when the underlying value has significatnly different values.

Formula:
  • po = 100 * (ema(short) - ema(long)) / ema(long)

See:
alias = ('PPO', 'PercPriceOsc')
plotlines = <backtrader.metabase.plotlines_obj object>
__init__(*args, **kwargs)
next()[source]

Calculate PPO, signal, and histogram for current bar.

PPO = 100 * (ma1 - ma2) / ma2 Signal = EMA(PPO) Histogram = PPO - Signal

nextstart()[source]

Seed PPO calculation on first valid bar.

Initializes signal line with first PPO value.

once(start, end)[source]

Calculate PPO in runonce mode.

frompackages = ()
packages = ()
class backtrader.indicators.priceoscillator.PercentagePriceOscillatorShort[source]

Bases: PercentagePriceOscillator

Shows the difference between a short and long exponential moving averages expressed in percentage. The MACD does the same but expressed in absolute points.

Expressing the difference in percentage allows to compare the indicator at different points in time when the underlying value has significatnly different values.

Most on-line literature shows the percentage calculation having the long exponential moving average as the denominator. Some sources like MetaStock use the short one.

Formula:
  • po = 100 * (ema(short) - ema(long)) / ema(short)

See:
alias = ('PPOShort', 'PercPriceOscShort')
frompackages = ()
packages = ()