HaiGui.py 文件源码

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

项目:hf_at_py 作者: haifengat 项目源码 文件源码
def BarUpdate(self):
        """"""
        if self.CurrentBar < self.Params['fsLength']:
            return
        atr = talib.ATR(self.H, self.L, self.C, 14)

        lots = self.Params['Lots']

        DonchianHi = talib.MAX(self.H, self.Params['boLength'])[-2]
        DonchianLo = talib.MIN(self.L, self.Params['boLength'])[-2]

        fsDonchianHi = talib.MAX(self.H, self.Params['fsLength'])[-2]
        fsDonchianLo = talib.MIN(self.L, self.Params['fsLength'])[-2]

        ExitHighestPrice = talib.MAX(self.H, self.Params['teLength'])[-2]
        ExitLowestPrice = talib.MIN(self.L, self.Params['teLength'])[-2]

        if len(atr) < 2:
            return

        N = atr[-2]

        if self.Position == 0:
            if self.H[-1] > DonchianHi:
                price = max(min(self.H[-1], DonchianHi), self.O[-1])
                self.Buy(price, lots, '??')
            elif self.L[-1] < DonchianLo:
                price = min(max(self.L[-1], DonchianLo), self.O[-1])
                self.SellShort(price, lots, '??')
            # ????
            elif self.H[-1] > fsDonchianHi:
                price = max(min(self.H[-1], fsDonchianHi), self.O[-1])
                self.Buy(price, lots, '??-fs')
            elif self.L[-1] < fsDonchianLo:
                price = min(max(self.L[-1], fsDonchianLo), self.O[-1])
                self.SellShort(price, lots, '??-fs')

        elif self.Position > 0:
            if self.L[-1] < ExitLowestPrice:
                price = min(self.O[-1], max(self.L[-1], ExitLowestPrice))
                self.Sell(price, self.PositionLong, 'exit-?????')
            else:
                if self.H[-1] >= self.LastEntryPriceLong + 0.5 * N:
                    price = max(self.O[-1], self.LastEntryPriceLong + 0.5 * N)
                    self.Buy(price, lots, '{0},{1}'.format(N, '??-?'))
        elif self.Position < 0:
            if self.H[-1] > ExitHighestPrice:
                price = max(self.O[-1], min(self.H[-1], ExitHighestPrice))
                self.BuyToCover(price, self.PositionShort, 'exit')
            else:
                if self.L[-1] <= self.LastEntryPriceShort - 0.5 * N:
                    price = min(self.O[-1], self.LastEntryPriceShort - 0.5 * N)
                    self.SellShort(price, lots, '{0},{1}'.format(N, '??-?'))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号