backtrader is a python backtesting library for trading strategies
Questions tagged [backtrader]
107 questions
0
votes
1 answer
Backtrader: AttributeError: 'RRuleLocator' object has no attribute 'set_view_interval'
I'm running Backtrader for the first time and am having this issue when running cerebro.plot():
---------------------------------------------------------------------------
AttributeError Traceback (most recent call…
0
votes
0 answers
How to add new columns to BackTrader?
I'm trying to add all columns of a pandas dataframe into backtrader Cerebro. Without putting Cerebro into a class, everything was fine. I'm getting error when putting Cerebro into a class. Because Cerebro cannot pick class inside init, I put…

StaEx_G
- 1
- 3
0
votes
0 answers
Backtrader + Interactive Brokers with external data source
I have a question related to trading live with Interactive Brokers using Backtrader. Is it mandatory to use the IB Data Feeds for trading on IB in Backtrader?
Or is it possible to just get the data from another source (DB, CSV etc.), and based on…

Tamas Holics
- 21
- 2
0
votes
1 answer
Unable to call notify_timer in backtrader
I am new to backtrader and I am trying to design strategies that involve a timer that triggers an action.
Specifically, I am trying to take the action on the first day of each month.
class MyStrategy(bt.Strategy):
def __init__(self):
…

dnn-6
- 1
- 1
0
votes
0 answers
Backtrader params optimization alternatives in python
I'm trying to optimize the followiong strategy in Backtrader:
class MyStrategy(bt.Strategy):
params = (('LONG_ENTRY', 'pattern_L1'),
('SHORT_ENTRY', 'pattern_S1'),
('LONG_EXIT', 'pattern_S3'),
('SHORT_EXIT',…

mattia mosolo
- 13
- 5
0
votes
0 answers
Problem with datetime when backtesting with backtrader library
I've been trying to backtest a strategy using backtrader and need some help using the correct format for datetimes used by the variable cerebro of backtrader.
This snippet is an example of my problem:
timestamps = [price[0] / 1000 for price in…

hologormonong
- 1
- 2
0
votes
0 answers
How do I add a daterange to open trades during when backtesting with backtrader?
I am trying to backtest a strategy where trades are only opened during 8.30 to 16.00 using backtrader.
Using the below attempt my code is running but returning no trades so my clsoing balane is the same as the opening. If I remove this filter my…
0
votes
0 answers
Backtrader: How can I have stops execute on the same bar they were entered on?
I'm confused about the behavior of stop orders. Consider the example below, in which the stop price is reached on the same bar on which the order is entered. However, the stop is not executed.
In this example, both the buy and the stop orders are…

arosca
- 469
- 7
- 15
0
votes
1 answer
File not found/Invalid Argument
Although my folder is in the correct path, the function can't find it.
I am relatively new to programming, maybe some obvious mistakes?
import backtrader as bt
cerebro = bt.Cerebro()
data = bt.feeds.GenericCSVData(dataname=r'D:\Programme\Visual…

theJavaNoob
- 13
- 4
0
votes
0 answers
Options Trading Back-testing Strategy Issue
I have been getting the following error message:
IndexError Traceback (most recent call last)
Cell In [29], line 12
8 for index, row in df.iterrows():
9 # if the 50-day moving average is above the…

tradingwithme
- 1
- 1
0
votes
1 answer
How to add multiple timeframes in CCXTStore? [Python, backtrader]
I'm trying to use the CCXTStore library to create a backtrader Strategy that uses multiple timeframes (1h and 5m). For that I need to figure out how to add additional datafeeds into Cerebro.
With CSV data it is easy, I can simply create two data…

rongard
- 89
- 7
0
votes
2 answers
Can't get object from pandas dataframe
I have a pandas dataframe, one of the columns has an object type, like this:
`
trade_data['history'].to_string()
out:
1 [{'status': {'status': 1, 'dt': 738415.125, 'b...
2 [{'status': {'status': 1, 'dt': 738416.8333333...
3 [{'status':…

LiverLove
- 13
- 4
0
votes
0 answers
Does backtrader or backtesting.py work with mapreduce and/or mrjob?
Would it be possible to backtest using either backtesting.py or backtrader doing mapreduce with the mrjob library or another?
Unsure if backtrader or backtesting.py works with mapreduce/mrjob or if we will have to write some extra code to use…

Andy
- 1
0
votes
0 answers
Python, Backtrader : Sell one stock and buy another for the cash from the sell
A strategy where a simple Moving Average crossing of SPX (data0) on the close of one day makes a trade on the open next day: Crossing upward: 1) sell order of TQQQ (data1) and 2) a buy order of SQQQ (data2) (with the cash from sell included.) And…

Mjoey
- 1
0
votes
0 answers
how efficient to compare multi Indicator to get max one
self.one_pct = bt.indicators.RateOfChange(self.datas[0].close, period=1)
self.two_pct = bt.indicators.RateOfChange(self.datas[1].close, period=1)
self.three_pct = bt.indicators.RateOfChange(self.datas[2].close, period=1)
.....
self.n_pct =…

ChandlerSong
- 387
- 1
- 14