The most usual problem: you installed using pip but are running inside another environment like Spyder. You have to install it in your environment (the interpreter you use in the shell happens to be another installation)
thanks for your reply, I understand it now. From the log information, I see the buy order is submitted, accepted and completed on the next bar, So it cannot be cancelled. The system is designed wisely.
Many thanks for the detailed answer! I totally agree with most of the points you made. Though, I do think people also opt for Java and other strongly typed languages for other reasons than just ease of integration with legacy systems (stability, speed, better concurrency support, better inheritance support, etc.).
Out of curiosity, how do you see the emergence of languages like Julia? Do you think it has a chance to bridge the worlds of HPC and the development speed of languages like Python and R?
Without really understanding what you mean with "rates", it seems the value of your asset moves around 1.14-1.15 with a very small variation.
The variation is so small that matplotlib changes the representation to accommodate such a small variation, indicating the reference value at the top with 1.145
You will have to dig in the matplotlib documentation to understand how this may be changed.
Track it with the notifications of notify_order or notify_trade - https://www.backtrader.com/docu/strategy/
Use the TradeAnalyzer which already includes this calculation - https://www.backtrader.com/docu/analyzers-reference/#tradeanalyzer
Write a custom analyzer which only tracks that value.
@Roger-Bos said in Full example of custom indicator:
import backtrader.indicator as btind
Notice that the original problem is the lack on an s. The code is importing backtrader.indicator and not backtrader.indicators
And yes, MovAv.Simple and all other aliases aforementioned, do exist.
I totally agree. I think that the quality of the documentation is really world class, all thanks to @backtrader
Nevertheless, having an online course would probably bring traders like myself up the learning curve much faster.
And I don't mind paying a small premium for the course.
At the risk of embarrassing myself in my very first post in this community by creating a zombie in replying to an old thread, i would like to say I found this thread useful, but runonce=False not so much. I bumped into:
ValueError: x and y must have same first dimension, but have shapes (1796,) and (1795,)"
when first adding just now resampling to daily data on a 1795-long pre-existing intra-day strategy with a bunch of my own indicators and observers being plotted.
I poked around a bit in the code before I found another work-around (and then, because I was hoping to do better, this thread...) to keep running back-tests seeing most of the plot with:
cerebro.plot(end = end-datetime.timedelta(hours = 8, minutes = 0, seconds = 0.01)) # hack to get around resample extra bar plot or whatever...
We'll see how long that lasts as I continue to develop with mixed timescales now. I have no idea why stopping the plot 8+epsilon hours early avoids the issue in my particular code-case (for now). But maybe the same idea might help someone else, so I bother to resurrect the zombie.
As an aside, I am somewhat stunned, as a total py newbie, that in a fairly short time I have been able to pull together a system that is downloading from IB, running my own custom strategy and indicators and observers on their live or my captured CSVs, producing plots that show what is going on...
Very nice job on the infrastructure. Kudos @backtrader.
PS: I also noticed that a prenext in one of my observers failed to execute after adding:
cerebro.resampledata(data0, name = 'data2', timeframe=bt.TimeFrame.Days,
which I thought odd, but not odd enough in itself to trouble anyone about. Now. On to inter-day, with almost all my plot, I hope.
Ended up with just a small change that 'fixes' the issue for me (probably not the best fix of cause):
diff --git a/backtrader/feeds/ibdata.py b/backtrader/feeds/ibdata.py
index ab3c184..84cff62 100644
@@ -408,7 +408,7 @@ class IBData(with_metaclass(MetaIBData, DataBase)):
'''request real-time data. checks cash vs non-cash) and param useRT'''
- if self.contract is None:
+ if self.contract is None or self._state == self._ST_LIVE: