backtrader.filters.renko module

Renko Filter Module - Renko chart bars.

This module provides the Renko filter for converting price data into Renko bricks for charting.

Classes:

Renko: Creates Renko bars from price data.

Example

>>> data = bt.feeds.GenericCSVData(dataname='data.csv')
>>> data.addfilter(bt.filters.Renko(size=10))
>>> cerebro.adddata(data)
class backtrader.filters.renko.Renko[source]

Bases: Filter

Modify the data stream to draw Renko bars (or bricks)

Params:

  • hilo (default: False) Use high and low instead of close to decide if a new brick is needed

  • size (default: None) The size to consider for each brick

  • autosize (default: 20.0) If size is None, this will be used to autocalculate the size of the bricks (simply dividing the current price by the given value)

  • dynamic (default: False) If True and using autosize, the size of the bricks will be recalculated when moving to a new brick. This

    will, of course, eliminate the perfect alignment of Renko bricks.

  • align (default: 1.0) Factor used to align the price boundaries of the bricks. If the price is for example 3563.25 and align is 10.0, the resulting aligned price will be 3560. The calculation:

    • 3563.25 / 10.0 = 356.325

    • round it and remove the decimals -> 356

    • 356 * 10.0 -> 3560

  • roundstart (default: True) If True, round the initial start value to int. Else keep the original value, which should aid when backtesting penny stocks

See:
params = (('hilo', False), ('size', None), ('autosize', 20.0), ('dynamic', False), ('align', 1.0), ('roundstart', True))
__init__(data, *args, **kwargs)[source]

Initialize the Renko filter.

Parameters:
  • data – The data feed to apply the filter to.

  • *args – Variable length argument list.

  • **kwargs – Additional keyword arguments passed to parent class.

nextstart(data)[source]

Initialize Renko brick boundaries on the first data point.

This method sets up the initial brick size and top/bottom boundaries based on the opening price and configured parameters.

Parameters:

data – The data feed containing the first bar.

next(data)[source]

Process each bar to create Renko bricks.

This method analyzes the current price data and creates Renko bricks when price moves beyond the current brick boundaries. Each brick has a fixed size, and new bricks are created when price breaks through the current brick’s top or bottom boundary.

Parameters:

data – The data feed containing current bar data.

Returns:

True if the stream length changed (bar removed),

False if unchanged (Renko brick created).

Return type:

bool