In the context of a Double NR7 Bar, it means that there are two days in a row where the daily price range is exceptionally narrow compared to the previous seven days. This pattern often indicates a period of very low volatility and a potential upcoming price breakout or significant move.
Double NR7 Bar is also NR8 by Definition:
To go ahead with this tutorial, One must complete the pre-requsite tutorial which shows how to scan the stocks having Double NR4 Bar Pattern.
from datetime import datetime, timedelta
# Define the date range
start_date = datetime.strptime('2023-08-01', '%Y-%m-%d')
end_date = datetime.strptime('2023-09-01', '%Y-%m-%d')
# Define the interval (in minutes)
interval = 'day'
# Iterate through the list of stock symbols
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, start_date, end_date, interval='day')
# Initialize variables to track NR7 candles
nr7_candles = []
consecutive_nr7_candles = 0 # Initialize a counter for consecutive NR7 candles
# Iterate through historical data to detect NR7 candles
for i in range(6, len(historical_data)):
current_candle = historical_data[i]
# Calculate the trading range for the previous six candles
previous_candles = historical_data[i - 6:i]
trading_ranges = [candle['high'] - candle['low'] for candle in previous_candles]
# Check if the current candle has the narrowest range among the previous six (NR7)
if min(trading_ranges) == trading_ranges[-1]:
nr7_candles.append(current_candle)
consecutive_nr7_candles += 1
else:
consecutive_nr7_candles = 0 # Reset the counter if no NR7 candle
# Check if there were two consecutive NR7 candles
if consecutive_nr7_candles == 2:
print(f"Double NR7 Candle detected for {symbol} on {current_candle['date']}")
consecutive_nr7_candles = 0 # Reset the counter after detection
else:
print(f"Instrument token not found for {symbol}")
else:
print(f"{symbol} not found in instruments")
The output looks like –
Double NR7 Candle detected for NSE:NIFTY BANK on 2023-08-21 00:00:00+05:30
Double NR7 Candle detected for NSE:NIFTY BANK on 2023-08-23 00:00:00+05:30
Double NR7 Candle detected for NSE:VOLTAS on 2023-08-18 00:00:00+05:30
Double NR7 Candle detected for NSE:TATASTEEL on 2023-08-23 00:00:00+05:30
...
...
...
...
Double NR7 Candle detected for NSE:SYNGENE on 2023-08-31 00:00:00+05:30
Double NR7 Candle detected for NSE:NAVINFLUOR on 2023-08-28 00:00:00+05:30
Double NR7 Candle detected for NSE:GRASIM on 2023-08-21 00:00:00+05:30
Double NR7 Candle detected for NSE:NIFTY FIN SERVICE on 2023-08-21 00:00:00+05:30
Here’s an explanation of the key changes made from the code for detecting Double Narrow Range 4 (NR4) Bars to the code for detecting Double Narrow Range 7 (NR7) Bars:
nr4_candles
becomes nr7_candles
, and consecutive_nr4_candles
becomes consecutive_nr7_candles
. This ensures that the code appropriately tracks NR7 candles and consecutive NR7 candles.These changes allow the code to scan for Double NR7 Bars, which require identifying two consecutive NR7 candles within the historical data for a given stock symbol.