backtrader is a python backtesting library for trading strategies
Questions tagged [backtrader]
107 questions
48
votes
12 answers
ImportError Cannot import name 'warnings' from 'matplotlib.dates
Alpaca backtrader plot issue: I ran into this import issue and found this article, so I applied the code, but same issue not resolved. any one can help please?
My installed matplotlib version is 3.3.1
backtrader 1.9.76.123
python 3.8.5
the entire…

G Chu
- 481
- 1
- 4
- 5
5
votes
2 answers
Progress bar (using tqdm) prints in a new line everytime the update is called on the tqdm object (VSCode terminal)
I am trying to print the status of the progress of an optimization algorithm using the tqdm module available in Python, however, every time I try to update it, it prints the progress in a new line, is there a way I could only update the original…

yash
- 331
- 1
- 3
- 12
4
votes
2 answers
Backtrader error: 'DataFrame' object has no attribute 'setenvironment'
I am new to backtrader, and I have a big problem. I want to start my strategy (just a simple GoldenCross strategy). This GoldenCross.py Script looks like this:
import math
import backtrader as bt
class GoldenCross(bt.Strategy):
params =…

chrissi2909
- 51
- 2
- 6
3
votes
0 answers
Matplotlib plot no output jupyter-lab
I know I am beating a dead horse here, but I simply can't get the matplotlib plot to display in a Jupyterlab notebook.
I am trying to run a python script that eventually plots inside a jupyter cell.
Things I have tried:
The best success that I had…

LeggoMaEggo
- 512
- 1
- 9
- 24
3
votes
3 answers
Getting data in Backtrader issue
I am trying to write a backtesting strategy on Backtrader in Python, and below is the code that is giving me the error. I am using the latest version of backtrader as of July 2, 2021.
import backtrader as bt
import backtrader.feeds as btfeeds
from…

Rishab
- 143
- 2
- 8
3
votes
0 answers
I have a issue at Backtrader Lib
I am interested in backtesting for my strategy by backtrader but I have a problem in the beginning.
Here is my code:
import backtrader as bt
cerebro = bt.Cerebro()
data = bt.feeds.GenericCSVData(dataname='BTCUSDT_15min.csv', dtformat =…

Ulaş Yılmaz
- 31
- 3
2
votes
3 answers
How to created pandasData for backtrader with ccxt
I am trying to back test a strategy using backtrader. Most of the examples I have seen only are using a csv file. I was wondering if it is possible to just get data from an exchange and turn it into pandas dataframe and then use backtrader? When I…

Sarah James
- 431
- 5
- 19
2
votes
3 answers
Python dynamic function parameters
When calling the function below, I can provide values that will be used instead of the default parameters in the function (see below).
cerebro.addstrategy(GoldenCross, fast=10, slow=25)
This works great for a small number of known parameters, but I…

Deemo
- 131
- 1
- 1
- 10
2
votes
2 answers
backtrader printing data feed vaues does not print hours and minues and defaults to
I'm learning to use backtrader and I've come across a problem when trying to print out the datafeed. It correctly prints the day, open, high, low, close and volume but the hour and minutes data seems to default to 23:59:59.999989 on every line.
Here…

tew
- 261
- 4
- 13
2
votes
1 answer
backtrader time column : ValueError: time data '0' does not match format '%Y-%m-%d %H:%M:%S'
I have a price table that has date and time in a csv format:
Date Time o h l c v
0 2020-07-09 15:10:00 8 8 7.5 7.94 41
1 2020-07-09 15:00:00 7.61 8.24 7.61 8.24 10
2 2020-07-09 …

BangolPhoenix
- 383
- 1
- 4
- 16
1
vote
0 answers
Backtrader, using mongodb as datafeed instead CSV
I'm quite new to backtrader and since I've started I couldn't stop wondering why there's no database support for the datafeed. I've found a page on the official website where's described how to implement a custom datafeed. The implementation should…

Paolo Ardissone
- 837
- 1
- 6
- 15
1
vote
0 answers
Backtrader : convert python code into backtrader custom indicator
I am trying to convert the snippet from https://medium.datadriveninvestor.com/how-to-detect-support-resistance-levels-and-breakout-using-python-f8b5dac42f21 into backtrader custom indicator. However, I encounter error AttributeError:…

bkcollection
- 913
- 1
- 12
- 35
1
vote
1 answer
Can you add parameters to backtrader strategy?
I am using the backtrader library.
class MA_CrossOver(bt.Strategy):
alias = ('SMA_CrossOver',)
params = (
# period for the fast Moving Average
('fast', 10),
# period for the slow moving average
('slow',…

Borut Flis
- 15,715
- 30
- 92
- 119
1
vote
1 answer
IndexError: list index out of range backtrader
Sorry for the noob question!
I have a CSV that looks like:
date,volume,open,close,high,low
2020-11-12 13:38:00,100,1.85,1.85,1.85,1.85
2020-11-12 13:58:00,100,1.85,1.85,1.85,1.85
2020-11-12 14:03:00,100,1.85,1.85,1.85,1.85
...
And I'm trying to use…

a7dc
- 3,323
- 7
- 32
- 50
1
vote
0 answers
Is there an easy way to overwrite Backtrader IB broker live data feed?
I am working on Backtrader using IB Broker, And i need to overwrite data reciever function so instead of using Backtrader ibstore to get live data, It use my own data service (its just a simple socket connection that returns IB data for…

SMB H
- 121
- 6