Many thanks. I'm enjoying this nice conversation.
Always very appreciated.
@backtrader : You're always right. I'm not accurate, however I do my best to improve the ability. Also thanks to you.
Finally, you're also right: It's a modified piece of the library.
No, it cannot work for me, because that doesn't read from Yahoo. It tries
@Mario-Pellegrini said in float division by zero:
It is not a random code since you also say that the ticker works
It is random, because you apparently want to read from Yahoo and apply Quandl. The code has also nothing to do with the code from the homepage (3 snippets) that directly reads data from Yahoo.
Why don't you start from one of the scripts on the home page, change the ticker to FCA.MI and then slowly modify it? The link again for your reference
@Dimasik007 said in Observers/Analyzers per asset in multi-asset strategy?:
Is it possible to modify DataTrades Observer to implement something similar to what I've made on the picture below?
You can for sure write an Observer which looks at the current position value to determine the PnL.
@ab_trader said in IndexError: array index out of range:
In the __init()__ indexing should be done with (), not with  brackets, ref Docs - Lines: DELAYED indexing:
Pointed out some days ago by @ab_trader
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.
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.
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.
Really nice discussion. Check out this talk by John Reese on multithreading out of GIL and asyncio (be warned that your laptop may spontaneously combust :P ) : https://www.youtube.com/watch?v=0kXaLh8Fz3k&feature=youtu.be&t=10m30s
To learn more on asyncio : https://realpython.com/async-io-python/#the-asyncio-package-and-asyncawait
To learn more on GIL : https://realpython.com/python-gil/
Keep the good work guys ;)
notify_trade (with a closed trade) would in any case be called after this has been printed out:
@Benjamin-Kesby said in Trade never closed with position = 0:
Because your log ends there ... it is impossible to actually judge if notify_trade is called or not.
Then ... you fail to take into account that the cross runs on the higher timeframe and you operate on the lower timeframe. The lower timeframe will tick SEVERAL times, whilst the higher timeframe remains at the same point. On all these ticks the cross will evaluate to be true.
That's why you have order duplication and probably the source of your problems. You can only check the cross when it actually happens and have to ignore all other ticks which only belong to the lower timeframe.
See: https://www.backtrader.com/docu/concepts/ and read about the len