AFAIU, the data feeds ( and other classes inherited from LineRoot ) override all the operators (including eq ) in order to support the definition of complex lines during the strategy's __init__ method. Explained in the docs: here and here
So just writing ( during the __init__ method only ):
a = self.datas == self.datas
will result not in boolean value, but return a LineOperation object.
However, after the data feedsstart` method is called the behavior of the above operators changes. Now instead of returning the LineOperation, the operator is applied to the current value of the first line object in the data feed. So:
a = self.datas == self.datas
will actually be equal to:
a = self.datas.lines == self.datas.lines
It may not sound intuitive at first - but this is how it seems to be working (at least in my debugger :-) ). Please correct me if I'm wrong in case you are observing something else.
Back to your second question - I would suggest to store the index of the data in the rankings array instead of storing the data feed itself. Probably this way it will be easier to compare them.
I've placed the indicators in strategy's init(self)
# Calculate these on each run
self.lowF = bt.indicators.MovingAverageSimple(self.data.low, period=15)
self.highF = bt.indicators.MovingAverageSimple(self.data.high, period=15)
If I try to place the indicators in next(self), I'm unable to use the results (self.lowF: IndexError: array index out of range) or (self.lowF: <backtrader.indicators.sma.MovingAverageSimple object at 0x7f9153a59c70>)
What is the difference when calling the data with self.lowF and self.lowF in next(self) ?
I'm comparing the exact same algorithm in Backtrader and Quantopian (with the exception that in Q the indicators are generated on every run of the rebalance function).
If I use  to get the indicators values in next(), I get quite different results.
If I set  and then do the algo calculations - the end result is ... extremely similar to the one I see in Quantopian.
Absolutely every other parameter is 1:1... I'm hitting my head for a week now trying to figure out where this enormous difference comes from.
And something else, say I set a fromdate 2010-08-01 and todate 2010-09-01.
If the SMA period is 20 days, that makes the strategy start working at 2010-08-21 which is ... weird comparing to Quantopian where data.history can get values outside of the backtest period.
How do you approach this? If I leave the fromdate value out of the dataset load - most indicators / observers start from the very beginning of the dataset, which makes graphing them extremely ugly, and some of my indicators are for 1 year back.
Hopefully you'll help me out cause my head starting to hurt a lot :)
Okay thanks for the advice, i think i understand that.
Just one problem, i'm using a machine learning function.
And that wants data in a numpy array format like this;
(2D numpy array i think)
But the lines in backtrader are working different :
[1000 2000 3000 4000]
(1D array i think)
So i wonder if there is a way to convert this too a numpy array on which the algorithm is working.
@Andre-Frade said in Open position but no resting order:
Any ideas of what might be going on ?
No resting order is issued
Resting order is executed before you search for it
The way you are looking for the resting order is incorrect
You can use writer. Or extract this data from cerebro() after the run. Or write strategy which will gather all prices during next() calls and then save .csv in the stop()
Docs - Logging - Writer
Docs - Cerebro - Returning the results
@vladisld Yes you are right, my mistake was that I was using a reversed csv file and for GenericCSVData the reverse=True does not do anything. Then the csv file gets read assuming that the next row will be a later timestamp and ignores everything if the first line is too late to be considered. Might be wring with that but that's my explanation I came up with.
Anyway I tried and reversed the csv file manually and now it works, thank you.
But still, for further workings: do you have a trick for debugging? When I load it in a pandas dataframe for example it is really easy to read out the data, but where is the data stored in the GenericCSVData object? I am curious to find out, is it present in the line buffers?
@kian-hong-Tan thanks for your reply. Yes, I've tried all of that already and it doesn't work in Jupyter unfortunately so I guess I just won't use jupyter for now. I only noticed that some space is allocated for the toolbar but the toolbar itself doesn't want to show up.
@vbs no problem, thanks for your reply and for backtrader-plotting!
After some search, it seems the problem with ipython kernel. So just use another plot frame is ok to show the figure.
cerebro.plot(height = 30, iplot = False)
Sorry to mention: I printed out position.size to see, if it is going negativ...but it was allways positive, Long and Short.
But anyway...somehow it is not...maybe I was looking wrong, or formating-error.
Now it works with no error.
Thanks so much for quick reply!
So I just tested quantopian's "PerShare" stocks commission model and comparing to BTs model - well.. for the same amount of shares BT shows 40k $ commissions, Q shows 211.0 $ commissions.
So, again.. does BT have a PerShare commissions model where we can set the minimum amount - 1$, and 0.0115$ per share ?