Filters Reference
SessionFilter
class backtrader.filters.SessionFilter(data)
This class can be applied to a data source as a filter and will filter outintraday bars which fall outside of the regular session times (ie: pre/postmarket data)
This is a “non-simple” filter and must manage the stack of the data (passedduring init andcall)
It needs no “last” method because it has nothing to deliver
SessionFilterSimple
class backtrader.filters.SessionFilterSimple(data)
This class can be applied to a data source as a filter and will filter outintraday bars which fall outside of the regular session times (ie: pre/postmarket data)
This is a “simple” filter and must NOT manage the stack of the data (passedduring init andcall)
It needs no “last” method because it has nothing to deliver
Bar Management will be done by the SimpleFilterWrapper class made which isadded durint the DataBase.addfilter_simple call
SessionFilller
class backtrader.filters.SessionFiller(data)
Bar Filler for a Data Source inside the declared session start/end times.
The fill bars are constructed using the declared Data Sourcetimeframeandcompression (used to calculate the intervening missing times)
Params:
fill_price (def: None):
If None is passed, the closing price of the previous bar will beused. To end up with a bar which for example takes time but it is notdisplayed in a plot … use float(‘Nan’)
fill_vol (def: float(‘NaN’)):
Value to use to fill the missing volume
fill_oi (def: float(‘NaN’)):
Value to use to fill the missing Open Interest
skip_first_fill (def: True):
Upon seeing the 1st valid bar do not fill from the sessionstart up tothat bar
CalendarDays
class backtrader.filters.CalendarDays(data)
Bar Filler to add missing calendar days to trading days
Params:
fill_price (def: None):
0: The given value to fill0 or None: Use the last known closing price-1: Use the midpoint of the last bar (High-Low average)
fill_vol (def: float(‘NaN’)):
Value to use to fill the missing volume
fill_oi (def: float(‘NaN’)):
Value to use to fill the missing Open Interest
BarReplayer_Open
class backtrader.filters.BarReplayer_Open(data)
This filters splits a bar in two parts:
Open: the opening price of the bar will be used to deliver an initial price bar in which the four components (OHLC) are equal
The volume/openinterest fields are 0 for this initial bar
OHLC: the original bar is delivered complete with the originalvolume/openinterest
The split simulates a replay without the need to use thereplay filter.
DaySplitter_Close
class backtrader.filters.DaySplitter_Close(data)
Splits a daily bar in two parts simulating 2 ticks which will be used toreplay the data:
First tick:OHLX
TheClose will be replaced by theaverage ofOpen,HighandLow
The session opening time is used for this tick
and
The volume will be split amongst the 2 ticks using the parameters:
closevol (default:0.5) The value indicate which percentage, in absolute terms from 0.0 to 1.0, has to be assigned to theclosing tick. The rest will be assigned to theOHLX tick.
This filter is meant to be used together withcerebro.replaydata
HeikinAshi
class backtrader.filters.HeikinAshi(data)
The filter remodels the open, high, low, close to make HeikinAshicandlesticks
See:
* [https://en.wikipedia.org/wiki/Candlestick_chart#Heikin_Ashi_candlesticks](https://en.wikipedia.org/wiki/Candlestick_chart#Heikin_Ashi_candlesticks)* [http://stockcharts.com/school/doku.php?id=chart_school:chart_analysis:heikin_ashi](http://stockcharts.com/school/doku.php?id=chart_school:chart_analysis:heikin_ashi)
Renko
class backtrader.filters.Renko(data)
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) Ifsize isNone, this will be used to autocalculate the size of the bricks (simply dividing the current price by the given value)
dynamic (default:False) IfTrue and usingautosize, 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 use to align the price boundaries of the bricks. If the price is for example3563.25 andalign is10.0, the resulting aligned price will be3560. The calculation:
See:
* [http://stockcharts.com/school/doku.php?id=chart_school:chart_analysis:renko](http://stockcharts.com/school/doku.php?id=chart_school:chart_analysis:renko)