Esempio n. 1
0
    def bear_marubozu_gravestone(self, *args):
        def logic(r):
            if (np.all(self.array[loc[-1]] == self.array[-2])
                    and np.all(self.array[loc2[-1]] == self.array[-1])
                    # (self.array[-2][3] < r[0] and self.array[-2][0] > r[0]) and
                    # (self.array[-1][3] < r[1] and self.array[-2][1] > r[0])
                ):
                return 1
            return 0

        mar = talib.CDLMARUBOZU(self.o, self.h, self.l, self.c)
        grave = talib.CDLGRAVESTONEDOJI(self.o, self.h, self.l, self.c)

        try:
            loc, loc2 = np.where(mar == -100)[0], np.where(grave == 100)[0]
            if (loc.size or loc2.size) == 0 or (len(self.array) < 2):
                return 0
        except Exception:
            return 0

        finally:
            if self.ilist is None:
                r = self.iarray[-2:]
                return logic(r)

            for i in self.ilist:
                r = i[-2:]
                return logic(r)
Esempio n. 2
0
def get_cdlmarubozu(ohlc):
    cdlmarubozu = ta.CDLMARUBOZU(ohlc['1_open'], ohlc['2_high'], ohlc['3_low'],
                                 ohlc['4_close'])

    ohlc['cdlmarubozu'] = cdlmarubozu

    return ohlc
Esempio n. 3
0
def candle_patt(df,x,all_fig,params):
    '''ローソク足パターンのローソク足チャートへの描画'''
    
    # パターンチェック & シグナル値を描画用に置き換え
    df['Marubozu'] = ta.CDLMARUBOZU(df['Open'],df['High'],df['Low'],df['Close']) * df['High'] / 100
    df['Engulfing_Pattern'] = ta.CDLENGULFING(df['Open'],df['High'],df['Low'],df['High']) * df['Close'] / 100
    df['Hammer'] = ta.CDLHAMMER(df['Open'],df['High'],df['Low'],df['Close']) * df['High'] / 100
    df['Dragonfly_Doji'] = ta.CDLDRAGONFLYDOJI(df['Open'],df['High'],df['Low'],df['Close']) * df['High'] / 100    
    
    # 列名を作成
    pattern_list = list(df.loc[:,'Marubozu':'Dragonfly_Doji'].columns)
    label_list = [ k+'_label' for k in list(df.loc[:,'Marubozu':'Dragonfly_Doji'].columns)]
    
    # 0をNaNで埋める
    df[pattern_list] = df[pattern_list].where(~(df[pattern_list] == 0.0), np.nan)
        
    # 売り買いラベルの作成
    df[label_list] = df[pattern_list]
    df[label_list] = df[label_list].where(~(df[label_list] > 0), 1)
    df[label_list] = df[label_list].where(~(df[label_list] < 0), -1)
    df[label_list] = df[label_list].where(~(df[label_list] == 1), '買い')
    df[label_list] = df[label_list].where(~(df[label_list] == -1), '売り')
    
    # 発生価格の絶対値化
    df[pattern_list] = df[pattern_list].abs()
    
    # 各シグナルを描画
    for pattern in list(df.loc[:,'Marubozu':'Dragonfly_Doji'].columns):
        all_fig.add_trace(go.Scatter(x=x, y=df[pattern],mode='markers+text',text=df[label_list],textposition="top center",name=pattern,
                                    marker = dict(size = 9),opacity=0.8),row=1, col=1)
    
    return all_fig
Esempio n. 4
0
 def marubozu(self):
     """
     名称:Marubozu 光头光脚/缺影线
     简介:一日K线模式,上下两头都没有影线的实体,阴线预示着熊市持续或者牛市反转,阳线相反。
     """
     result = talib.CDLMARUBOZU(open=np.array(self.dataframe['open']),
                                high=np.array(self.dataframe['high']),
                                low=np.array(self.dataframe['low']),
                                close=np.array(self.dataframe['close']))
     self.dataframe['marubozu'] = result
Esempio n. 5
0
    def bear_marubozu_up_cross_snr(self, *args):
        ham = talib.CDLMARUBOZU(self.o, self.h, self.l, self.c)
        idx = np.where(ham == 100)[0]

        o = []
        for x in idx:
            if True:
                o.append(x)
        a = np.zeros(len(self.o))
        a[o] = 1
        return a
Esempio n. 6
0
def CDLMARUBOZU(open, high, low, close):
    ''' Marubozu 光头光脚/缺影线

    分组: Pattern Recognition 形态识别

    简介: 一日K线模式,上下两头都没有影线的实体,
    阴线预示着熊市持续或者牛市反转,阳线相反。

    integer = CDLMARUBOZU(open, high, low, close)
    '''
    return talib.CDLMARUBOZU(open, high, low, close)
Esempio n. 7
0
    def marubozu(self, sym, frequency):
        if not self.kbars_ready(sym, frequency):
            return []

        opens = self.open(sym, frequency)
        highs = self.high(sym, frequency)
        lows = self.low(sym, frequency)
        closes = self.close(sym, frequency)

        cdl = ta.CDLMARUBOZU(opens, highs, lows, closes)

        return cdl
Esempio n. 8
0
    def bear_marubozu_dragonfly(self, *args):

        ham = talib.CDLMARUBOZU(self.o, self.h, self.l, self.c)
        dragon = talib.CDLDRAGONFLYDOJI(self.o, self.h, self.l, self.c)
        idx = np.where(ham == -100)[0]
        idx1 = np.where(dragon == 100)[0]

        o = []
        for x in idx1:
            if x - 1 in idx and self.array[x][0] == self.array[x][-1]:
                o.append(x)
        a = np.zeros(len(self.o))
        a[o] = 1
        return a
Esempio n. 9
0
    def bull_marubozu_shootingStar_Marubozu(self, *args):

        mar = talib.CDLMARUBOZU(self.o, self.h, self.l, self.c)
        star = talib.CDLSHOOTINGSTAR(self.o, self.h, self.l, self.c)

        idx = np.where(mar == 100)[0]
        idx1 = np.where(star == -100)[0]

        o = []
        for x in idx:
            if x - 1 in idx1 and x - 2 in idx:
                o.append(x)
        a = np.zeros(len(self.o))
        a[o] = 1
        return a
Esempio n. 10
0
    def bull_gMarubozu_rMarubozu_green_top_wick(self, *args):

        mar = talib.CDLMARUBOZU(self.o, self.h, self.l, self.c)
        eng = talib.CDLENGULFING(self.o, self.h, self.l, self.c)
        idx = np.where(mar == 100)[0]
        idx3 = np.where(eng == 100)[0]

        o = []

        for x in idx3:
            if x - 2 in idx:
                o.append(x)

        a = np.zeros(len(self.o))
        a[o] = 1
        return a
