Python talib.MACDEXT Examples

The following are 5 code examples of talib.MACDEXT(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module talib , or try the search function .
Example #1
Source File: talib_series.py    From QUANTAXIS with MIT License 5 votes vote down vote up
def MACDEXT(Series, fastperiod=12, fastmatype=0, slowperiod=26, slowmatype=0, signalperiod=9, signalmatype=0):
    macd, macdsignal, macdhist = talib.MACDEXT(
        Series.values, fastperiod, fastmatype, slowperiod, slowmatype, signalperiod, signalmatype)
    return pd.Series(macd, index=Series.index), pd.Series(macdsignal, index=Series.index), pd.Series(macdhist, index=Series.index) 
Example #2
Source File: macdext.py    From jesse with MIT License 5 votes vote down vote up
def macdext(candles: np.ndarray, fastperiod=12, fastmatype=0, slowperiod=26, slowmatype=0, signalperiod=9,
            signalmatype=0, source_type="close", sequential=False) -> MACDEXT:
    """
    MACDEXT - MACD with controllable MA type

    :param candles: np.ndarray
    :param fastperiod: int - default: 12
    :param fastmatype: int - default: 0
    :param slow_period: int - default: 26
    :param slowmatype: int - default: 0
    :param signal_period: int - default: 9
    :param signalmatype: int - default: 0
    :param source_type: str - default: "close"
    :param sequential: bool - default: False

    :return: MACDEXT(macd, signal, hist)
    """
    if not sequential and len(candles) > 240:
        candles = candles[-240:]

    source = get_candle_source(candles, source_type=source_type)
    macd, macdsignal, macdhist = talib.MACDEXT(source, fastperiod=fastperiod, fastmatype=fastmatype,
                                               slowperiod=slowperiod, slowmatype=slowmatype,
                                               signalperiod=signalperiod, signalmatype=signalmatype)

    if sequential:
        return MACDEXT(macd, macdsignal, macdhist)
    else:
        return MACDEXT(macd[-1], macdsignal[-1], macdhist[-1]) 
Example #3
Source File: talib_indicators.py    From qtpylib with Apache License 2.0 5 votes vote down vote up
def MACDEXT(data, **kwargs):
    _check_talib_presence()
    prices = _extract_series(data)
    return talib.MACDEXT(prices, **kwargs) 
Example #4
Source File: ctaLineBar.py    From vnpy_crypto with MIT License 4 votes vote down vote up
def __recountMacd(self):
        """
        Macd计算方法:
        12日EMA的计算:EMA12 = 前一日EMA12 X 11/13 + 今日收盘 X 2/13
        26日EMA的计算:EMA26 = 前一日EMA26 X 25/27 + 今日收盘 X 2/27
        差离值(DIF)的计算: DIF = EMA12 - EMA26,即为talib-MACD返回值macd
        根据差离值计算其9日的EMA,即离差平均值,是所求的DEA值。
        今日DEA = (前一日DEA X 8/10 + 今日DIF X 2/10),即为talib-MACD返回值signal
        DIF与它自己的移动平均之间差距的大小一般BAR=(DIF-DEA)*2,即为MACD柱状图。
        但是talib中MACD的计算是bar = (dif-dea)*1
        """

        if self.inputMacdFastPeriodLen <= EMPTY_INT: return
        if self.inputMacdSlowPeriodLen <= EMPTY_INT: return
        if self.inputMacdSignalPeriodLen <= EMPTY_INT: return

        maxLen = max(self.inputMacdFastPeriodLen,self.inputMacdSlowPeriodLen)+self.inputMacdSignalPeriodLen+1

        #maxLen = maxLen * 3             # 注:数据长度需要足够,才能准确。测试过,3倍长度才可以与国内的文华等软件一致

        if len(self.lineBar) < maxLen:
            self.debugCtaLog(u'数据未充分,当前Bar数据数量:{0},计算MACD需要:{1}'.format(len(self.lineBar), maxLen))
            return

        if self.mode == self.TICK_MODE:
            listClose =[x.close for x in self.lineBar[-maxLen:-1]]
        else:
            listClose =[x.close for x in self.lineBar[-maxLen-1:]]

        dif, dea, macd = ta.MACD(np.array(listClose, dtype=float), fastperiod=self.inputMacdFastPeriodLen,
                       slowperiod=self.inputMacdSlowPeriodLen, signalperiod=self.inputMacdSignalPeriodLen)

        #dif, dea, macd = ta.MACDEXT(np.array(listClose, dtype=float),
        #                            fastperiod=self.inputMacdFastPeriodLen, fastmatype=1,
        #                            slowperiod=self.inputMacdSlowPeriodLen, slowmatype=1,
        #                            signalperiod=self.inputMacdSignalPeriodLen, signalmatype=1)

        if len(self.lineDif) > maxLen:
            del self.lineDif[0]
        self.lineDif.append(dif[-1])

        if len(self.lineDea) > maxLen:
            del self.lineDea[0]
        self.lineDea.append(dea[-1])

        if len(self.lineMacd) > maxLen:
            del self.lineMacd[0]
        self.lineMacd.append(macd[-1]*2)            # 国内一般是2倍 
Example #5
Source File: ta.py    From dash-technical-charting with MIT License 4 votes vote down vote up
def add_MACDEXT(self, fastperiod=12, fastmatype=0,
                slowperiod=26, slowmatype=0,
                signalperiod=9, signalmatype=0,
                types=['line', 'line', 'histogram'],
                colors=['primary', 'tertiary', 'fill'],
                **kwargs):
    """Moving Average Convergence Divergence with Controllable MA Type.

    Note that the first argument of types and colors refers to MACD,
    the second argument refers to MACD signal line and the third argument
    refers to MACD histogram.

    """
    if not self.has_close:
        raise Exception()

    utils.kwargs_check(kwargs, VALID_TA_KWARGS)
    if 'kind' in kwargs:
        kwargs['type'] = kwargs['kind']
    if 'kinds' in kwargs:
        types = kwargs['type']

    if 'type' in kwargs:
        types = [kwargs['type']] * 3
    if 'color' in kwargs:
        colors = [kwargs['color']] * 3

    name = 'MACDEXT({},{},{})'.format(str(fastperiod),
                                      str(slowperiod),
                                      str(signalperiod))
    macd = name
    smacd = name + '[Sign]'
    hmacd = name + '[Hist]'
    self.sec[macd] = dict(type=types[0], color=colors[0])
    self.sec[smacd] = dict(type=types[1], color=colors[1], on=macd)
    self.sec[hmacd] = dict(type=types[2], color=colors[2], on=macd)
    (self.ind[macd],
     self.ind[smacd],
     self.ind[hmacd]) = talib.MACDEXT(self.df[self.cl].values,
                                      fastperiod, fastmatype,
                                      slowperiod, slowmatype,
                                      signalperiod, signalmatype)