backtrader.indicators.prettygoodoscillator module

Pretty Good Oscillator Module - PGO indicator.

This module provides the Pretty Good Oscillator (PGO) developed by Mark Johnson for measuring price distance from moving average in terms of ATR.

Classes:

PrettyGoodOscillator: PGO indicator (aliases: PGO, PrettyGoodOsc).

示例

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

# Calculate Pretty Good Oscillator with 14-period self.pgo = bt.indicators.PrettyGoodOscillator(self.data, period=14)

def next(self):

# Buy when PGO rises above 3.0 (breakout signal) if self.pgo[0] > 3.0:

self.buy()

# Sell short when PGO falls below -3.0 elif self.pgo[0] < -3.0:

self.sell()

# Exit positions when returning to zero elif len(self.position) > 0 and abs(self.pgo[0]) < 0.5:

self.close()

class backtrader.indicators.prettygoodoscillator.PrettyGoodOscillator[源代码]

基类:Indicator

The "Pretty Good Oscillator" (PGO) by Mark Johnson measures the distance of the current close from its simple moving average of period Average), expressed in terms of an average true range (see Average True Range) over a similar period.

So for instance a PGO value of +2.5 would mean the current close is 2.5 average days' range above the SMA.

Johnson's approach was to use it as a breakout system for longer term trades. If the PGO rises above 3.0 then go long, or below -3.0 then go short, and in both cases exit on returning to zero (which is a close back at the SMA).

Formula:
  • pgo = (data.close - sma(data, period)) / atr(data, period)

alias = ('PGO', 'PrettyGoodOsc')
__init__(*args, **kwargs)
next()[源代码]

Calculate PGO for the current bar.

Formula: PGO = (price - MA) / ATR

once(start, end)[源代码]

Calculate PGO in runonce mode.

frompackages = ()
packages = ()