Login Page - Create Account

Support Board


Date/Time: Thu, 02 May 2024 17:17:57 +0000



Post From: Python for Sierra Chart

[2023-01-12 18:45:07]
machinagurujp - Posts: 12
I'm still getting the same issue with 1 sec. When you look at the data historically it works fine. But when live and printing the values for current bar based on resampling size it's wrong. After the next bar it corrects the values from previous bars that were incorrect. I provided the code below. It matches yours and technically the data is indexed before it's resampled. I didn't sort it but I can.


def __init__(self) -> None:

self.bcols = ['Time', 'Open', 'High', 'Low', 'Close', 'Volume', 'Trades', 'BidVolume', 'AskVolume']

def get_scid_df(self, filename, limitsize=sys.maxsize):

f = Path(filename)
assert f.exists(), "file not found"
stat = f.stat()
offset = 56 if stat.st_size < limitsize else stat.st_size - (
(limitsize // 40) * 40)
rectype = np.dtype([
(self.bcols[0], '<u8'), (self.bcols[1], '<f4'), (self.bcols[2], '<f4'),
(self.bcols[3], '<f4'), (self.bcols[4], '<f4'), (self.bcols[6], '<i4'),
(self.bcols[5], '<i4'), (self.bcols[7], '<i4'), (self.bcols[8], '<i4')
])
df = pd.DataFrame(data=np.memmap(f, dtype=rectype, offset=offset, mode="r"),copy=False)
df.dropna(inplace=True)
df["Time"] = df["Time"] - 2209161600000000
df.drop(df[(df.Time < 1) | (df.Time > 1705466561000000)].index, inplace=True)
df.set_index("Time", inplace=True)
df.index = pd.to_datetime(df.index, unit='us')
# df.index = df.index.tz_localize(tz="est")

return df

def resampling(self, df):
df_5min = (
df.resample("5Min").agg(
{
"Open": "first",
"High": "max",
"Low": "min",
"Close": "last",
"Volume": "sum",
"Trades": "sum",
"BidVolume": "sum",
"AskVolume": "sum",
}

).ffill()

)

df = df_5min[["Open", "High", "Low", "Close"]]
df.index.rename('Open time', inplace=True)

eastern = pytz.timezone('US/Eastern')
df.index = df.index.tz_localize(pytz.utc).tz_convert(eastern)
df.index = df.index.tz_localize(None)
df = df / 100 #Needed for CL prices

return df

Date Time Of Last Edit: 2023-01-12 18:56:47