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).
Example
- 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[source]¶
Bases:
IndicatorMeasures 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()[source]¶
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)[source]¶
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¶
alias of
PercentChange