In this example I have a dataframe filled with OHLC hourly data from EURUSD.
My strategy revolves around signaling daily patterns and executing on the hourly timeframe. Therefore, besides hourly OHLC data, I also want daily OHLC data.
When criteria is met on the daily, I drop down to the 1 hour to look for an entry
I have tried the following
bars = ib.reqHistoricalData(contract, endDateTime='', durationStr='1 Y', barSizeSetting='1 hour', whatToShow='MIDPOINT', useRTH=True, formatDate=2)
df = pd.DataFrame(bars)[['date', 'open', 'high', 'low', 'close']]
df.set_index('date', inplace=True)
df['daily open'] = df['open'].resample('D').first()
df['daily close'] = df['close'].resample('D').last()
df['daily high'] = df['high'].resample('D').max()
df['daily low'] = df['low'].resample('D').min()
results dataframe
This does the job relatively well, but the daily OHLC data is calculated at mindnight (00.00). This is UTC time, so a new day starts at 21.15. I tried shifting the entire dataframe, but wondering if that is the best way to do it.
To summarize:
- I want the daily close price from the hourly ‘close’ at 20.00
- I want the daily open price from the hourly ‘open’ at 21.15 previous day
- I want the daily high price from ‘max’ previous day
- I want the daily low price from ‘low’ previous day
2