Esempio n. 11
0
    def bear_GmarubozuTwice_gravestone(self, *args):

        mar = talib.CDLMARUBOZU(self.o, self.h, self.l, self.c)
        grave = talib.CDLGRAVESTONEDOJI(self.o, self.h, self.l, self.c)

        idx = np.where(mar == 100)[0]
        idx1 = np.where(grave == 100)[0]

        o = []

        for x in idx1:
            if x - 1 in idx and x - 2 in idx:
                o.append(x)
        a = np.zeros(len(self.o))
        a[o] = 1
        return a
Esempio n. 12
0
    def bullRmarubozuTwice_Dragonfly(self, *args):

        mar = talib.CDLMARUBOZU(self.o, self.h, self.l, self.c)
        dra = talib.CDLDRAGONFLYDOJI(self.o, self.h, self.l, self.c)

        idx = np.where(mar == -100)[0]
        idx1 = np.where(dra == 100)[0]

        o = []

        for x in idx1:
            if x - 1 in idx and x - 2 in idx:
                o.append(x)
        a = np.zeros(len(self.o))
        a[o] = 1
        return a
Esempio n. 13
0
    def bear_Rmarubozu_Takuri_Rmarubozu(self, *args):

        mar = talib.CDLMARUBOZU(self.o, self.h, self.l, self.c)
        ham = talib.CDLHAMMER(self.o, self.h, self.l, self.c)

        idx = np.where(mar == -100)[0]
        idx1 = np.where(ham == 100)[0]

        o = []

        for x in idx:
            if (x - 1 in idx1 and x - 2 in idx and self.check_status(
                    self.array[x - 2][0], self.array[x - 2][-1]) == "Bearish"):
                o.append(x)
        a = np.zeros(len(self.o))
        a[o] = 1
        return a
Esempio n. 14
0
    def bear_marubozu_touch_doji(self, *args):
        ham = talib.CDLMARUBOZU(self.o, self.h, self.l, self.c)
        doji = talib.CDLDOJI(self.o, self.h, self.l, self.c)
        idx = np.where(ham == 100)[0]
        idx1 = np.where(doji == 100)[0]

        o = []
        for x in idx1:
            try:
                if (x - 1 in idx
                        and self.array[x - 1][1] != self.array[x - 1][-1]
                        and self.array[x - 1][2] == self.array[x - 1][0]):
                    o.append(x)
            except Exception:
                pass
        a = np.zeros(len(self.o))
        a[o] = 1
        return a
Esempio n. 15
0
    def bull_marubozu_dragonfly(self, *args):

        ham = talib.CDLMARUBOZU(self.o, self.h, self.l, self.c)
        dra = talib.CDLDRAGONFLYDOJI(self.o, self.h, self.l, self.c)

        idx = np.where(ham == 100)[0]
        idx2 = np.where(dra == 100)[0]

        o = []
        for x in idx2:
            try:
                if x - 1 in idx and self.array[x][0] == self.array[x][-1]:
                    o.append(x)
            except Exception:
                continue
        a = np.zeros(len(self.o))
        a[o] = 1
        return a
Esempio n. 16
0
    def __draw_chart(self, ohlc, fdate, ddate):
        fig, (axT, axB) = plt.subplots(nrows=2, sharex=True)

        open = np.asarray(ohlc)[:, 1]
        high = np.asarray(ohlc)[:, 2]
        low = np.asarray(ohlc)[:, 3]
        close = np.asarray(ohlc)[:, 4]
        step = int(len(close) / 5)

        # graph上のfloat型の日付と、表示文字列を紐付けている
        plt.xticks(fdate[::step],
                   [x.strftime('%Y-%m-%d') for x in ddate][::step])

        #ax = axT.subplot()
        candlestick_ohlc(axT, ohlc)

        # 5 日単純移動平均を求める
        #sma5 = ta.SMA(close, timeperiod=5)
        #plt.plot(sma5,label="SMA5")

        axT.plot(ta.HT_TRENDLINE(close), label="TRENDLINE")

        # trendline
        #line=self.interpolation(100,200,3000,3500,len(close))
        #plt.plot(line,label="line")

        ret = ta.CDL2CROWS(open, high, low, close)
        print ret
        ret = ta.CDLMARUBOZU(open, high, low, close)
        print ret

        axT.set_xlabel('Date')
        axT.set_ylabel('Price')
        axT.set_title("title")
        axT.legend()

        macd, macdsignal, macdhist = ta.MACD(close)

        axB.plot(macd, label="MACD")
        axB.plot(macdhist, label="MACD-Hist")
        axB.plot(macdsignal, label="MACD-Signal")
        axB.set_xlabel("Date")
        axB.legend()
        plt.show()
Esempio n. 17
0
    def bear_RinvertedHammer_Marubozu_doji(self, *args):

        mar = talib.CDLMARUBOZU(self.o, self.h, self.l, self.c)
        inv = talib.CDLINVERTEDHAMMER(self.o, self.h, self.l, self.c)
        doji = talib.CDLDOJI(self.o, self.h, self.l, self.c)

        idx = np.where(mar == 100)[0]
        idx1 = np.where(inv == 100)[0]
        idx2 = np.where(doji == 100)[0]

        o = []

        for x in idx2:
            if (x - 1 in idx and x - 2 in idx1 and self.check_status(
                    self.array[x - 2][0], self.array[x - 2][-1]) == "Bearish"):
                o.append(x)
        a = np.zeros(len(self.o))
        a[o] = 1
        return a
Esempio n. 18
0
    def bull_marubozu_gravestone(self, *args):

        ham = talib.CDLMARUBOZU(self.o, self.h, self.l, self.c)
        grave = talib.CDLGRAVESTONEDOJI(self.o, self.h, self.l, self.c)
        idx = np.where(ham == 100)[0]
        idx1 = np.where(grave == 100)[0]

        o = []
        for x in idx1:
            try:
                if (x - 1 in idx and self.array[x][0] == self.array[x][-1]
                        and self.array[x - 1][-1] == self.array[x][-1]
                        and self.array[x][2] == self.array[x][-1]):
                    o.append(x)
            except Exception:
                pass
        a = np.zeros(len(self.o))
        a[o] = 1
        return a
Esempio n. 19
0
    def bull_Gtakuri_Rmarubozu_doji(self, *args):

        hang = talib.CDLTAKURI(self.o, self.h, self.l, self.c)
        mar = talib.CDLMARUBOZU(self.o, self.h, self.l, self.c)
        star = talib.CDLDOJISTAR(self.o, self.h, self.l, self.c)

        idx = np.where(hang == 100)[0]
        idx1 = np.where(mar == -100)[0]
        idx2 = np.where(star == 100)[0]

        o = []

        for x in idx2:
            if (x - 1 in idx1 and x - 2 in idx and self.check_status(
                    self.array[x - 2][0], self.array[x - 2][-1]) == "Bullish"):
                o.append(x)
        a = np.zeros(len(self.o))
        a[o] = 1
        return a
