backtrader.indicators.pivotpoint module¶
Pivot Point Indicator Module - Support and resistance levels.
This module provides Pivot Point indicators for calculating support and resistance levels from previous period price data.
- Classes:
PivotPoint: Standard pivot points with 2 support/resistance levels. FibonacciPivotPoint: Pivot points with Fibonacci-based levels. DemarkPivotPoint: Demark pivot point calculation.
示例
- class MyStrategy(bt.Strategy):
- def __init__(self):
# Calculate pivot points from resampled data (data1) self.pivot = bt.indicators.PivotPoint(self.data1)
- def next(self):
# Buy when price breaks above resistance level 1 if self.data.close[0] > self.pivot.r1[0]:
self.buy()
# Sell when price breaks below support level 1 elif self.data.close[0] < self.pivot.s1[0]:
self.sell()
- class backtrader.indicators.pivotpoint.PivotPoint[源代码]¶
基类:
IndicatorDefines a level of significance by taking into account the average of price bar components of the past period of a larger timeframe. For example, when operating with days, the values are taking from the already "past" month fixed prices.
Example of using this indicator:
data = btfeeds.ADataFeed(dataname=x, timeframe=bt.TimeFrame.Days) cerebro.adddata(data) cerebro.resampledata(data, timeframe=bt.TimeFrame.Months)
In the
__init__method of the strategy:pivotindicator = btind.PivotPoiont(self.data1) # the resampled data
The indicator will try to automatically plo to the non-resampled data. To disable this behavior, use the following during construction:
_autoplot=False
备注
The example shows days and months, but any combination of timeframes can be used. See the literature for recommended combinations
- Formula:
pivot = (h + l + c) / 3 # variants duplicate close or add open
support1 = 2.0 * pivot - high
support2 = pivot - (high - low)
resistance1 = 2.0 * pivot - low
resistance2 = pivot + (high - low)
- See:
- plotinfo = <backtrader.metabase.plotinfo_obj object>¶
- __init__(*args, **kwargs)¶
- next()[源代码]¶
Calculate pivot point and support/resistance levels.
Standard formula: p = (h + l + c) / 3 Support/Resistance levels derived from pivot and high-low range.
- once(start, end)[源代码]¶
Calculate pivot point levels in runonce mode.
Computes pivot, support, and resistance levels across all bars.
- frompackages = ()¶
- packages = ()¶
- class backtrader.indicators.pivotpoint.FibonacciPivotPoint[源代码]¶
基类:
IndicatorDefines a level of significance by taking into account the average of price bar components of the past period of a larger timeframe. For example, when operating with days, the values are taking from the already "past" month fixed prices.
Fibonacci levels (configurable) are used to define the support/resistance levels
Example of using this indicator:
data = btfeeds.ADataFeed(dataname=x, timeframe=bt.TimeFrame.Days) cerebro.adddata(data) cerebro.resampledata(data, timeframe=bt.TimeFrame.Months)
In the
__init__method of the strategy:pivotindicator = btind.FibonacciPivotPoiont(self.data1) # the resampled data
The indicator will try to automatically plo to the non-resampled data. To disable this behavior, use the following during construction:
_autoplot=False
备注
The example shows days and months, but any combination of timeframes can be used. See the literature for recommended combinations
- Formula:
pivot = (h + l + c) / 3 # variants duplicate close or add open
support1 = p - level1 * (high - low) # level1 0.382
support2 = p - level2 * (high - low) # level2 0.618
support3 = p - level3 * (high - low) # level3 1.000
resistance1 = p + level1 * (high - low) # level1 0.382
resistance2 = p + level2 * (high - low) # level2 0.618
resistance3 = p + level3 * (high - low) # level3 1.000
- See:
- plotinfo = <backtrader.metabase.plotinfo_obj object>¶
- __init__(*args, **kwargs)¶
- next()[源代码]¶
Calculate Fibonacci pivot point and support/resistance levels.
Uses Fibonacci ratios (0.382, 0.618, 1.0) to calculate support/resistance levels from pivot point.
- once(start, end)[源代码]¶
Calculate Fibonacci pivot point levels in runonce mode.
Computes pivot and Fibonacci-based support/resistance levels across all bars.
- frompackages = ()¶
- packages = ()¶
- class backtrader.indicators.pivotpoint.DemarkPivotPoint[源代码]¶
基类:
IndicatorDefines a level of significance by taking into account the average of price bar components of the past period of a larger timeframe. For example, when operating with days, the values are taking from the already "past" month fixed prices.
Example of using this indicator:
data = btfeeds.ADataFeed(dataname=x, timeframe=bt.TimeFrame.Days) cerebro.adddata(data) cerebro.resampledata(data, timeframe=bt.TimeFrame.Months)
In the
__init__method of the strategy:pivotindicator = btind.DemarkPivotPoiont(self.data1) # the resampled data
The indicator will try to automatically plo to the non-resampled data. To disable this behavior, use the following during construction:
_autoplot=False
备注
The example shows days and months, but any combination of timeframes can be used. See the literature for recommended combinations
- Formula:
if close < open x = high + (2 x low) + close
If close > open x = (2 x high) + low + close
If Close == open x = high + low + (2 x close)
P = x / 4
Support1 = x / 2 - high
resistance1 = x / 2 - low
- See:
- plotinfo = <backtrader.metabase.plotinfo_obj object>¶
- __init__(*args, **kwargs)¶
- next()[源代码]¶
Calculate Demark pivot point and support/resistance levels.
Demark formula uses relationship between open and close to determine the calculation method.
- once(start, end)[源代码]¶
Calculate Demark pivot point levels in runonce mode.
Computes Demark-style pivot, support, and resistance levels across all bars.
- frompackages = ()¶
- packages = ()¶