SMACross.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:hf_at_py 作者: haifengat 项目源码 文件源码
def OnBarUpdate(self, data=Data, bar=Bar):
        if len(self.C) < self.p_ma2:
            return

        # print('{0}-{1}'.format(self.D[-1], self.C[-1]))
        ma1 = talib.SMA(self.C, self.p_ma1)
        ma2 = talib.SMA(self.C, self.p_ma2)

        self.IndexDict['ma5'] = ma1
        self.IndexDict['ma10'] = ma2

        if self.PositionLong == 0:
            if ma1[-1] >= ma2[-1] and ma1[-2] < ma2[-2]:
                if self.PositionShort > 0:
                    self.BuyToCover(self.O[-1], self.p_lots, '??')
                self.Buy(self.O[-1], self.p_lots, '??')
        elif self.PositionShort == 0:
            if ma1[-1] <= ma2[-1] and ma1[-2] > ma2[-2]:
                if self.PositionLong > 0:
                    self.Sell(self.O[-1], self.p_lots, '??')
                self.SellShort(self.O[-1], self.p_lots, '??')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号