Esempio n. 20
0
    def bear_Gmarubozu_invertedHammer_Ghammer(self, *args):

        mar = talib.CDLMARUBOZU(self.o, self.h, self.l, self.c)
        ham = talib.CDLHAMMER(self.o, self.h, self.l, self.c)
        inv = talib.CDLSHOOTINGSTAR(self.o, self.h, self.l, self.c)

        idx = np.where(mar == 100)[0]
        idx1 = np.where(ham == 100)[0]
        idx2 = np.where(inv == 100)[0]

        o = []

        for x in idx1:
            if (x - 1 in idx2 and x - 2 in idx and self.check_status(
                    self.array[x - 1][0], self.array[x - 1][-1]) == "Bullish"
                    and self.check_status(self.array[x][0],
                                          self.array[x][-1]) == "Bullish"):
                o.append(x)
        a = np.zeros(len(self.o))
        a[o] = 1
        return a
Esempio n. 21
0
    def bull_marubozu_gravestone_dragonfly(self, *args):
        ham = talib.CDLMARUBOZU(self.o, self.h, self.l, self.c)
        gra = talib.CDLGRAVESTONEDOJI(self.o, self.h, self.l, self.c)
        dra = talib.CDLDRAGONFLYDOJI(self.o, self.h, self.l, self.c)

        idx = np.where(ham == 100)[0]
        idx2 = np.where(gra == 100)[0]
        idx3 = np.where(dra == 100)[0]

        o = []
        for x in idx3:
            try:
                if (x - 1 in idx2 and x - 2 in idx
                        and self.array[x - 2][0] == self.array[x - 2][-1]
                        and self.array[x - 1][0] == self.array[x - 1][-1]):
                    o.append(x)
            except Exception:
                continue
        a = np.zeros(len(self.o))
        a[o] = 1
        return a
def findTAPattern(df, patternName):
    if patternName == '2CROWS':
        df[patternName] = talib.CDL2CROWS(df.Open.values, df.High.values,
                                          df.Low.values, df.Close.values)
    elif patternName == 'DOJI':
        df[patternName] = talib.CDLDOJI(df.Open.values, df.High.values,
                                        df.Low.values, df.Close.values)
    elif patternName == 'ENGULFING':
        df[patternName] = talib.CDLENGULFING(df.Open.values, df.High.values,
                                             df.Low.values, df.Close.values)
    elif patternName == 'EVENINGSTAR':
        df[patternName] = talib.CDLEVENINGSTAR(df.Open.values, df.High.values,
                                               df.Low.values, df.Close.values)
    elif patternName == 'MARUBOZU':
        df[patternName] = talib.CDLMARUBOZU(df.Open.values, df.High.values,
                                            df.Low.values, df.Close.values)
    else:
        print('Pattern not supported yet')

    patterned_df = df[df[patternName] != 0]
    return patterned_df
    print(patterned_df)
Esempio n. 23
0
    def bear_invertedHammer_marubozu_rHammer(self, *args):
        ham = talib.CDLINVERTEDHAMMER(self.o, self.h, self.l, self.c)
        mar = talib.CDLMARUBOZU(self.o, self.h, self.l, self.c)
        red = talib.CDLHAMMER(self.o, self.h, self.l, self.c)

        idx = np.where(ham == 100)[0]
        idx1 = np.where(mar == 100)[0]
        idx2 = np.where(red == 100)[0]

        o = []
        for x in idx2:
            try:
                if (x - 1 in idx1 and x - 2 in idx and self.check_status(
                        self.array[x - 2][0], self.array[x - 2][-1])
                        == "Bullish" and self.check_status(
                            self.array[x][0], self.array[x][-1]) == "Bearish"):
                    o.append(x)
            except Exception:
                pass
        a = np.zeros(len(self.o))
        a[o] = 1
        return a
def CDLMARUBOZU(DataFrame):
    res = talib.CDLMARUBOZU(DataFrame.open.values, DataFrame.high.values,
                            DataFrame.low.values, DataFrame.close.values)
    return pd.DataFrame({'CDLMARUBOZU': res}, index=DataFrame.index)
