Hey guys!
I have what will be a simple question for anyone well endowed in Python! I am attempting to loop through multiple symbols but I keep getting these errors!
Runtime Error: 'bool' object is not subscriptable
at OnData
if (symbol_price < self.trigger_thirty_min_low[symbol]) and self.invest_thirty_min[symbol] and self.thirty_min_trigger[symbol] and not self.Portfolio.Invested[symbol]:
at Python.Runtime.PythonException.ThrowLastAsClrException()
OR
argument of type ‘bool’ is not iterable
Consider the following example code in an OnData Method:
for symbol in self.symbolData.keys():
symboldata = self.symbolData[symbol]
if symboldata.IsReady():
if self.short[symbol] and self.target_sell[symbol] and (symbol_price < self.initial_target_price[symbol]):
self.MarketOrder(self.ticket.Symbol, (self.Securities[self.ticket.Symbol].Holdings.AbsoluteQuantity))
self.target_sell[symbol] = False
self.thirty_min_reversal_sell[symbol] = False
self.Log(f'{symbol} EXIT (INITIAL TARGET) {symbol_price}')
if self.long[symbol] and self.target_sell_l[symbol] and (symbol_price < self.initial_target_price_l[symbol]):
self.MarketOrder(symbol, -(held_stocks))
self.target_sell_l[symbol] = False
self.thirty_min_reversal_sell_l[symbol] = False
self.Log(f'{symbol} EXIT (INITIAL TARGET) {symbol_price}')
Thank you so much to anyone who helps me out!
Best,
Jesse
Thank you my awesome community!
Derek Melchin
Hi Jesse,
Try replacing self.Portfolio.Invested[symbol] with self.Portfolio[symbol].Invested.
Best,
Derek Melchin
Want to invest in QuantConnect as we build the Linux of quant finance? Checkout our Wefunder campaign to join the revolution.
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Jesse Fleming
That is beautiful, thank you!
May I ask you one more thing, how could I add resolutions to my multiple tickers? Say, if I wanted Second Resolution on both AAPL and USO.
def Initialize(self):
self.SetStartDate(2022, 8, 1) # Set Start Date
self.SetEndDate(2022, 10, 18)
self.SetCash(10000) # Set Strategy Cash
self.symbolData = {}
self.ticker_list = ['AAPL', ‘USO’]
for ticker in self.ticker_list:
symbol = self.AddEquity(ticker)
symbol.SetDataNormalizationMode(DataNormalizationMode.SplitAdjusted)
symbol = symbol.Symbol
self.symbolData[symbol] = SymbolData(self, symbol)
Let me know what you think! And thank you for your usual timely and wonderful answers.
Best,
Jesse
Nico Xenox
Hey Jesse Fleming,
just add the resolution you want to the AddEquity function.
Hope it helps ;)
Jesse Fleming
Remarkable. You guys save me constantly, thank you so much, you two
Jesse Fleming
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!