Support Board
Date/Time: Sat, 23 Nov 2024 18:07:56 +0000
Post From: Python for Sierra Chart
[2024-02-13 04:03:11] |
rudy5 - Posts: 5 |
Thanks so much for that function. I was having issues with the time adjustment so I did this instead, in case its helpful for anyone. The time adjustment will need to be updated manually for DST I'd imagine but that should be simple enough. def get_scid_df(symbol, limitsize=sys.maxsize):
f = Path(rf'c:\SierraChart\Data\{symbol}') assert f.exists(), "file not found" stat = f.stat() offset = 56 if stat.st_size < limitsize else stat.st_size - ((limitsize // 40) * 40) BCOLS = ['datetime', 'open', 'high', 'low', 'close', 'volume', 'trades', 'bidVolume', 'askVolume'] rectype = np.dtype([ (BCOLS[0], '<u8'), (BCOLS[1], '<f4'), (BCOLS[2], '<f4'), (BCOLS[3], '<f4'), (BCOLS[4], '<f4'), (BCOLS[6], '<i4'), (BCOLS[5], '<i4'), (BCOLS[7], '<i4'), (BCOLS[8], '<i4') ]) df = pd.DataFrame(data=np.memmap(f, dtype=rectype, offset=offset, mode="r"), copy=False) df = df.dropna() years_microseconds = 70 * 365.25 * 24 * 60 * 60 * 10**6 # accounts for leap years supposedly days_microseconds = 2 * 24 * 60 * 60 * 10**6 total_microseconds = years_microseconds + days_microseconds # 70 years, 2 days df.datetime = df.datetime - total_microseconds # Add 6 hours to get to local time df.datetime = pd.to_datetime(df.datetime, unit='us') + pd.Timedelta(hours=6) df.set_index('datetime', inplace=True) # Prices need to be adjusted if 'ES' in symbol: div = 100 if any(item in symbol for item in ['6E', '6B']): div = 10000 for c in ['high', 'low', 'close']: df[c] = df[c] / div df.open = df.close return df I have yet to get custom `limitsize` values working reliably though. Date Time Of Last Edit: 2024-02-13 04:21:36
|