Esempio n. 25
0
    def calculate(self, para):

        self.t = self.inputdata[:, 0]
        self.op = self.inputdata[:, 1]
        self.high = self.inputdata[:, 2]
        self.low = self.inputdata[:, 3]
        self.close = self.inputdata[:, 4]
        #adjusted close
        self.close1 = self.inputdata[:, 5]
        self.volume = self.inputdata[:, 6]
        #Overlap study

        #Overlap Studies
        #Overlap Studies
        if para is 'BBANDS':  #Bollinger Bands
            upperband, middleband, lowerband = ta.BBANDS(self.close,
                                                         timeperiod=self.tp,
                                                         nbdevup=2,
                                                         nbdevdn=2,
                                                         matype=0)
            self.output = [upperband, middleband, lowerband]

        elif para is 'DEMA':  #Double Exponential Moving Average
            self.output = ta.DEMA(self.close, timeperiod=self.tp)

        elif para is 'EMA':  #Exponential Moving Average
            self.output = ta.EMA(self.close, timeperiod=self.tp)

        elif para is 'HT_TRENDLINE':  #Hilbert Transform - Instantaneous Trendline
            self.output = ta.HT_TRENDLINE(self.close)

        elif para is 'KAMA':  #Kaufman Adaptive Moving Average
            self.output = ta.KAMA(self.close, timeperiod=self.tp)

        elif para is 'MA':  #Moving average
            self.output = ta.MA(self.close, timeperiod=self.tp, matype=0)

        elif para is 'MAMA':  #MESA Adaptive Moving Average
            mama, fama = ta.MAMA(self.close, fastlimit=0, slowlimit=0)

        elif para is 'MAVP':  #Moving average with variable period
            self.output = ta.MAVP(self.close,
                                  periods=10,
                                  minperiod=self.tp,
                                  maxperiod=self.tp1,
                                  matype=0)

        elif para is 'MIDPOINT':  #MidPoint over period
            self.output = ta.MIDPOINT(self.close, timeperiod=self.tp)

        elif para is 'MIDPRICE':  #Midpoint Price over period
            self.output = ta.MIDPRICE(self.high, self.low, timeperiod=self.tp)

        elif para is 'SAR':  #Parabolic SAR
            self.output = ta.SAR(self.high,
                                 self.low,
                                 acceleration=0,
                                 maximum=0)

        elif para is 'SAREXT':  #Parabolic SAR - Extended
            self.output = ta.SAREXT(self.high,
                                    self.low,
                                    startvalue=0,
                                    offsetonreverse=0,
                                    accelerationinitlong=0,
                                    accelerationlong=0,
                                    accelerationmaxlong=0,
                                    accelerationinitshort=0,
                                    accelerationshort=0,
                                    accelerationmaxshort=0)

        elif para is 'SMA':  #Simple Moving Average
            self.output = ta.SMA(self.close, timeperiod=self.tp)

        elif para is 'T3':  #Triple Exponential Moving Average (T3)
            self.output = ta.T3(self.close, timeperiod=self.tp, vfactor=0)

        elif para is 'TEMA':  #Triple Exponential Moving Average
            self.output = ta.TEMA(self.close, timeperiod=self.tp)

        elif para is 'TRIMA':  #Triangular Moving Average
            self.output = ta.TRIMA(self.close, timeperiod=self.tp)

        elif para is 'WMA':  #Weighted Moving Average
            self.output = ta.WMA(self.close, timeperiod=self.tp)

        #Momentum Indicators
        elif para is 'ADX':  #Average Directional Movement Index
            self.output = ta.ADX(self.high,
                                 self.low,
                                 self.close,
                                 timeperiod=self.tp)

        elif para is 'ADXR':  #Average Directional Movement Index Rating
            self.output = ta.ADXR(self.high,
                                  self.low,
                                  self.close,
                                  timeperiod=self.tp)

        elif para is 'APO':  #Absolute Price Oscillator
            self.output = ta.APO(self.close,
                                 fastperiod=12,
                                 slowperiod=26,
                                 matype=0)

        elif para is 'AROON':  #Aroon
            aroondown, aroonup = ta.AROON(self.high,
                                          self.low,
                                          timeperiod=self.tp)
            self.output = [aroondown, aroonup]

        elif para is 'AROONOSC':  #Aroon Oscillator
            self.output = ta.AROONOSC(self.high, self.low, timeperiod=self.tp)

        elif para is 'BOP':  #Balance Of Power
            self.output = ta.BOP(self.op, self.high, self.low, self.close)

        elif para is 'CCI':  #Commodity Channel Index
            self.output = ta.CCI(self.high,
                                 self.low,
                                 self.close,
                                 timeperiod=self.tp)

        elif para is 'CMO':  #Chande Momentum Oscillator
            self.output = ta.CMO(self.close, timeperiod=self.tp)

        elif para is 'DX':  #Directional Movement Index
            self.output = ta.DX(self.high,
                                self.low,
                                self.close,
                                timeperiod=self.tp)

        elif para is 'MACD':  #Moving Average Convergence/Divergence
            macd, macdsignal, macdhist = ta.MACD(self.close,
                                                 fastperiod=12,
                                                 slowperiod=26,
                                                 signalperiod=9)
            self.output = [macd, macdsignal, macdhist]
        elif para is 'MACDEXT':  #MACD with controllable MA type
            macd, macdsignal, macdhist = ta.MACDEXT(self.close,
                                                    fastperiod=12,
                                                    fastmatype=0,
                                                    slowperiod=26,
                                                    slowmatype=0,
                                                    signalperiod=9,
                                                    signalmatype=0)
            self.output = [macd, macdsignal, macdhist]
        elif para is 'MACDFIX':  #Moving Average Convergence/Divergence Fix 12/26
            macd, macdsignal, macdhist = ta.MACDFIX(self.close, signalperiod=9)
            self.output = [macd, macdsignal, macdhist]
        elif para is 'MFI':  #Money Flow Index
            self.output = ta.MFI(self.high,
                                 self.low,
                                 self.close,
                                 self.volume,
                                 timeperiod=self.tp)

        elif para is 'MINUS_DI':  #Minus Directional Indicator
            self.output = ta.MINUS_DI(self.high,
                                      self.low,
                                      self.close,
                                      timeperiod=self.tp)

        elif para is 'MINUS_DM':  #Minus Directional Movement
            self.output = ta.MINUS_DM(self.high, self.low, timeperiod=self.tp)

        elif para is 'MOM':  #Momentum
            self.output = ta.MOM(self.close, timeperiod=10)

        elif para is 'PLUS_DI':  #Plus Directional Indicator
            self.output = ta.PLUS_DI(self.high,
                                     self.low,
                                     self.close,
                                     timeperiod=self.tp)

        elif para is 'PLUS_DM':  #Plus Directional Movement
            self.output = ta.PLUS_DM(self.high, self.low, timeperiod=self.tp)

        elif para is 'PPO':  #Percentage Price Oscillator
            self.output = ta.PPO(self.close,
                                 fastperiod=12,
                                 slowperiod=26,
                                 matype=0)

        elif para is 'ROC':  #Rate of change : ((price/prevPrice)-1)*100
            self.output = ta.ROC(self.close, timeperiod=10)

        elif para is 'ROCP':  #Rate of change Percentage: (price-prevPrice)/prevPrice
            self.output = ta.ROCP(self.close, timeperiod=10)

        elif para is 'ROCR':  #Rate of change ratio: (price/prevPrice)
            self.output = ta.ROCR(self.close, timeperiod=10)

        elif para is 'ROCR100':  #Rate of change ratio 100 scale: (price/prevPrice)*100
            self.output = ta.ROCR100(self.close, timeperiod=10)

        elif para is 'RSI':  #Relative Strength Index
            self.output = ta.RSI(self.close, timeperiod=self.tp)

        elif para is 'STOCH':  #Stochastic
            slowk, slowd = ta.STOCH(self.high,
                                    self.low,
                                    self.close,
                                    fastk_period=5,
                                    slowk_period=3,
                                    slowk_matype=0,
                                    slowd_period=3,
                                    slowd_matype=0)
            self.output = [slowk, slowd]

        elif para is 'STOCHF':  #Stochastic Fast
            fastk, fastd = ta.STOCHF(self.high,
                                     self.low,
                                     self.close,
                                     fastk_period=5,
                                     fastd_period=3,
                                     fastd_matype=0)
            self.output = [fastk, fastd]

        elif para is 'STOCHRSI':  #Stochastic Relative Strength Index
            fastk, fastd = ta.STOCHRSI(self.close,
                                       timeperiod=self.tp,
                                       fastk_period=5,
                                       fastd_period=3,
                                       fastd_matype=0)
            self.output = [fastk, fastd]

        elif para is 'TRIX':  #1-day Rate-Of-Change (ROC) of a Triple Smooth EMA
            self.output = ta.TRIX(self.close, timeperiod=self.tp)

        elif para is 'ULTOSC':  #Ultimate Oscillator
            self.output = ta.ULTOSC(self.high,
                                    self.low,
                                    self.close,
                                    timeperiod1=self.tp,
                                    timeperiod2=self.tp1,
                                    timeperiod3=self.tp2)

        elif para is 'WILLR':  #Williams' %R
            self.output = ta.WILLR(self.high,
                                   self.low,
                                   self.close,
                                   timeperiod=self.tp)

        # Volume Indicators    : #
        elif para is 'AD':  #Chaikin A/D Line
            self.output = ta.AD(self.high, self.low, self.close, self.volume)

        elif para is 'ADOSC':  #Chaikin A/D Oscillator
            self.output = ta.ADOSC(self.high,
                                   self.low,
                                   self.close,
                                   self.volume,
                                   fastperiod=3,
                                   slowperiod=10)

        elif para is 'OBV':  #On Balance Volume
            self.output = ta.OBV(self.close, self.volume)

    # Volatility Indicators: #
        elif para is 'ATR':  #Average True Range
            self.output = ta.ATR(self.high,
                                 self.low,
                                 self.close,
                                 timeperiod=self.tp)

        elif para is 'NATR':  #Normalized Average True Range
            self.output = ta.NATR(self.high,
                                  self.low,
                                  self.close,
                                  timeperiod=self.tp)

        elif para is 'TRANGE':  #True Range
            self.output = ta.TRANGE(self.high, self.low, self.close)

        #Price Transform      : #
        elif para is 'AVGPRICE':  #Average Price
            self.output = ta.AVGPRICE(self.op, self.high, self.low, self.close)

        elif para is 'MEDPRICE':  #Median Price
            self.output = ta.MEDPRICE(self.high, self.low)

        elif para is 'TYPPRICE':  #Typical Price
            self.output = ta.TYPPRICE(self.high, self.low, self.close)

        elif para is 'WCLPRICE':  #Weighted Close Price
            self.output = ta.WCLPRICE(self.high, self.low, self.close)

        #Cycle Indicators     : #
        elif para is 'HT_DCPERIOD':  #Hilbert Transform - Dominant Cycle Period
            self.output = ta.HT_DCPERIOD(self.close)

        elif para is 'HT_DCPHASE':  #Hilbert Transform - Dominant Cycle Phase
            self.output = ta.HT_DCPHASE(self.close)

        elif para is 'HT_PHASOR':  #Hilbert Transform - Phasor Components
            inphase, quadrature = ta.HT_PHASOR(self.close)
            self.output = [inphase, quadrature]

        elif para is 'HT_SINE':  #Hilbert Transform - SineWave #2
            sine, leadsine = ta.HT_SINE(self.close)
            self.output = [sine, leadsine]

        elif para is 'HT_TRENDMODE':  #Hilbert Transform - Trend vs Cycle Mode
            self.integer = ta.HT_TRENDMODE(self.close)

        #Pattern Recognition  : #
        elif para is 'CDL2CROWS':  #Two Crows
            self.integer = ta.CDL2CROWS(self.op, self.high, self.low,
                                        self.close)

        elif para is 'CDL3BLACKCROWS':  #Three Black Crows
            self.integer = ta.CDL3BLACKCROWS(self.op, self.high, self.low,
                                             self.close)

        elif para is 'CDL3INSIDE':  #Three Inside Up/Down
            self.integer = ta.CDL3INSIDE(self.op, self.high, self.low,
                                         self.close)

        elif para is 'CDL3LINESTRIKE':  #Three-Line Strike
            self.integer = ta.CDL3LINESTRIKE(self.op, self.high, self.low,
                                             self.close)

        elif para is 'CDL3OUTSIDE':  #Three Outside Up/Down
            self.integer = ta.CDL3OUTSIDE(self.op, self.high, self.low,
                                          self.close)

        elif para is 'CDL3STARSINSOUTH':  #Three Stars In The South
            self.integer = ta.CDL3STARSINSOUTH(self.op, self.high, self.low,
                                               self.close)

        elif para is 'CDL3WHITESOLDIERS':  #Three Advancing White Soldiers
            self.integer = ta.CDL3WHITESOLDIERS(self.op, self.high, self.low,
                                                self.close)

        elif para is 'CDLABANDONEDBABY':  #Abandoned Baby
            self.integer = ta.CDLABANDONEDBABY(self.op,
                                               self.high,
                                               self.low,
                                               self.close,
                                               penetration=0)

        elif para is 'CDLBELTHOLD':  #Belt-hold
            self.integer = ta.CDLBELTHOLD(self.op, self.high, self.low,
                                          self.close)

        elif para is 'CDLBREAKAWAY':  #Breakaway
            self.integer = ta.CDLBREAKAWAY(self.op, self.high, self.low,
                                           self.close)

        elif para is 'CDLCLOSINGMARUBOZU':  #Closing Marubozu
            self.integer = ta.CDLCLOSINGMARUBOZU(self.op, self.high, self.low,
                                                 self.close)

        elif para is 'CDLCONCEALBABYSWALL':  #Concealing Baby Swallow
            self.integer = ta.CDLCONCEALBABYSWALL(self.op, self.high, self.low,
                                                  self.close)

        elif para is 'CDLCOUNTERATTACK':  #Counterattack
            self.integer = ta.CDLCOUNTERATTACK(self.op, self.high, self.low,
                                               self.close)

        elif para is 'CDLDARKCLOUDCOVER':  #Dark Cloud Cover
            self.integer = ta.CDLDARKCLOUDCOVER(self.op,
                                                self.high,
                                                self.low,
                                                self.close,
                                                penetration=0)

        elif para is 'CDLDOJI':  #Doji
            self.integer = ta.CDLDOJI(self.op, self.high, self.low, self.close)

        elif para is 'CDLDOJISTAR':  #Doji Star
            self.integer = ta.CDLDOJISTAR(self.op, self.high, self.low,
                                          self.close)

        elif para is 'CDLDRAGONFLYDOJI':  #Dragonfly Doji
            self.integer = ta.CDLDRAGONFLYDOJI(self.op, self.high, self.low,
                                               self.close)

        elif para is 'CDLENGULFING':  #Engulfing Pattern
            self.integer = ta.CDLENGULFING(self.op, self.high, self.low,
                                           self.close)

        elif para is 'CDLEVENINGDOJISTAR':  #Evening Doji Star
            self.integer = ta.CDLEVENINGDOJISTAR(self.op,
                                                 self.high,
                                                 self.low,
                                                 self.close,
                                                 penetration=0)

        elif para is 'CDLEVENINGSTAR':  #Evening Star
            self.integer = ta.CDLEVENINGSTAR(self.op,
                                             self.high,
                                             self.low,
                                             self.close,
                                             penetration=0)

        elif para is 'CDLGAPSIDESIDEWHITE':  #Up/Down-gap side-by-side white lines
            self.integer = ta.CDLGAPSIDESIDEWHITE(self.op, self.high, self.low,
                                                  self.close)

        elif para is 'CDLGRAVESTONEDOJI':  #Gravestone Doji
            self.integer = ta.CDLGRAVESTONEDOJI(self.op, self.high, self.low,
                                                self.close)

        elif para is 'CDLHAMMER':  #Hammer
            self.integer = ta.CDLHAMMER(self.op, self.high, self.low,
                                        self.close)

        elif para is 'CDLHANGINGMAN':  #Hanging Man
            self.integer = ta.CDLHANGINGMAN(self.op, self.high, self.low,
                                            self.close)

        elif para is 'CDLHARAMI':  #Harami Pattern
            self.integer = ta.CDLHARAMI(self.op, self.high, self.low,
                                        self.close)

        elif para is 'CDLHARAMICROSS':  #Harami Cross Pattern
            self.integer = ta.CDLHARAMICROSS(self.op, self.high, self.low,
                                             self.close)

        elif para is 'CDLHIGHWAVE':  #High-Wave Candle
            self.integer = ta.CDLHIGHWAVE(self.op, self.high, self.low,
                                          self.close)

        elif para is 'CDLHIKKAKE':  #Hikkake Pattern
            self.integer = ta.CDLHIKKAKE(self.op, self.high, self.low,
                                         self.close)

        elif para is 'CDLHIKKAKEMOD':  #Modified Hikkake Pattern
            self.integer = ta.CDLHIKKAKEMOD(self.op, self.high, self.low,
                                            self.close)

        elif para is 'CDLHOMINGPIGEON':  #Homing Pigeon
            self.integer = ta.CDLHOMINGPIGEON(self.op, self.high, self.low,
                                              self.close)

        elif para is 'CDLIDENTICAL3CROWS':  #Identical Three Crows
            self.integer = ta.CDLIDENTICAL3CROWS(self.op, self.high, self.low,
                                                 self.close)

        elif para is 'CDLINNECK':  #In-Neck Pattern
            self.integer = ta.CDLINNECK(self.op, self.high, self.low,
                                        self.close)

        elif para is 'CDLINVERTEDHAMMER':  #Inverted Hammer
            self.integer = ta.CDLINVERTEDHAMMER(self.op, self.high, self.low,
                                                self.close)

        elif para is 'CDLKICKING':  #Kicking
            self.integer = ta.CDLKICKING(self.op, self.high, self.low,
                                         self.close)

        elif para is 'CDLKICKINGBYLENGTH':  #Kicking - bull/bear determined by the longer marubozu
            self.integer = ta.CDLKICKINGBYLENGTH(self.op, self.high, self.low,
                                                 self.close)

        elif para is 'CDLLADDERBOTTOM':  #Ladder Bottom
            self.integer = ta.CDLLADDERBOTTOM(self.op, self.high, self.low,
                                              self.close)

        elif para is 'CDLLONGLEGGEDDOJI':  #Long Legged Doji
            self.integer = ta.CDLLONGLEGGEDDOJI(self.op, self.high, self.low,
                                                self.close)

        elif para is 'CDLLONGLINE':  #Long Line Candle
            self.integer = ta.CDLLONGLINE(self.op, self.high, self.low,
                                          self.close)

        elif para is 'CDLMARUBOZU':  #Marubozu
            self.integer = ta.CDLMARUBOZU(self.op, self.high, self.low,
                                          self.close)

        elif para is 'CDLMATCHINGLOW':  #Matching Low
            self.integer = ta.CDLMATCHINGLOW(self.op, self.high, self.low,
                                             self.close)

        elif para is 'CDLMATHOLD':  #Mat Hold
            self.integer = ta.CDLMATHOLD(self.op,
                                         self.high,
                                         self.low,
                                         self.close,
                                         penetration=0)

        elif para is 'CDLMORNINGDOJISTAR':  #Morning Doji Star
            self.integer = ta.CDLMORNINGDOJISTAR(self.op,
                                                 self.high,
                                                 self.low,
                                                 self.close,
                                                 penetration=0)

        elif para is 'CDLMORNINGSTAR':  #Morning Star
            self.integer = ta.CDLMORNINGSTAR(self.op,
                                             self.high,
                                             self.low,
                                             self.close,
                                             penetration=0)

        elif para is 'CDLONNECK':  #On-Neck Pattern
            self.integer = ta.CDLONNECK(self.op, self.high, self.low,
                                        self.close)

        elif para is 'CDLPIERCING':  #Piercing Pattern
            self.integer = ta.CDLPIERCING(self.op, self.high, self.low,
                                          self.close)

        elif para is 'CDLRICKSHAWMAN':  #Rickshaw Man
            self.integer = ta.CDLRICKSHAWMAN(self.op, self.high, self.low,
                                             self.close)

        elif para is 'CDLRISEFALL3METHODS':  #Rising/Falling Three Methods
            self.integer = ta.CDLRISEFALL3METHODS(self.op, self.high, self.low,
                                                  self.close)

        elif para is 'CDLSEPARATINGLINES':  #Separating Lines
            self.integer = ta.CDLSEPARATINGLINES(self.op, self.high, self.low,
                                                 self.close)

        elif para is 'CDLSHOOTINGSTAR':  #Shooting Star
            self.integer = ta.CDLSHOOTINGSTAR(self.op, self.high, self.low,
                                              self.close)

        elif para is 'CDLSHORTLINE':  #Short Line Candle
            self.integer = ta.CDLSHORTLINE(self.op, self.high, self.low,
                                           self.close)

        elif para is 'CDLSPINNINGTOP':  #Spinning Top
            self.integer = ta.CDLSPINNINGTOP(self.op, self.high, self.low,
                                             self.close)

        elif para is 'CDLSTALLEDPATTERN':  #Stalled Pattern
            self.integer = ta.CDLSTALLEDPATTERN(self.op, self.high, self.low,
                                                self.close)

        elif para is 'CDLSTICKSANDWICH':  #Stick Sandwich
            self.integer = ta.CDLSTICKSANDWICH(self.op, self.high, self.low,
                                               self.close)

        elif para is 'CDLTAKURI':  #Takuri (Dragonfly Doji with very long lower shadow)
            self.integer = ta.CDLTAKURI(self.op, self.high, self.low,
                                        self.close)

        elif para is 'CDLTASUKIGAP':  #Tasuki Gap
            self.integer = ta.CDLTASUKIGAP(self.op, self.high, self.low,
                                           self.close)

        elif para is 'CDLTHRUSTING':  #Thrusting Pattern
            self.integer = ta.CDLTHRUSTING(self.op, self.high, self.low,
                                           self.close)

        elif para is 'CDLTRISTAR':  #Tristar Pattern
            self.integer = ta.CDLTRISTAR(self.op, self.high, self.low,
                                         self.close)

        elif para is 'CDLUNIQUE3RIVER':  #Unique 3 River
            self.integer = ta.CDLUNIQUE3RIVER(self.op, self.high, self.low,
                                              self.close)

        elif para is 'CDLUPSIDEGAP2CROWS':  #Upside Gap Two Crows
            self.integer = ta.CDLUPSIDEGAP2CROWS(self.op, self.high, self.low,
                                                 self.close)

        elif para is 'CDLXSIDEGAP3METHODS':  #Upside/Downside Gap Three Methods
            self.integer = ta.CDLXSIDEGAP3METHODS(self.op, self.high, self.low,
                                                  self.close)

        #Statistic Functions  : #
        elif para is 'BETA':  #Beta
            self.output = ta.BETA(self.high, self.low, timeperiod=5)

        elif para is 'CORREL':  #Pearson's Correlation Coefficient (r)
            self.output = ta.CORREL(self.high, self.low, timeperiod=self.tp)

        elif para is 'LINEARREG':  #Linear Regression
            self.output = ta.LINEARREG(self.close, timeperiod=self.tp)

        elif para is 'LINEARREG_ANGLE':  #Linear Regression Angle
            self.output = ta.LINEARREG_ANGLE(self.close, timeperiod=self.tp)

        elif para is 'LINEARREG_INTERCEPT':  #Linear Regression Intercept
            self.output = ta.LINEARREG_INTERCEPT(self.close,
                                                 timeperiod=self.tp)

        elif para is 'LINEARREG_SLOPE':  #Linear Regression Slope
            self.output = ta.LINEARREG_SLOPE(self.close, timeperiod=self.tp)

        elif para is 'STDDEV':  #Standard Deviation
            self.output = ta.STDDEV(self.close, timeperiod=5, nbdev=1)

        elif para is 'TSF':  #Time Series Forecast
            self.output = ta.TSF(self.close, timeperiod=self.tp)

        elif para is 'VAR':  #Variance
            self.output = ta.VAR(self.close, timeperiod=5, nbdev=1)

        else:
            print('You issued command:' + para)
