In the world of trading and investing, candlestick patterns play a significant role in helping traders make informed decisions. One such pattern is the “Inside Bar,” which can signal potential changes in price direction.
In this article, we will explore how to use Python and the Zerodha Kite Connect API to detect Inside Bars for a specific stock, such as RELIANCE.
for symbol in symbol_list:
# Fetch instrument data for the current stock symbol
instruments = kite.ltp([symbol])
# Check if the stock symbol is in the instruments dictionary
if symbol in instruments:
instrument_token = instruments[symbol]['instrument_token']
if instrument_token:
# Fetch historical data for the stock
historical_data = kite.historical_data(instrument_token, '2023-01-01', '2023-09-01', interval='day')
# Initialize variables to track inside bars
inside_bars = []
# Iterate through historical data to detect inside bars
for i in range(1, len(historical_data)):
current_candle = historical_data[i]
previous_candle = historical_data[i - 1]
if (current_candle['high'] < previous_candle['high']) and (current_candle['low'] > previous_candle['low']):
inside_bars.append(current_candle)
# Check if there was an Inside Bar pattern yesterday
if len(inside_bars) > 0:
print(f"Inside Bar detected for {symbol} on {inside_bars[-1]['date']}")
else:
print(f"Instrument token not found for {symbol}")
else:
print(f"{symbol} not found in instruments")
In this modified code:
symbol_list
.kite.ltp([symbol])
.instruments
dictionary.instruments
, it proceeds to fetch historical data and check for Inside Bar patterns as before.This code will loop through all the stock symbols in your list and analyze each one for Inside Bar patterns while fetching instrument data for each symbol.
Inside Bar detected for NSE:NIFTY BANK on 2023-08-07 00:00:00+05:30
Inside Bar detected for NSE:IBULHSGFIN on 2023-09-01 00:00:00+05:30
Inside Bar detected for NSE:VOLTAS on 2023-08-28 00:00:00+05:30
Inside Bar detected for NSE:SBIN on 2023-08-28 00:00:00+05:30
Inside Bar detected for NSE:INFY on 2023-08-29 00:00:00+05:30
Inside Bar detected for NSE:GAIL on 2023-08-29 00:00:00+05:30
Inside Bar detected for NSE:ESCORTS on 2023-08-31 00:00:00+05:30
Inside Bar detected for NSE:TATASTEEL on 2023-08-18 00:00:00+05:30
Inside Bar detected for NSE:APOLLOTYRE on 2023-08-30 00:00:00+05:30
Inside Bar detected for NSE:DRREDDY on 2023-08-21 00:00:00+05:30
Inside Bar detected for NSE:LALPATHLAB on 2023-08-08 00:00:00+05:30
...
...
...
...
Inside Bar detected for NSE:WIPRO on 2023-08-23 00:00:00+05:30
Inside Bar detected for NSE:ZEEL on 2023-09-01 00:00:00+05:30
Inside Bar detected for NSE:ZYDUSLIFE on 2023-08-21 00:00:00+05:30