117 questions
0
votes
0
answers
112
views
Could not retrieve data fram without index thus resulting in value error
I have this below code that calculates DEMA [Double Exponential Moving Average] based on the close price
import backtrader as bt
import pandas as pd
class CalculateDema:
def __init__(self, data, ...
0
votes
1
answer
228
views
how to set initial position for backtrader?
before I start backtesting, may I hold some stock share?
As I can set cash at the begining, can I set a stock share like this?
cerebro.broker.set_position(size=10, price=100)
2
votes
0
answers
205
views
How to add new data and run again after running in Backtrader?
How to add new data and run again after running in Backtrader?
cerebro = bt.Cerebro()
df = pd.read_csv('data.csv')
data = bt.feeds.PandasData(
dataname=df
)
cerebro....
2
votes
0
answers
207
views
Backtrader - multiple time series with different lengths
I have historical stock data from Norgate that I'd like to use with Backtrader. Of course, the stocks that I'd like to use all have different start and end dates that they've been listed. When I try ...
1
vote
0
answers
98
views
Sellstop order not executing if a buy trade is already open
I have run two tests which clearly explain the scenario. Please see code block below of notify_order and notify_trade.
**Test 1 (execute only 1 sellstop order):
**
When I solely execute a sellstop ...
0
votes
1
answer
192
views
Difference between the calculation results of the BackTrader indicators EMA and Pandas.DataFrame.EWM
I found a problem when using the backtrader EMA indicator to calculate the values. The larger the period value input( ex. 120days ), the greater the difference between the value of the EMA displayed ...
2
votes
0
answers
265
views
Backtrader - stop and profit orders not executing if passing buy order as parent
i am placing a buy order in my next() method of strategy and in notify order after checking if it is completed i am placing two orders (profit and loss)
def notify_order(self, order):
"&...
-1
votes
1
answer
865
views
How can I use my own strategy to test by backtrader?
I try to backtest my strategy of trading that is named "AI reversal". Light-weight implementation is available in strategies and I checked the document of backtrader to be right. But ...
0
votes
1
answer
444
views
Backtrader plotting returns NaN or Inf error
I m starting out with backtrader. I can load data into the object but plotting fails with a strange error message.
I can create an object with sample data, like so:
import pandas as pd
import numpy as ...
0
votes
2
answers
2k
views
Backtrader throws attribute error on the data i have given
The Data I am using is throwing a Attribute Error:
[*********************100%***********************] 1 of 1 completed
Traceback (most recent call last):
File "C:\Users\Navid\AppData\Roaming\...
0
votes
1
answer
1k
views
Backtrader not plotting
I am trying to get a plot to show with some test code in VSC.
I have version 3.2.2 of Matplotlib installed, as that is stated in Backtrader's documentation to be the compatible version. I am running ...
0
votes
4
answers
418
views
Python Backtrader RSI ZeroDivisionError: float division by zero
import backtrader as bt
import pandas as pd
# Load data
file_path = r'C:\forex\python\data\EURUSD1min-v2.xlsx'
data = pd.read_excel(file_path)
# Handle date and time in separate columns
data['...
0
votes
1
answer
146
views
Access the main plot axis in backtrader
I wand to add custom plot elements e.g. a box between buy and sell trades. The axis ax is normally created like this: fig, ax = plt.subplots()
How can I access it in Backtester's plot?
ax =...
0
votes
1
answer
360
views
Can backtrader plot only with close price?
I can plot with the test data (2005-2006-day-001.txt) when read all columns.
My code is as follows:
import backtrader as bt
class St(bt.Strategy):
def __init__(self):
self.sma = bt....
0
votes
0
answers
78
views
Why should not call super(ClassName, self).__init__() in derived class‘s construction function?
I've noticed that every example and doc and reference about backtrader never calls super(ClassName, self).__init__() in derived class, which is different from common use. For example, when I want to ...