Check the order status of Multiple Stocks
-
@backtrader I found the issue of the key error looping over stocks in the
INIT`` part of the strategy... its the
if len(d)``` part of the enumerate loop:for i, d in enumerate(d for d in self.datas if len(d)):
if you get rid of
if len(d)
the INIT works fine, and sets all the parameters toNone
.My question to @backtrader is, what is the purpose of
len(d)
? I thought it was just checking the length of the dataframe was >0 (i.e. contains data), however all of my dataframes contain data (checked their CSVs) so unsure why I get a key error whenif len(d)
is included - and unsure whyif len(d)
its used at all?Could it be that
len(d)
is the number of days you are in the market? This appears like it may be the case from thetradeanalyzer
analyzer output? But if thats the case... why would you useif len(d)
in the strategy next() loop?Thank you and look forward to your response!!
CWSE
-
If the data feeds have different timeframes not all of them may start delivering at the same time. A
1-minute
data feed will deliver faster than the1-day
counterpart.The
1-minute
data feed may already have delivered 500 bars and the1-day
may still be waiting. Hence thelen
check to avoid pulling values from a data feed which hasn't still delivered.A data feed having values is not the same as a data feed having delivered values.
-
@backtrader but all my data frames are daily time frame?
-
That's something you know and need not necessarily be true for other use cases. The code is written in a generic way which can also be applied during for example
prenext