但生成的K线并不是完全等价的,如果跳空那根K线还是会很长,按道理应该是一根K线很长的话应该切成多根等长的K线,不应该出现高低点
所以自己处理出来的和系统自带的对不上
哪里有问题,为什么计算出来的和系统不一样,而且根数也很少。请老师帮忙指点一下
from PythonApi import *
import time
Diff=0.005 #价格变动的区间百分比
C"
NewClose=[]
def init(context):
global ContractId,ContractName,NewClose
RefClose1=0
RefClose2=0
ContractId=Symbol(context)
ContractName=SymbolName()
PriceList=history_bars(ContractId,1001,'1m',['open','high','low','close'])
if (len(PriceList)<1000):
return
LastClose=PriceList[-1][3]#最后一根K线的收盘价
NewClose.append(LastClose)
RefClose1=LastClose/(1+Diff)#倒推之前的高点范围
RefClose2=LastClose/(1-Diff)#倒推之前的低点范围
#print("%.3f %.3f %.3f"%(LastClose,RefClose1,RefClose2))
for i in range(len(PriceList)-1,-1,-1):
if (PriceList[i][1]>=RefClose2): #高点超过范围
LastClose=PriceList[i][3]#取超过范围的那根1分钟K线收盘价
RefClose2=LastClose/(1-Diff)#建立新的范围
NewClose.append(LastClose)#先不管顺序加入到最后
elif (PriceList[i][2]<=RefClose1):#低点超过范围
LastClose=PriceList[i][3]
RefClose1=LastClose/(1+Diff)
NewClose.append(LastClose)
print(NewClose)
print(len(NewClose))
def handle_bar(context):
pass
def Symbol(context):
return context.run_info.base_book_id
def SymbolName():
return get_dynainf(ContractId,219)