backtrader.flt module

Filter Module - Data filtering for backtrader.

This module provides the base Filter class for data filtering operations. Filters can be applied to data feeds to modify or filter bars during backtesting.

Classes:

Filter: Base class for data filters.

Example

>>> class MyFilter(bt.Filter):
...     def next(self, data):
...         # Modify data bar
...         pass
class backtrader.flt.Filter[source]

Bases: ParameterizedBase

Base class for data filters in backtrader.

Filters process data bars and can modify or reject them. Subclasses should override the next() method to implement custom filtering logic.

_firsttime

Tracks if this is the first call.

This class has been refactored from MetaParams to the new ParameterizedBase system for Day 36-38 of the metaprogramming removal project.

__init__(data_, **kwargs)[source]

Initialize the Filter.

Parameters:
  • data – The data feed to filter.

  • **kwargs – Additional keyword arguments for parameters.

__call__(data)[source]

Process a data bar through the filter.

Parameters:

data – The data feed being filtered.

nextstart(data)[source]

Called on the first bar before filtering starts.

Parameters:

data – The data feed being filtered.

Note

Override this method to perform one-time initialization.

next(data)[source]

Process each data bar.

Parameters:

data – The data feed being filtered.

Note

Subclasses must override this method to implement filtering logic.