Esempio n. 26
0
def pattern_recognition(candles: np.ndarray, pattern_type, penetration=0, sequential=False) -> Union[int, np.ndarray]:
    """
    Pattern Recognition

    :param candles: np.ndarray
    :param penetration: int - default = 0
    :param pattern_type: str
    :param sequential: bool - default=False

    :return: int | np.ndarray
    """
    if not sequential and len(candles) > 240:
        candles = candles[-240:]

    if pattern_type == "CDL2CROWS":
        res = talib.CDL2CROWS(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDL3BLACKCROWS":
        res = talib.CDL3BLACKCROWS(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDL3INSIDE":
        res = talib.CDL3INSIDE(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDL3LINESTRIKE":
        res = talib.CDL3LINESTRIKE(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDL3OUTSIDE":
        res = talib.CDL3OUTSIDE(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDL3STARSINSOUTH":
        res = talib.CDL3STARSINSOUTH(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDL3WHITESOLDIERS":
        res = talib.CDL3WHITESOLDIERS(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLABANDONEDBABY":
        res = talib.CDLABANDONEDBABY(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2],
                                     penetration=penetration)
    elif pattern_type == "CDLADVANCEBLOCK":
        res = talib.CDLADVANCEBLOCK(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLBELTHOLD":
        res = talib.CDLBELTHOLD(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLBREAKAWAY":
        res = talib.CDLBREAKAWAY(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLCLOSINGMARUBOZU":
        res = talib.CDLCLOSINGMARUBOZU(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLCONCEALBABYSWALL":
        res = talib.CDLCONCEALBABYSWALL(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLCOUNTERATTACK":
        res = talib.CDLCOUNTERATTACK(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLDARKCLOUDCOVER":
        res = talib.CDLDARKCLOUDCOVER(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2],
                                      penetration=penetration)
    elif pattern_type == "CDLDOJI":
        res = talib.CDLDOJI(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLDOJISTAR":
        res = talib.CDLDOJISTAR(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLDRAGONFLYDOJI":
        res = talib.CDLDRAGONFLYDOJI(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLENGULFING":
        res = talib.CDLENGULFING(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLEVENINGDOJISTAR":
        res = talib.CDLEVENINGDOJISTAR(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2],
                                       penetration=penetration)
    elif pattern_type == "CDLEVENINGSTAR":
        res = talib.CDLEVENINGSTAR(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2], penetration=penetration)
    elif pattern_type == "CDLGAPSIDESIDEWHITE":
        res = talib.CDLGAPSIDESIDEWHITE(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLGRAVESTONEDOJI":
        res = talib.CDLGRAVESTONEDOJI(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLHAMMER":
        res = talib.CDLHAMMER(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLHANGINGMAN":
        res = talib.CDLHANGINGMAN(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLHARAMI":
        res = talib.CDLHARAMI(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLHARAMICROSS":
        res = talib.CDLHARAMICROSS(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLHIGHWAVE":
        res = talib.CDLHIGHWAVE(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLHIKKAKE":
        res = talib.CDLHIKKAKE(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLHIKKAKEMOD":
        res = talib.CDLHIKKAKEMOD(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLHOMINGPIGEON":
        res = talib.CDLHOMINGPIGEON(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLIDENTICAL3CROWS":
        res = talib.CDLIDENTICAL3CROWS(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLINNECK":
        res = talib.CDLINNECK(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLINVERTEDHAMMER":
        res = talib.CDLINVERTEDHAMMER(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLKICKING":
        res = talib.CDLKICKING(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLKICKINGBYLENGTH":
        res = talib.CDLKICKINGBYLENGTH(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLLADDERBOTTOM":
        res = talib.CDLLADDERBOTTOM(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLLONGLEGGEDDOJI":
        res = talib.CDLLONGLEGGEDDOJI(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLLONGLINE":
        res = talib.CDLLONGLINE(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLMARUBOZU":
        res = talib.CDLMARUBOZU(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLMATCHINGLOW":
        res = talib.CDLMATCHINGLOW(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLMATHOLD":
        res = talib.CDLMATHOLD(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2], penetration=penetration)
    elif pattern_type == "CDLMORNINGDOJISTAR":
        res = talib.CDLMORNINGDOJISTAR(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2],
                                       penetration=penetration)
    elif pattern_type == "CDLMORNINGSTAR":
        res = talib.CDLMORNINGSTAR(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2], penetration=penetration)
    elif pattern_type == "CDLONNECK":
        res = talib.CDLONNECK(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLPIERCING":
        res = talib.CDLPIERCING(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLRICKSHAWMAN":
        res = talib.CDLRICKSHAWMAN(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLRISEFALL3METHODS":
        res = talib.CDLRISEFALL3METHODS(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLSEPARATINGLINES":
        res = talib.CDLSEPARATINGLINES(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLSHOOTINGSTAR":
        res = talib.CDLSHOOTINGSTAR(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLSHORTLINE":
        res = talib.CDLSHORTLINE(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLSPINNINGTOP":
        res = talib.CDLSPINNINGTOP(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLSTALLEDPATTERN":
        res = talib.CDLSTALLEDPATTERN(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLSTICKSANDWICH":
        res = talib.CDLSTICKSANDWICH(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLTAKURI":
        res = talib.CDLTAKURI(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLTASUKIGAP":
        res = talib.CDLTASUKIGAP(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLTHRUSTING":
        res = talib.CDLTHRUSTING(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLTRISTAR":
        res = talib.CDLTRISTAR(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLUNIQUE3RIVER":
        res = talib.CDLUNIQUE3RIVER(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLUPSIDEGAP2CROWS":
        res = talib.CDLUPSIDEGAP2CROWS(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    elif pattern_type == "CDLXSIDEGAP3METHODS":
        res = talib.CDLXSIDEGAP3METHODS(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])
    else:
        raise ValueError('pattern type string not recognised')

    return res / 100 if sequential else res[-1] / 100
Esempio n. 27
0
def TALIB_CDLMARUBOZU(close):
    '''00437,1,1'''
    return talib.CDLMARUBOZU(close)
 df['CDLHANGINGMAN'] = talib.CDLHANGINGMAN(op, hp, lp, cp)
 df['CDLHARAMI'] = talib.CDLHARAMI(op, hp, lp, cp)
 df['CDLHARAMICROSS'] = talib.CDLHARAMICROSS(op, hp, lp, cp)
 df['CDLHIGHWAVE'] = talib.CDLHIGHWAVE(op, hp, lp, cp)
 df['CDLHIKKAKE'] = talib.CDLHIKKAKE(op, hp, lp, cp)
 df['CDLHIKKAKEMOD'] = talib.CDLHIKKAKEMOD(op, hp, lp, cp)
 df['CDLHOMINGPIGEON'] = talib.CDLHOMINGPIGEON(op, hp, lp, cp)
 df['CDLIDENTICAL3CROWS'] = talib.CDLIDENTICAL3CROWS(op, hp, lp, cp)
 df['CDLINNECK'] = talib.CDLINNECK(op, hp, lp, cp)
 df['CDLINVERTEDHAMMER'] = talib.CDLINVERTEDHAMMER(op, hp, lp, cp)
 df['CDLKICKING'] = talib.CDLKICKING(op, hp, lp, cp)
 df['CDLKICKINGBYLENGTH'] = talib.CDLKICKINGBYLENGTH(op, hp, lp, cp)
 df['CDLLADDERBOTTOM'] = talib.CDLLADDERBOTTOM(op, hp, lp, cp)
 df['CDLLONGLEGGEDDOJI'] = talib.CDLLONGLEGGEDDOJI(op, hp, lp, cp)
 df['CDLLONGLINE'] = talib.CDLLONGLINE(op, hp, lp, cp)
 df['CDLMARUBOZU'] = talib.CDLMARUBOZU(op, hp, lp, cp)
 df['CDLMATCHINGLOW'] = talib.CDLMATCHINGLOW(op, hp, lp, cp)
 df['CDLMATHOLD'] = talib.CDLMATHOLD(op, hp, lp, cp)
 df['CDLMORNINGDOJISTAR'] = talib.CDLMORNINGDOJISTAR(op, hp, lp, cp)
 df['CDLMORNINGSTAR'] = talib.CDLMORNINGSTAR(op, hp, lp, cp)
 df['CDLONNECK'] = talib.CDLONNECK(op, hp, lp, cp)
 df['CDLPIERCING'] = talib.CDLPIERCING(op, hp, lp, cp)
 df['CDLRICKSHAWMAN'] = talib.CDLRICKSHAWMAN(op, hp, lp, cp)
 df['CDLRISEFALL3METHODS'] = talib.CDLRISEFALL3METHODS(op, hp, lp, cp)
 df['CDLSEPARATINGLINES'] = talib.CDLSEPARATINGLINES(op, hp, lp, cp)
 df['CDLSHOOTINGSTAR'] = talib.CDLSHOOTINGSTAR(op, hp, lp, cp)
 df['CDLSHORTLINE'] = talib.CDLSHORTLINE(op, hp, lp, cp)
 df['CDLSPINNINGTOP'] = talib.CDLSPINNINGTOP(op, hp, lp, cp)
 df['CDLSTALLEDPATTERN'] = talib.CDLSTALLEDPATTERN(op, hp, lp, cp)
 df['CDLSTICKSANDWICH'] = talib.CDLSTICKSANDWICH(op, hp, lp, cp)
 df['CDLTAKURI'] = talib.CDLTAKURI(op, hp, lp, cp)
                                                np.array(df['High']),
                                                np.array(df['Low']),
                                                np.array(df['Adj Close']))
df['Ladder_Bottom'] = ta.CDLLADDERBOTTOM(np.array(df['Open']),
                                         np.array(df['High']),
                                         np.array(df['Low']),
                                         np.array(df['Adj Close']))
df['Long_Legged_Doji'] = ta.CDLLONGLEGGEDDOJI(np.array(df['Open']),
                                              np.array(df['High']),
                                              np.array(df['Low']),
                                              np.array(df['Adj Close']))
df['Long_line_Candle'] = ta.CDLLONGLINE(np.array(df['Open']),
                                        np.array(df['High']),
                                        np.array(df['Low']),
                                        np.array(df['Adj Close']))
df['Marubozu'] = ta.CDLMARUBOZU(np.array(df['Open']), np.array(df['High']),
                                np.array(df['Low']), np.array(df['Adj Close']))
df['Matching_Low'] = ta.CDLMATCHINGLOW(np.array(df['Open']),
                                       np.array(df['High']),
                                       np.array(df['Low']),
                                       np.array(df['Adj Close']))
df['Mat_Hold'] = ta.CDLMATHOLD(np.array(df['Open']), np.array(df['High']),
                               np.array(df['Low']), np.array(df['Adj Close']))
df['Morning_Star'] = ta.CDLMORNINGSTAR(np.array(df['Open']),
                                       np.array(df['High']),
                                       np.array(df['Low']),
                                       np.array(df['Adj Close']))
df['On_Neck_Pattern'] = ta.CDLONNECK(np.array(df['Open']),
                                     np.array(df['High']), np.array(df['Low']),
                                     np.array(df['Adj Close']))
df['Piercing_Pattern'] = ta.CDLPIERCING(np.array(df['Open']),
                                        np.array(df['High']),
Esempio n. 30
0
def CDLMARUBOZU(data, **kwargs):
    _check_talib_presence()
    popen, phigh, plow, pclose, pvolume = _extract_ohlc(data)
    return talib.CDLMARUBOZU(popen, phigh, plow, pclose, **kwargs)