VeighNa量化社区
你的开源社区量化交易平台
Member
avatar
加入于:
帖子: 20
声望: 0

编程新手求问,计算倒数第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]
Member
avatar
加入于:
帖子: 716
声望: 62

用min函数取最小值和均价比较就行

Member
avatar
加入于:
帖子: 20
声望: 0

郭易燔 wrote:

用min函数取最小值和均价比较就行
嗯嗯谢谢,其实我的意思是,倒数第10根k的收盘价大于倒数第10根k时刻均线的值,倒数第9根k的收盘价大于倒数第9根k时刻均线的值,以此类推

Member
avatar
加入于:
帖子: 716
声望: 62

要不试试各写进一个列表,然后使用map函数或者for循环比较

© 2015-2022 上海韦纳软件科技有限公司
备案服务号:沪ICP备18006526号

沪公网安备 31011502017034号

【用户协议】
【隐私政策】
【免责条款】