Python talib 模块,MAX 实例源码

我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用talib.MAX

项目:base_function    作者:Rockyzsu    | 项目源码 | 文件源码
def math_operator_process(event):
    print(event.widget.get())
    math_operator = event.widget.get()

    upperband, middleband, lowerband = ta.BBANDS(close, timeperiod=5, nbdevup=2, nbdevdn=2, matype=0)
    fig, axes = plt.subplots(2, 1, sharex=True)
    ax1, ax2 = axes[0], axes[1]
    axes[0].plot(close, 'rd-', markersize=3)
    axes[0].plot(upperband, 'y-')
    axes[0].plot(middleband, 'b-')
    axes[0].plot(lowerband, 'y-')
    axes[0].set_title(math_operator, fontproperties="SimHei")


    if math_operator == '?????????':
        real = ta.MAX(close, timeperiod=30)
        axes[1].plot(real, 'r-')
    elif math_operator == '????????????':
        integer = ta.MAXINDEX(close, timeperiod=30)
        axes[1].plot(integer, 'r-')
    elif math_operator == '?????????':
        real = ta.MIN(close, timeperiod=30)
        axes[1].plot(real, 'r-')
    elif math_operator == '????????????':
        integer = ta.MININDEX(close, timeperiod=30)
        axes[1].plot(integer, 'r-')
    elif math_operator == '????????????':
        min, max = ta.MINMAX(close, timeperiod=30)
        axes[1].plot(min, 'r-')
        axes[1].plot(max, 'r-')
    elif math_operator == '???????????????':
        minidx, maxidx = ta.MINMAXINDEX(close, timeperiod=30)
        axes[1].plot(minidx, 'r-')
        axes[1].plot(maxidx, 'r-')
    elif math_operator == '??':
        real = ta.SUM(close, timeperiod=30)
        axes[1].plot(real, 'r-')

    plt.show()
项目:zStock    作者:superxhy    | 项目源码 | 文件源码
def MAX_CN(close, timeperiod=5):
        return tl.MAX(close, timeperiod)

    #MIN
项目:futuquant    作者:FutunnOpen    | 项目源码 | 文件源码
def donchian(self, n, array=False):
        """?????"""
        up = talib.MAX(self.high, n)
        down = talib.MIN(self.low, n)

        if array:
            return up, down
        return up[-1], down[-1]


########################################################################
项目: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, '??-?'))