backtrader.indicators.percentchange module

Percent Change Indicator Module - Percentage change calculation.

This module provides the Percent Change indicator for measuring the percentage change in price over a given period.

Classes:

PercentChange: Percentage change indicator (alias: PctChange).

示例

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

# Measure 30-period percent change self.pctchange = bt.indicators.PctChange(self.data.close, period=30)

def next(self):

# Buy when percent change is positive if self.pctchange[0] > 0:

self.buy()

class backtrader.indicators.percentchange.PercentChange[源代码]

基类:Indicator

Measures the percentage change of the current value with respect to that of period bars ago

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

Calculate percent change for the current bar.

Formula: pctchange = (current_value / value_period_ago) - 1.0 Returns 0.0 if the previous value is 0 to avoid division by zero.

once(start, end)[源代码]

Calculate percent change in runonce mode.

Computes percentage change for each bar relative to the value 'period' bars ago.

frompackages = ()
packages = ()
backtrader.indicators.percentchange.PctChange

PercentChange 的别名