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 theif 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 to
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 when
if len(d)is included - and unsure why
if 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 the
tradeanalyzeranalyzer output? But if thats the case... why would you use
if len(d)in the strategy next() loop?
Thank you and look forward to your response!!
If the data feeds have different timeframes not all of them may start delivering at the same time. A
1-minutedata feed will deliver faster than the
1-minutedata feed may already have delivered 500 bars and the
1-daymay still be waiting. Hence the
lencheck 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