Previous Day NIFTY 50 (12:30–3:30) High/Low - How to calculate via Dhan/TradeHull?

Hi all,

I’m looking to calculate previous trading day NIFTY 50 index High & Low specifically for the session 12:30 PM to 3:30 PM.

Can this be done directly in TradeHull, or via Dhan data / API?

If yes, please share the exact process or settings.

If not, what is the recommended workaround (intraday candles, export, API logic, etc.)?

This is required for rule-based / algo trading, not manual chart marking.

Tagging @Tradehull_Imran for guidance.

Thanks in advance.

Hi @Ketan_Kharva ,

Refer the below code-

previous_date  = tsl.get_historical_data(tradingsymbol='NIFTY', exchange='INDEX', timeframe="day")
previous_date  = previous_date.iloc[-1]['timestamp']

previous_range = tsl.get_historical_data(tradingsymbol='NIFTY', exchange='INDEX', timeframe="5")
previous_range = previous_range.set_index(previous_range['timestamp'])

start          = str(previous_date) + ' 12:30:00+05:30'
end            = str(previous_date) + ' 15:30:00+05:30'
previous_range = previous_range[start:end]
range_high     = previous_range['high'].max()
range_low      = previous_range['low'].min()
1 Like

Hi Imran

Thank you so much for this explanation. It really helped clear things for me.

Honestly, I’m a big fan of the way you explain concepts, and I actually started learning algo trading because of your videos and guidance. This logic made things click properly for me.

Really appreciate your support :folded_hands:

If I run into any issues, I’ll reach out.

1 Like

Hi Imran,

@Tradehull_Imran

Your index data logic is working fine now.

I need help only on the options data part in Tradehull/Dhan:

• Based on previous day Index second-half (12:30–3:30 PM) High/Low, how to

  1. select the correct CE & PE strike (ATM ±4 / ±200 pts)
  2. fetch previous day (12:30–3:30 PM) High/Low, for those CE & PE premiums

Also, on expiry day, what’s the correct way to:

• switch to next expiry, and

• fetch previous day second-half High/Low for next-expiry CE & PE

I’m asking only for data-fetching & symbol-selection workflow

Thanks in advance

Hi @Ketan_Kharva ,

Refer the below code-

# Fetch 4th OTM option data for the current expiry
ce_symbol, pe_symbol, ce_strike, pe_strike = tsl.OTM_Strike_Selection(
    Underlying='NIFTY',
    Expiry=0,      # 0 = current expiry, 1 = next expiry
    OTM_count=4    # Fetch the 4th Out-of-The-Money strike
)
  • Expiry = 0 → fetches current expiry
  • Expiry = 1 → fetches next expiry
  • OTM_count = 4 → selects the 4th OTM strike
1 Like

Thanks a lot, Imran :+1:

This helps and clears the strike selection confusion.

I’ll proceed using OTM_Strike_Selection() for CE/PE and handle expiry switching as suggested.

If any concern comes up, I’ll update you.

Appreciate your support

1 Like

Hi Imran,

@Tradehull_Imran

We are using Tradehull + Dhan in a log-only algo setup and would like clarity on three specific implementation points.

  1. Option symbol resolution (strike finalised, expiry offset known)

We already decide the strike ourselves (ITM logic) and only need Tradehull for expiry resolution & symbol mapping.

Our strike logic (fixed and final) is:

rounded_high = round(index_sh_high / 100) * 100

rounded_low = round(index_sh_low / 100) * 100

ce_strike = rounded_high - 200 # CE ITM

pe_strike = rounded_low + 200 # PE ITM

We also already decide expiry offset:

Expiry = 0 → current weekly expiry

Expiry = 1 → next weekly expiry

Could you please confirm the recommended Tradehull-supported way to fetch the exact option symbol (CE / PE) when strike price and expiry offset are already known, without using OTM_Strike_Selection for strike logic or any LTP-based logic?

  1. Expiry-day detection (weekly expiry)

We want to reliably detect weekly expiry day so that on expiry:

We switch from Expiry = 0 → Expiry = 1

With our current setup (strike fixed, expiry offset controlled by us), what is the recommended Tradehull way to detect that “today is weekly expiry day”?

  1. Live market feed (Index + Option)

We are currently subscribing to the live NIFTY index feed via Dhan and building our own 1-minute candle engine.

After index direction is locked, we want to subscribe to only one option (CE or PE):

Index live feed → direction logic

After lock → subscribe to CE or PE only

security_id already resolved

Could you also confirm the recommended Dhan / Tradehull approach to:

Subscribe to live NIFTY index feed, and

Subscribe to live option feed (CE / PE) using security_id,

so ticks can be forwarded into a custom candle engine?

If there are simpler or more robust patterns you recommend for live feed handling, we’re open to those as well.

A minimal reference example would be really helpful. Thanks.

Hi @Tradehull_Imran,

Just re-tagging in case my earlier message got missed.

We’ve already implemented most of the engine and would really appreciate your guidance / confirmation on the points shared above (option symbol resolution with known strike & expiry, expiry-day detection, and live feed approach).

Your direction will help us align correctly with Tradehull’s intended usage. Thanks :folded_hands:

Hi @Ketan_Kharva ,

  1. If strike and expiry is already known -
  • You can form the symbol name as below
    option_name = f"{name}{expiry_str}{strike}{right}"
  • OR you can use the instrument file and filter accordingly.
  1. If you want to switch strike selection on expiry day, you can firstly fetch the the expiry list using the below function of codebase -
expiry_list = tsl.get_expiry_list(Underlying="NIFTY", exchange = "INDEX")
date=expiry_list [0]
today = datetime.today().date()
if today==date:
    expiry = 1
else:
    expiry = 0
  1. The live feed you fetch from api can be stored in a database like MYSQL and form the data accordingly and use it for your requirements.
1 Like

Hi @Tradehull_Imran,

Thanks for the guidance on symbol formation and expiry logic. It helped us resolve the issue we were stuck on.

Appreciate your support :folded_hands:

1 Like