4.23K 浏览
0

def recalc_paramter(self): 
# 平均真实波幅(N值) 
self.n = ATR(self.klines, self.atr_day_length)["atr"].iloc[-1] 
# 买卖单位 
self.unit = int((self.account.balance * 0.01) / (self.quote.volume_multiple * self.n)) 
# 唐奇安通道上轨:前N个交易日的最高价 
self.donchian_channel_high = max(self.klines.high[-self.donchian_channel_open_position - 1:-1]) 
# 唐奇安通道下轨:前N个交易日的最低价 s
elf.donchian_channel_low = min(self.klines.low[-self.donchian_channel_open_position - 1:-1]) 
print("唐其安通道上下轨: %f, %f" % (self.donchian_channel_high, self.donchian_channel_low)) 
return True

这一段看起来是无条件return true的,在下面

def strategy(self): 
"""海龟策略""" 
print("等待K线及账户数据...")
 deadline = time.time() + 5 
while not self.recalc_paramter(): 
if not self.api.wait_update(deadline=deadline): 
raise Exception("获取数据失败,请确认行情连接正常并已经登录交易账户")
 while True: 
self.try_open() 
self.try_close()

这一段strategy中,while not self.recalc_paramter()是在什么情况下可以发生返回false的?

youzhixiaozhu 未选择答案 2020年5月26日
0

海龟策略是以前写的了,现在api优化了很多,比如一定会收到行情才返回给策略代码,因此就不需要您这段代码里的”获取数据失败“那一段了,这个代码以后需要优化

youzhixiaozhu 未选择答案 2020年5月26日
您正在查看2个答案中的1个,单击此处查看所有答案。