I love backtrader but I'm not playing on futures. I know that TradeStation is perfect for it. I imagine I will move to futures soon. But I'm curious since TS is apparently so good, what are the advantages of backtrader that you want to use it instead of TS?
Latest posts made by MrKalindro
-
RE: Backtrader
-
RE: Array index out of range for lower period params
I made it work. I had to delete enough rows so the 1h dataframe that the data is taken from starts on any day but at 23:00:00. I still don't know why it matters and how. I guess it's coding in a nutshell (fixing the error I don't know why exists by guessing). I can only guess, maybe data resampling from 1 hour to 1 day only occurs when there is a full day available (from 00:00 to 24:00)? And when the data stated on for ex. 2:00, there were 22 1h candles that envelope wanted to plot on (with a lower period than 22 it could), where ATR couldn't even start as there was no 1D candle. And when it starts at 23:00 both can start plotting on next candle. If someone knows what is/was the issue I'm happy to listen, hope it won't show again at some point.
-
RE: Array index out of range for lower period params
When I drop a few rows it works with a particular period. To be exact, when I drop 12 rows (12 hours of data), I'm able to use 10-period envelope (for 9 period it crashes). When I drop 13 rows, I can use 9 (and it goes to 21 rows for period 1). When I delete more than 21 it crashes again for numbers it didn't crash before removing that much. I can see that it's connected to those periods and the amount of it or something but I'm going insane a bit as I can't wrap my head around what's the exact problem.
-
RE: Array index out of range for lower period params
I noticed that if I drop 5 first rows of the dataframe the datas use (data_1d is resampled data_1h so they are born from the same dataframe) it happens on different datasets. I guess it's some issue with coupling? Or it's maybe when the backtest start's in the middle of the week or something? So it makes me think even more I have to trim the data somehow to make it work.
-
RE: Date Axis does not show up on plot
Afaik it's matplotlib issue, there are many of them with the newest version. I recommend downgrading to lower version (3.0.3 works perfectly for me).
-
Array index out of range for lower period params
Hello! So I coded a bit with backtrader, my backtests works just as intended to a point. When I change the period of Envelope to 16 and below (I swear some tweaks ago it was 22 and below...) I get an error:
Traceback (most recent call last): File "F:/xxx/Showoff.py", line 102, in <module> Cerebro.run() File "F:\xxx\venv\lib\site-packages\backtrader\cerebro.py", line 1127, in run runstrat = self.runstrategies(iterstrat) File "F:\xxx\venv\lib\site-packages\backtrader\cerebro.py", line 1298, in runstrategies self._runnext(runstrats) File "F:\xxx\venv\lib\site-packages\backtrader\cerebro.py", line 1630, in _runnext strat._next() File "F:\xxx\venv\lib\site-packages\backtrader\strategy.py", line 347, in _next super(Strategy, self)._next() File "F:\xxx\venv\lib\site-packages\backtrader\lineiterator.py", line 263, in _next indicator._next() File "F:\xxx\venv\lib\site-packages\backtrader\lineiterator.py", line 263, in _next indicator._next() File "F:\xxx\venv\lib\site-packages\backtrader\linebuffer.py", line 621, in _next self.nextstart() File "F:\xxx\venv\lib\site-packages\backtrader\lineroot.py", line 144, in nextstart self.next() File "F:\xxx\venv\lib\site-packages\backtrader\linebuffer.py", line 744, in next self[0] = self.operation(self.a[0], self.b[0]) File "F:\xxx\venv\lib\site-packages\backtrader\linebuffer.py", line 163, in __getitem__ return self.array[self.idx + ago] IndexError: array index out of range Process finished with exit code 1
The problem is it only works on some datasets, for some it works with any period.
The probe of the code that works standalone and causes the error is:
class ATRP(bt.indicators.AverageTrueRange): def next(self): self.lines.atr[0] = (self.lines.atr[0] / self.data[0]) * 100 class MovingAverageSimpleEnvelope(bt.indicators.MovingAverageSimpleEnvelope): params = (("period", 10),) class Envelope_strategy(bt.Strategy): def __init__(self): self.ATRP = ATRP(data_1d) self.perc = self.ATRP / 2 self.Envelope = MovingAverageSimpleEnvelope(data_1h, perc = self.perc)
I think I understand what is the problem, it's because I set Envelope perc as the ATRP I created. When it's set as a fixed int it works perfectly. So my small brain thinks that with a lower period the Envelope tries to plots sooner, before the ATRP gives data (and it requires the data from it) and it causes the error. I'm not sure how could I fix if that's the problem, make the Envelope wait a bit? (But I think it's implemented in Cerbero to some extent). Or remove some rows from Envelope data so it's equal? Thanks for help!
-
RE: Envelope indicators are not available, can't pass params
Yeah thanks @ab_trader it's Pycharm or other big IDE's thing. It's just notification errors, the script runs smoothly but the autofill doesn't work with many commands. Just gotta know that it's a thing and not worry about ugly prompts.
-
RE: Envelope indicators are not available, can't pass params
I just found some topic about pycharm with backtrader.
"Developing Coder 1 Jun 2019, 18:11
Wouldn't recommend PyCharm although I use it myself.BackTrader is a bag of tricks with a hack on top and PyCharm's tools don't play well with that. Half of your code will be highlighted as problematic, autocomplete rarely works and you can't ask which parameters a function takes.
If I wasn't so used to PyCharm, I'd probably go with Sublime Text."
Does it mean I'm not retarded and I spent the last few days trying to figure it out where it's not my issue actually?
-
Envelope indicators are not available, can't pass params
Hello guys! I'm still quite a noob but I have some issues with backtrader, I already inspected some posts and I can see people easily using for example
emamean = bt.indicators.AdaptiveMovingAverageEnvelope(period=30, fast=1, slow=8, perc=0.2, plotname='mean')
When I try to pass that it says "Cannot find reference AdaptiveMovingAverageEnvelope in init.py"
Even when I try to pass arguments to
sma1, sma2 = bt.indicators.MovingAverageSimple(period=10), bt.ind.SMA(period=30)
It says that the period is an unexpected argument.
I have my whole backtesting environment ready but the indicator that I struggle with, I have data upload and the rest figured out. I have python 3.7.9 and the newest backtrader version on Pycharm 2020.2