编程新手求问,计算倒数第10根k线至倒数第2根k线的收盘价,全部大于当时的均线数值,除了一个个去比较的笨方法……有没有一两句精简代码,就可以完成这项判断的?
# 计算均线
ma_ = am.sma(self.ma_window, array=True)
self.ma_2 = ma_[-2] # T-1时刻数值
self.ma_3 = ma_[-3] # T-2时刻数值
self.ma_4 = ma_[-4] # T-3时刻数值
self.ma_5 = ma_[-5] # T-4时刻数值
self.ma_6 = ma_[-6] # T-5时刻数值
self.ma_7 = ma_[-7] # T-6时刻数值
self.ma_8 = ma_[-8] # T-7时刻数值
self.ma_9 = ma_[-9] # T-8时刻数值
self.ma_10 = ma_[-10] # T-9时刻数值
# 计算收盘价
close_ = bar.close_price
self.close_2 = bar.close_price[-2]
self.close_3 = bar.close_price[-3]
self.close_4 = bar.close_price[-4]
self.close_5 = bar.close_price[-5]
self.close_6 = bar.close_price[-6]
self.close_7 = bar.close_price[-7]
self.close_8 = bar.close_price[-8]
self.close_9 = bar.close_price[-9]
self.close_10 = bar.close_price[-10]