等级: 超级版主
- 注册:
- 2021-5-18
- 曾用名:
- FireScript
|
def init(context):
# 在context中保存全局变量
context.s1 = "SQRB00"
day_data = history_bars_date(context.s1,'20230801','20230807','1d', ['open','datetime'])[-3:]
min5_data = history_bars_date(context.s1,'20230801','20230807','5m', ['close','datetime'])[-1000:]
data_iter = iter(day_data)
openc,starttime = next(data_iter)
endtime = starttime+190000
result = []
sm = 0
for item in min5_data:
price,time = item
if time<starttime:
continue
if time>endtime:
result.append((starttime,sm))
try:
openc,starttime = next(data_iter)
sm = 0
except StopIteration:
break
endtime = starttime+190000
sm = sm + price - openc
print(result[-1])
我上面对取出的数据做了个切片,因为history_bars_date 目前版本有BUG,会直接取出全部数据。 |
|