backtrader is a python backtesting library for trading strategies
Questions tagged [backtrader]
107 questions
1
vote
1 answer
AttributeError: 'NoneType' object has no attribute '_id'
I'm trying to make a trading bot and am using backtrader for the same. I have been trying to debug this issue but couldn't find a solution yet. The code is as shown below
# from ast import Constant
from operator import imod
import os, sys
import…

Divyam Bansal
- 153
- 11
1
vote
1 answer
long and short strategy with macd indicator in Backtrader
I just switched from Matlab to python and even newer to the backtrader library for backtestingtrading strategies. My questions might seem obvious.
My problem seems similar to this…

AMT456
- 13
- 5
1
vote
1 answer
backtrader: custom columns as indicator
import backtrader.feeds as btfeeds
class PandasDataSource(bt.feeds.PandasData):
lines = ('Strategy_GoldenCross_Signal',)
params=(
('Strategy_GoldenCross_Signal', -1),
('Strategy_MACDDiff', -1),
…

ZKK
- 627
- 1
- 10
- 16
1
vote
1 answer
Backtrader fail to show plot graph
I am new to coding, trying to use backtrader to do a simple backtesting process. I was able to execute the buy and sell, but when i am trying to plot the graph it shows:
AttributeError: type object 'Gcf' has no attribute '_set_new_active_manager'
My…

Adrian Wong
- 23
- 3
1
vote
1 answer
How I display the graph that return by backtrader in streamlit?
I try to do back testing on stock data using backtrading library in python. and I use this simple strategy
class CrossOver(bt.SignalStrategy):
def __init__(self):
sma=bt.ind.SMA(period=50)
price=self.data
…

Navin Seab
- 83
- 1
- 8
1
vote
0 answers
backtrader `next()` not called for hourly data
As an alternative to the very first example in backtrader's documentation, I tried to pass the hourly data of ETHUSDT, but nothing was shown in the output after cerebro.run().
I found that next() in the strategy class is not called at all, which is…

Zen
- 11
- 1
1
vote
1 answer
Backtrader / Python ValueError: year x is out of range
I'm trying to import some data from a .csv file into backtrader but hitting the error ValueError: year x is out of range.
Here is a line from the csv that I'm looking to…

Swashbuckler75
- 21
- 1
- 3
1
vote
1 answer
SQL Query for Calculating Trade Profits
Trying to build a SQL script to calculate profit/loss percent per trade
Below is the original table
SELECT id, exchange, ticker, signal, time, price
from trade_data
ORDER BY exchange, ticker,…

Shahrukh Khan
- 316
- 1
- 3
- 15
1
vote
0 answers
Backtrader Import error [ImportError: cannot import name 'warnings' from 'matplotlib.dates']
Seems to be an import error with matplotlib. This error started popping up once I fixed a data feed issue stemming from Yahoo Finance. I had to make a small modification to the source code, specifically the Yahoo.py file, but I do not believe that…

Andrei Larion
- 221
- 1
- 2
- 4
1
vote
3 answers
AttributeError: 'int' object has no attribute 'to_pydatetime'
I am not able to understand the error - AttributeError: 'int' object has no attribute 'to_pydatetime', I will be really grateful, if anyone could please help me out in this?
from datetime import date, datetime
import pandas as pd
import backtrader…

r_goel
- 43
- 1
- 6
1
vote
0 answers
Backtrader TradeAnalyzer empty - other analyzers work
I am trying to run a backtest with backtrader. When I try to print out the result from TradeAnalyzer, I only get this:
===============================================================================
TradeAnalyzer:
…

Mark
- 53
- 1
- 1
- 8
1
vote
1 answer
backtrader how to use analyzer to access data?
I am very new to this.
backtrader have a addwriter can write down some data,
cerebro.addwriter(bt.WriterFile, csv=True, out='outputfiles3\{}cerebro.csv'.format(ticker))
but buy and sell price always not match to the execute price.
so…

DMG
- 27
- 1
- 7
1
vote
1 answer
cerebro pandas dataframe load and run
Dataframe (df) looks like:
Open High Low Close VWAP Volume
Date
1996-01-01 83.0 83.00 83.0 83.0 83.00 100
1996-01-02 83.0 83.95 80.6 80.6 82.79 700
1996-01-03 …

Dr.PB
- 959
- 1
- 13
- 34
1
vote
1 answer
How to check fed data in backtrader?
import backtrader as bt
cerebro = bt.Cerebro()
data = bt.feeds.GenericCSVData(
dataname='data.csv',
# Do not pass values before this date
fromdate=dt.datetime(2000, 1, 1),
# Do not pass values after this date
…

Dr.PB
- 959
- 1
- 13
- 34
1
vote
1 answer
backtrader loop functions with class
There is a pickle file that has many (say 10) stocks names
and also have a folder that has all stock data
I am trying to run the code to do the MACD analysis and hope can write down the result buy and sell time, price, position, cash on hand.
when I…

DMG
- 27
- 1
- 7