cannot unpack non-iterable NoneType object
File "C:\Users\ratna\OneDrive\Desktop\upserge algo tradng masterclass\Session 3\Options addition.py", line 56, in <module>
CE_symbol_name, PE_symbol_name, CE_OTM_price, PE_OTM_price = tsl.OTM_Strike_Selection(Underlying= 'stock_name' , Expiry=0, OTM_count=2)
TypeError: cannot unpack non-iterable NoneType object
type or paste code here
while True:
current_time = datetime.now().time()
if current_time > EXIT_TIME:
print(f"{current_time} Exiting the Algo")
tsl.cancel_all_orders()
break
if current_time < ENTRY_TIME:
print(f"{current_time}Waiting for the market to open")
continue
for stock_name in watchlist:
print(f"{watchlist.index(stock_name)} Scanning {stock_name} :::: {traded_stocks}")
try:
chart = tsl.get_historical_data(tradingsymbol=stock_name, exchange='NSE', timeframe="5")
chart['RSI'] = talib.RSI(chart['close'], timeperiod=14) # todo: use as it is
except Exception as e:
print(f"Error in getting historical data for {stock_name}: {e}")
continue
rsi = chart.iloc[-2]['RSI'] # todo: use as it is
close = chart.iloc[-2]['close'] # todo: use as it is
bc1 = (rsi > 70)
bc2 = (close < 2000)
bc3 = (len(traded_stocks) <= 2)
bc4 = (stock_name not in traded_stocks)
sc1 = rsi < 30
sc2 = close < 2000
sc3 = len(traded_stocks) <= 2
sc4 = stock_name not in traded_stocks
if bc1 and bc2 and bc3 and bc4:
print("buy ", stock_name)
# ----- check if my entry is in options as well ------
CE_symbol_name, PE_symbol_name, CE_OTM_price, PE_OTM_price = tsl.OTM_Strike_Selection(Underlying= 'stock_name' , Expiry=0, OTM_count=2)
ce_options_chart = tsl.get_historical_data(tradingsymbol=CE_symbol_name, exchange='NFO', timeframe="5")
ce_options_chart['RSI'] = talib.RSI(ce_options_chart['close'], timeperiod=14) # todo: use as it is
bc5 = ce_options_chart.iloc[-1]['RSI'] > 60
if bc5:
lot_size = tsl.get_lot_size(tradingsymbol = CE_symbol_name)
first_ask = tsl.get_quote_data(names=[CE_symbol_name])[CE_symbol_name]['depth']['sell'][0]['price']
tsl.order_placement(tradingsymbol=CE_symbol_name, exchange='NFO', quantity=lot_size, price=first_ask, trigger_price=0,order_type='LIMIT', transaction_type='BUY', trade_type='MIS', amo_time="OPEN",after_market_order=False)
traded_stocks.append(stock_name)
if sc1 and sc2 and sc3 and sc4:
print("sell ", stock_name)
# ----- check if my entry is in options as well ------
CE_symbol_name, PE_symbol_name, CE_OTM_price, PE_OTM_price = tsl.OTM_Strike_Selection(Underlying= 'stock_name', Expiry=0, OTM_count=2)
pe_options_chart = tsl.get_historical_data(tradingsymbol=PE_symbol_name, exchange='NFO', timeframe="5")
pe_options_chart['RSI'] = talib.RSI(pe_options_chart['close'], timeperiod=14) # todo: use as it is
sc5 = pe_options_chart.iloc[-1]['RSI'] > 60
if sc5:
lot_size = tsl.get_lot_size(tradingsymbol = PE_symbol_name)
first_ask = tsl.get_quote_data(names=[PE_symbol_name])[PE_symbol_name]['depth']['sell'][0]['price']
tsl.order_placement(tradingsymbol=PE_symbol_name, exchange='NFO', quantity=lot_size, price=first_ask, trigger_price=0,order_type='LIMIT', transaction_type='BUY', trade_type='MIS', amo_time="OPEN",after_market_order=False)
traded_stocks.append(stock_name)