backtrader is a python backtesting library for trading strategies
Questions tagged [backtrader]
107 questions
0
votes
1 answer
Buy/Sell plot markers are in wrong location
My code is attached below, with example output. I am trying to plot the trades of my strategy, but they are displaying weird in the output. The buy/sell markers are sometimes not on the curve, just floating in space. This makes me think that my data…

Deemo
- 131
- 1
- 1
- 10
0
votes
1 answer
how to get a price that the order was submitted backtester python
Here is my code
class TestStrategy(bt.Strategy):
params = dict(
stop_loss=0.02, # price is 2% less than the entry point
trail=False,
)
def log(self, txt, dt=None):
''' Logging function fot this strategy'''
…

YanRemes
- 347
- 2
- 10
0
votes
1 answer
import custom multitimeframe data into backtrader
I need to import several timeframes into a single trading strategy and I am unsure how to proceed.
Here is my data:
df['M1'].tail(3)
volume complete o h l c
time …

user1601716
- 1,893
- 4
- 24
- 53
0
votes
1 answer
How to resolve datafeeds error for backtesting using Backtrader and Python with local csv file?
I am trying to build code for backtesting crypto strategy using backtrader and python but getting errors every time i try to connect data feeds, I tried different data feed methods and tried many other ways to connect but getting some or other kind…

Max Kat
- 1
0
votes
1 answer
Easiest way to open an HTML file and save it as a string variable
I am working with a file in python and trying to save it to a string variable, so I can then pass it into an html file with Flask.
Here is the process:
Run backtest and it saves the results as an HTML file.
Take the the HTML file and set it to a…

Will Powers
- 51
- 9
0
votes
1 answer
Cerebro.run() on backtrader doesn't output anything?
I am trying to run an example strategy on Backtrader however, I am not receiving an error code but simply no output except
[]
Can anybody help me please? Thanks a lot.
The code:
import backtrader as bt
from datetime…

Jimmy Hou
- 1
- 2
0
votes
1 answer
Backtrader 'File Not Found Error [ERRNO 2]'. Error with sample code from Backtrader Github page
I ran across this error when trying to run the backtrader sample setup code found on github. After doing some research I found that the error probably stems from the Yahoo Finance API being out of date or no longer compatible with the backtrader…

Andrei Larion
- 221
- 1
- 2
- 4
0
votes
2 answers
How To Handle date format in GenericCSVData in Backtrade
I was trying a simple example that prints datetime and close price from my csv.
It's printing date correctly but for the time it's printing 23:59:59 only.
Can you please help me to check what am I doing wrong?
Here is my code:
import datetime
import…

Raj Thakur
- 323
- 1
- 3
- 12
0
votes
1 answer
problem, backtesting with backtrader and btalib, It's not action as i tried, want to action as order buy if sma5>sma10 and sell when sma5
from btalib.indicators import sma
import pandas as pd
import backtrader as bt
import os.path #To manage paths
import sys # to find out the script name
import datetime
import matplotlib as plt
from backtrader import cerebro
from numpy import mod…
0
votes
0 answers
Kite ticker feed for backtrader
I am using backtrader for testing my strategy but my broker i.e kite api is not directly supported by backtrader. I want to either use a dynamic CSV or use kite websocket/ticker with backtrader for live trading

user2765457
- 11
0
votes
1 answer
Pinecsript to Python conversion
i'm trying to convert this strategy from pinescript to python but im getting enormous output value when i backtest it, someone can find if there's something wrong? thank tou
class WaveTrendStrategy(bt.Strategy):
def __init__(self) :
…
0
votes
1 answer
How to look for S&P 500 Constituents history, added and removed dates etc
I am trying to get a historical list of the S&P500 underlying stocks mix. all tickers the dates were added to the S&P500 index mix and the dates tickers were removed from the list. and throughout the years for each period what is the mix. I did…

DMG
- 27
- 1
- 7
0
votes
1 answer
Running backtest on backtrader I get many BUY ORDERS CANCELLED/MARGIN/REJECTED when they should not
Many buy orders are cancelled in the backtests and I cannot find why. Looking at the Writefile log it seems the buy orders are created at the next day's close. In most cases the buy price is in the day's range but still not executed.
I have tried…

Miguel_D
- 11
- 2
0
votes
1 answer
Backtrader - trades not lining up on .plot
I am trying to learn backtrader, but when using my own data (1 min. charts), I am having this issue, where the trades are not lining up with the graph.
Don't mind the many trades, there is not set a proper strategy at the moment as I am just…

RavenMan
- 73
- 1
- 8
0
votes
0 answers
AttributeError: 'Lines_LineSeries_LineIterator_DataAccessor_Strateg' object has no attribute 'analyers'
I've searched for this question on the internet and I didn't find any suitable answers, so I'm posting this question. My code is in this link.
Error:
AttributeError: 'Lines_LineSeries_LineIterator_DataAccessor_Strateg' object has no attribute…

jinna
- 43
- 9