Creating indicators on custom time frame using Tradehull library

Hi Imran & team,
@Tradehull_Imran
You provide historical data in fixed timeframes like 1, 5, 15, 30, and 60 minutes. But I want to calculate indicators such as RSI and SuperTrend on my own custom timeframes (for example, 2, 10, or 20 minutes). The issue is that the indicator timestamps don’t align with market hours. For example, if the market starts at 9:15 AM, my 2-minute candles are being generated from 9:14–9:16 AM instead of 9:15–9:17 AM. Please find the code here as well:
chart = tsl.get_historical_data(“TCS”, “NSE”, “1”)
df = pd.DataFrame(chart)
df[‘timestamp’] = pd.to_datetime(df[‘timestamp’])
df = df.set_index(‘timestamp’)

Keep only market hours

df = df.between_time(“09:15”, “15:30”)
results =
for day, df_day in df.groupby(df.index.date):
# — Warm-up with yesterday’s last 30 mins —
start = df_day.index.min() - pd.Timedelta(minutes=30)
df_warm = df.loc[start:df_day.index.max()]

# Resample to 2-min OHLC
ohlc_dict = {'open':'first','high':'max','low':'min','close':'last','volume':'sum'}
chart_2min = df_warm.resample(
'2T',
closed='right',
label='right',
origin='start_day',
offset='15min'   # <-- shift bins so first candle is 09:15–09:17
).agg(ohlc_dict).dropna()

# Indicators
chart_2min['rsi'] = talib.RSI(chart_2min['close'], timeperiod=14)
supertr = ta.supertrend(chart_2min['high'], chart_2min['low'], chart_2min['close'], 10, 3)
chart_2min = pd.concat([chart_2min, supertr], axis=1)
# Keep only today’s 9:15–15:30
chart_2min = chart_2min.loc[df_day.index.min():df_day.index.max()]
# Reset index so timestamp is a normal column
chart_2min = chart_2min.reset_index()
results.append(chart_2min)

Final dataframe with timestamp column

final_df = pd.concat(results, ignore_index=True)

Hey @Anil_Kumar2 ,

Thanks for bringing this up @Tradehull_Imran may be able to assist here.