不是新的一分钟的情况下,更新K线的最高价和最低价,代码如下:
self.bar.high_price = max(self.bar.high_price, tick.last_price)
if tick.high_price > self.last_tick.high_price:
self.bar.high_price = max(self.bar.high_price, tick.high_price)
self.bar.low_price = min(self.bar.low_price, tick.last_price)
if tick.low_price < self.last_tick.low_price:
self.bar.low_price = min(self.bar.low_price, tick.low_price)
疑问:
为什么要先与tick.last_price比较一下,然后再在价格走高/走低的条件下再与tick.high_price/tick.low_price进行比较?
将代码更改如下:
self.bar.high_price = max(self.bar.high_price, tick.high_price)
self.bar.low_price = min(self.bar.low_price, tick.low_price)
与原代码有什么区别?