要得到按照时间等分切片的k线,可以使用Python中的pandas库进行处理。具体步骤如下:
- 读取原始数据
使用pandas中的read_csv函数读取原始数据,并将数据的日期时间列作为datetime类型转换。
import pandas as pd
df = pd.read_csv('file.csv', parse_dates=['datetime'])
- 重采样
使用pandas中的resample函数将原数据按照需要的周期进行重采样,然后使用聚合函数(如OHLC)对每个时间段内的数据进行聚合。
period = '160min'
resampled_df = df.resample(period, on='datetime').agg({'open': 'first',
'high': 'max',
'low': 'min',
'close': 'last'})
- 重新设置索引
使用reset_index函数将时间列变为普通列,并添加一个新的时间列作为重采样后的时间点。
resampled_df.reset_index(inplace=True)
resampled_df.rename(columns={'datetime': 'new_datetime'}, inplace=True)
- 导出数据
可以使用pandas中的to_csv函数将新数据导出为csv文件。
resampled_df.to_csv('resampled_file.csv', index=False)
- 在交易师中显示新数据
将导出的csv文件导入交易师,然后在主图上添加指标即可应用于新建的k线数据上。
以上是一种基本的思路,具体实现方式可能会因数据格式、所使用的周期等因素而有所不同,需要具体问题具体分析。