backtrader.utils.fractal module

Fractal Indicator Module - Fractal pattern detection.

This module provides the Fractal indicator for identifying fractal patterns in price data. Fractals are reversal patterns that indicate potential trend changes.

Classes:

Fractal: Identifies bullish and bearish fractal patterns.

示例

>>> from backtrader.utils.fractal import Fractal
>>> class MyStrategy(bt.Strategy):
...     def __init__(self):
...         self.fractal = Fractal(self.data)
...     def next(self):
...         if self.fractal.fractal_bullish[0] > 0:
...             self.buy()
class backtrader.utils.fractal.Fractal[源代码]

基类:PeriodN

Fractal pattern indicator.

Identifies bullish and bearish fractal patterns which indicate potential reversal points in price trends.

A bearish fractal occurs when there's a pattern with the highest high in the middle and two lower highs on each side.

A bullish fractal occurs when there's a pattern with the lowest low in the middle and two higher lows on each side.

Params:

period: Number of bars to check (default: 5). bardist: Distance to max/min in percentage (default: 0.015). shift_to_potential_fractal: Index of potential fractal (default: 2).

Lines:

fractal_bearish: Bearish fractal levels. fractal_bullish: Bullish fractal levels.

plotinfo = <backtrader.metabase.plotinfo_obj object>
plotlines = <backtrader.metabase.plotlines_obj object>
next()[源代码]

Calculate fractal patterns for the current bar.

Identifies bearish fractals (highest high in middle with two lower highs on sides) and bullish fractals (lowest low in middle with two higher lows on sides).

frompackages = ()
once(start, end)

Implement once using next for batch calculation.

This is used when next is overridden but once is not. It loops through the range and calls next for each step.

参数:
  • start -- Starting index

  • end -- Ending index

oncestart(start, end)

Implement oncestart using nextstart for batch calculation.

This is used when nextstart is overridden but oncestart is not.

参数:
  • start -- Starting index

  • end -- Ending index

packages = ()
preonce(start, end)

Implement preonce using prenext for batch calculation.

This is a generic implementation if prenext is overridden but preonce is not. It loops through the range and calls prenext for each step.

参数:
  • start -- Starting index

  • end -- Ending index