backtrader.indicators.stochastic module

Stochastic Indicator Module - Stochastic Oscillator.

This module provides the Stochastic Oscillator indicator developed by Dr. George Lane in the 1950s for identifying overbought/oversold conditions.

Classes:

_StochasticBase: Base class for Stochastic indicators. StochasticFast: Fast Stochastic oscillator. Stochastic: Slow Stochastic oscillator (alias: StochasticSlow). StochasticFull: Full Stochastic with all 3 lines.

示例

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

self.stoch = bt.indicators.Stochastic(self.data, period=14)

def next(self):
if self.stoch.percK[0] > self.stoch.percD[0]:

self.buy()

class backtrader.indicators.stochastic.StochasticFast[源代码]

基类:_StochasticBase

By Dr. George Lane in the 50s. It compares a closing price to the price range and tries to show convergence if the closing prices are close to the extremes

  • It will go up if closing prices are close to the highs

  • It will roughly go down if closing prices are close to the lows

It shows divergence if the extremes keep on growing, but closing prices do not in the same manner (distance to the extremes grows)

Formula:
  • hh = highest(data.high, period)

  • ll = lowest(data.low, period)

  • knum = data.close - ll

  • kden = hh - ll

  • k = 100 * (knum / kden)

  • d = MovingAverage(k, period_dfast)

See:
__init__(*args, **kwargs)
next()[源代码]

Calculate Fast Stochastic for the current bar.

%K = 100 * (close - lowest) / (highest - lowest) %D = SMA(%K, period_dfast)

once(start, end)[源代码]

Calculate Fast Stochastic in runonce mode.

Computes %K and %D values across all bars.

frompackages = ()
packages = ()
class backtrader.indicators.stochastic.Stochastic[源代码]

基类:_StochasticBase

The regular (or slow version) adds an additional moving average layer and thus:

  • The percD line of the StochasticFast becomes the percK line

  • percD becomes a moving average of period_dslow of the original percD

Formula:
  • k = k

  • d = d

  • d = MovingAverage(d, period_dslow)

See:
alias = ('StochasticSlow',)
__init__(*args, **kwargs)
next()[源代码]

Calculate Slow Stochastic for the current bar.

Fast %D becomes Slow %K, then Slow %D is SMA of Slow %K.

once(start, end)[源代码]

Calculate Slow Stochastic in runonce mode.

Computes slow %K and %D values across all bars.

frompackages = ()
packages = ()
class backtrader.indicators.stochastic.StochasticFull[源代码]

基类:_StochasticBase

This version displays the 3 possible lines:

  • percK

  • percD

  • percSlow

Formula:
  • k = d

  • d = MovingAverage(k, period_dslow)

  • dslow =

See:
plotlines = <backtrader.metabase.plotlines_obj object>
__init__(*args, **kwargs)
next()[源代码]

Calculate Full Stochastic for the current bar.

%K = raw stochastic value %D = SMA(%K, period_dfast) %DSlow = SMA(%D, period_dslow)

once(start, end)[源代码]

Calculate Full Stochastic in runonce mode.

Computes %K, %D, and %DSlow values across all bars.

frompackages = ()
packages = ()