def bear_hammer_inverse(self, *args): def logic(x): nonlocal o if (x - 1 in idx and x - 2 in idx and self.check_status( self.array[x][0], self.array[x][-1]) == "Bearish" and self.check_status(self.array[x - 1][0], self.array[x - 1][-1]) == "Bearish" and self.check_status(self.array[x - 2][0], self.array[x - 2][-1]) == "Bearish"): o.append(x) ham = talib.CDLHAMMER(self.o, self.h, self.l, self.c) t = talib.CDLINVERTEDHAMMER(self.o, self.h, self.l, self.c) idx = np.where(ham == 100)[0] idx1 = np.where(t == 100)[0] o = [] for x in idx1: try: logic(x) except Exception: continue a = np.zeros(len(self.o)) a[o] = 1 return a
def genTA(data, y, t): #t is timeperiod indicators = {} y_ind = copy.deepcopy(y) for ticker in data: ## Overlap indicators[ticker] = ta.SMA(data[ticker].iloc[:,3], timeperiod=t).to_frame() indicators[ticker]['EMA'] = ta.EMA(data[ticker].iloc[:,3], timeperiod=t) indicators[ticker]['BBAND_Upper'], indicators[ticker]['BBAND_Middle' ], indicators[ticker]['BBAND_Lower' ] = ta.BBANDS(data[ticker].iloc[:,3], timeperiod=t, nbdevup=2, nbdevdn=2, matype=0) indicators[ticker]['HT_TRENDLINE'] = ta.HT_TRENDLINE(data[ticker].iloc[:,3]) indicators[ticker]['SAR'] = ta.SAR(data[ticker].iloc[:,1], data[ticker].iloc[:,2], acceleration=0, maximum=0) #rename SMA column indicators[ticker].rename(columns={indicators[ticker].columns[0]: "SMA"}, inplace=True) ## Momentum indicators[ticker]['RSI'] = ta.RSI(data[ticker].iloc[:,3], timeperiod=(t-1)) indicators[ticker]['MOM'] = ta.MOM(data[ticker].iloc[:,3], timeperiod=(t-1)) indicators[ticker]['ROC'] = ta.ROC(data[ticker].iloc[:,3], timeperiod=(t-1)) indicators[ticker]['ROCP']= ta.ROCP(data[ticker].iloc[:,3],timeperiod=(t-1)) indicators[ticker]['STOCH_SLOWK'], indicators[ticker]['STOCH_SLOWD'] = ta.STOCH(data[ticker].iloc[:,1], data[ticker].iloc[:,2], data[ticker].iloc[:,3], fastk_period=t, slowk_period=int(.6*t), slowk_matype=0, slowd_period=int(.6*t), slowd_matype=0) indicators[ticker]['MACD'], indicators[ticker]['MACDSIGNAL'], indicators[ticker]['MACDHIST'] = ta.MACD(data[ticker].iloc[:,3], fastperiod=t,slowperiod=2*t,signalperiod=int(.7*t)) ## Volume indicators[ticker]['OBV'] = ta.OBV(data[ticker].iloc[:,3], data[ticker].iloc[:,4]) indicators[ticker]['AD'] = ta.AD(data[ticker].iloc[:,1], data[ticker].iloc[:,2], data[ticker].iloc[:,3], data[ticker].iloc[:,4]) indicators[ticker]['ADOSC'] = ta.ADOSC(data[ticker].iloc[:,1], data[ticker].iloc[:,2], data[ticker].iloc[:,3], data[ticker].iloc[:,4], fastperiod=int(.3*t), slowperiod=t) ## Cycle indicators[ticker]['HT_DCPERIOD'] = ta.HT_DCPERIOD(data[ticker].iloc[:,3]) indicators[ticker]['HT_TRENDMODE']= ta.HT_TRENDMODE(data[ticker].iloc[:,3]) ## Price indicators[ticker]['AVGPRICE'] = ta.AVGPRICE(data[ticker].iloc[:,0], data[ticker].iloc[:,1], data[ticker].iloc[:,2], data[ticker].iloc[:,3]) indicators[ticker]['TYPPRICE'] = ta.TYPPRICE(data[ticker].iloc[:,1], data[ticker].iloc[:,2], data[ticker].iloc[:,3]) ## Volatility indicators[ticker]['ATR'] = ta.ATR(data[ticker].iloc[:,1], data[ticker].iloc[:,2], data[ticker].iloc[:,3], timeperiod=(t-1)) ## Statistics indicators[ticker]['BETA'] = ta.BETA(data[ticker].iloc[:,1], data[ticker].iloc[:,2], timeperiod=(t-1)) indicators[ticker]['LINEARREG'] = ta.LINEARREG(data[ticker].iloc[:,3], timeperiod=t) indicators[ticker]['VAR'] = ta.VAR(data[ticker].iloc[:,3], timeperiod=t, nbdev=1) ## Math Transform indicators[ticker]['EXP'] = ta.EXP(data[ticker].iloc[:,3]) indicators[ticker]['LN'] = ta.LN(data[ticker].iloc[:,3]) ## Patterns (returns integers - but norming might not really do anything but wondering if they should be normed) indicators[ticker]['CDLENGULFING'] = ta.CDLENGULFING(data[ticker].iloc[:,0], data[ticker].iloc[:,1], data[ticker].iloc[:,2], data[ticker].iloc[:,3]) indicators[ticker]['CDLDOJI'] = ta.CDLDOJI(data[ticker].iloc[:,0], data[ticker].iloc[:,1], data[ticker].iloc[:,2], data[ticker].iloc[:,3]) indicators[ticker]['CDLHAMMER'] = ta.CDLHAMMER(data[ticker].iloc[:,0], data[ticker].iloc[:,1], data[ticker].iloc[:,2], data[ticker].iloc[:,3]) indicators[ticker]['CDLHANGINGMAN']= ta.CDLHANGINGMAN(data[ticker].iloc[:,0], data[ticker].iloc[:,1], data[ticker].iloc[:,2], data[ticker].iloc[:,3]) #drop 'nan' values indicators[ticker].drop(indicators[ticker].index[np.arange(0,63)], inplace=True) y_ind[ticker].drop(y_ind[ticker].index[np.arange(0,63)], inplace=True) #Normalize Features indicators_norm = normData(indicators) return indicators_norm, indicators, y_ind
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
def get_cdlhammer(ohlc): cdlhammer = ta.CDLHAMMER(ohlc['1_open'], ohlc['2_high'], ohlc['3_low'], ohlc['4_close']) ohlc['cdlhammer'] = cdlhammer return ohlc
def hammer_doji(server): #The idea is to look at yesterdays candles, find hammes/dragonfly dojis/dojis and then initiate trade if we get a new high. watchlist = [] tickers = db.read_snp_tickers(server.serverSite).Symbol.tolist() for ticker in tickers: try: #Get the latest data only data = db.read_from_database( "Select distinct date, ticker,uOpen, uHigh, uLow, uClose from dailydata where ticker ='" + ticker + "' ORDER BY date DESC limit 1;", server.serverSite) data["dojidf"] = talib.CDLDRAGONFLYDOJI(data.uOpen, data.uHigh, data.uLow, data.uClose) data["hammer"] = talib.CDLHAMMER(data.uOpen, data.uHigh, data.uLow, data.uClose) data["doji"] = talib.CDLDOJI(data.uOpen, data.uHigh, data.uLow, data.uClose) if (int(data.dojidf) == 100 | int(data.hammer) == 100 | int(data.doji) == 100): watchlist.append([ticker, "buy", data.uHigh[0], "H/D"]) logging.info("Hd found", ticker) except: logging.info("Database fetch has failed for ticker", ticker) #Returns an list of lists with ticker, enrty price and strategy return watchlist
def hammer(cls, df): """ 锤子线 :param df: :return: """ return ta.CDLHAMMER(df['open'], df['high'], df['low'], df['close'])
def bull_RhammerThrice(self, *args): hammer = talib.CDLHAMMER(self.o, self.h, self.l, self.c) idx = np.where(hammer == 100)[0] o = [] for x in idx: try: if (self.check_status(self.array[x - 2][0], self.array[x - 2][-1]) == "Bearish" and self.check_status(self.array[x - 1][0], self.array[x - 1][-1]) == "Bearish" and self.check_status( self.array[x][0], self.array[x][-1]) == "Bullish" and self.array[x][0] == self.array[x - 1][-1] and self.array[x][-1] > ((self.array[x - 1][0] + self.array[x - 1][-1]) / 2)): o.append(x) except Exception: pass a = np.zeros(len(self.o)) a[o] = 1 return a
def plot_Hammer(data): """This function signals Hammer pattern. ############################ CDLHAMMER - Hammer ################################ explanation:""" hammer_pattern = talib.CDLHAMMER(data['Open'], data['High'], data['Low'], data['Close']) return np.flatnonzero(hammer_pattern)
def add_pattern_reconition_factor(df): df['two_crows'] = talib.CDL2CROWS(df['open'], df['high'], df['low'], df['close']) df['three_black_crows'] = talib.CDL3BLACKCROWS(df['open'], df['high'], df['low'], df['close']) df['three_inside'] = talib.CDL3INSIDE(df['open'], df['high'], df['low'], df['close']) df['three_line_strike'] = talib.CDL3LINESTRIKE(df['open'], df['high'], df['low'], df['close']) df['three_outside'] = talib.CDL3OUTSIDE(df['open'], df['high'], df['low'], df['close']) df['three_star_south'] = talib.CDL3STARINSOUTH(df['open'], df['high'], df['low'], df['close']) df['three_white_soldiers'] = talib.CDL3WHITESOLDIERS( df['open'], df['high'], df['low'], df['close']) df['abandoned_baby'] = talib.CDLABANDONEDBABY(df['open'], df['high'], df['low'], df['close']) df['advance_block'] = talib.CDLADVANCEBLOCK(df['open'], df['high'], df['low'], df['close']) df['belt_hold'] = talib.CDLBELTHOLD(df['open'], df['high'], df['low'], df['close']) df['break_away'] = talib.CDLBREAKAWAY(df['open'], df['high'], df['low'], df['close']) df['closing_marubozu'] = talib.CDLCLOSINGMARUBOZU(df['open'], df['high'], df['low'], df['close']) df['conceal_baby_swall'] = talib.CDLCONCEALBABYSWALL( df['open'], df['high'], df['low'], df['close']) df['counter_attack'] = talib.CDLCOUNTERATTACK(df['open'], df['high'], df['low'], df['close']) df['dark_cloud_cover'] = talib.CDLDARKCLOUDCOVER(df['open'], df['high'], df['low'], df['close']) df['doji'] = talib.CDLDOJI(df['open'], df['high'], df['low'], df['close']) df['doji_star'] = talib.CDLDOJISTAR(df['open'], df['high'], df['low'], df['close']) df['dragon_fly_doji'] = talib.CDLDRAGONFLYDOJI(df['open'], df['high'], df['low'], df['close']) df['engulfing'] = talib.CDLENGULFING(df['open'], df['high'], df['low'], df['close']) df['evening_doji_star'] = talib.CDLEVENINGDOJISTAR(df['open'], df['high'], df['low'], df['close'], penetration=0) df['gap_sideside_white'] = talib.CDLGAPSIDESIDEWHITE( df['open'], df['high'], df['low'], df['close']) df['grave_stone_doji'] = talib.CDLGRAVESTONEDOJI(df['open'], df['high'], df['low'], df['close']) df['hammer'] = talib.CDLHAMMER(df['open'], df['high'], df['low'], df['close']) df['morning_doji_star'] = talib.CDLMORNINGDOJISTAR(df['open'], df['high'], df['low'], df['close'], penetration=0) df['on_neck'] = talib.CDLONNECK(df['open'], df['high'], df['low'], df['close']) return df
def hummer(self): """ 名称:Hammer 锤头 简介:一日K线模式,实体较短,无上影线,下影线大于实体长度两倍,处于下跌趋势底部,预示反转。 """ result = talib.CDLHAMMER(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['hummer'] = result
def CDLHAMMER(open, high, low, close): ''' Hammer 锤头 分组: Pattern Recognition 形态识别 简介: 一日K线模式,实体较短,无上影线, 下影线大于实体长度两倍,处于下跌趋势底部,预示反转。 integer = CDLHAMMER(open, high, low, close) ''' return talib.CDLHAMMER(open, high, low, close)
def hammer(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.CDLHAMMER(opens, highs, lows, closes) return cdl
def the_twelve(df,return_candlelist=False): ''' adds candles to the data frame if return_candle_list is True: RETURNS: a list of the candels: [ 'DOJI', 'EVENINGSTAR', 'MORNINGSTAR', 'SHOOTINGSTAR', 'HAMMER', 'INVERTEDHAMMER', 'HARAMI', 'ENGULFING', 'HANGINGMAN', 'PIERCING', 'BELTHOLD', 'KICKING', 'DARKCLOUDCOVER' ''' df['DOJI'] = talib.CDLDOJI(df.open,df.high,df.low,df.close) df['EVENINGSTAR'] = talib.CDLEVENINGSTAR(df.open,df.high,df.low,df.close) df['MORNINGSTAR'] = talib.CDLMORNINGSTAR(df.open,df.high,df.low,df.close) df['SHOOTINGSTAR'] = talib.CDLSHOOTINGSTAR(df.open,df.high,df.low,df.close) df['HAMMER'] = talib.CDLHAMMER(df.open,df.high,df.low,df.close) df['INVERTEDHAMMER'] = talib.CDLINVERTEDHAMMER(df.open,df.high,df.low,df.close) df['HARAMI'] = talib.CDLHARAMI(df.open,df.high,df.low,df.close) df['ENGULFING'] = talib.CDLENGULFING(df.open,df.high,df.low,df.close) df['HANGINGMAN'] = talib.CDLHANGINGMAN(df.open,df.high,df.low,df.close) df['PIERCING'] = talib.CDLPIERCING(df.open,df.high,df.low,df.close) df['BELTHOLD'] = talib.CDLBELTHOLD(df.open,df.high,df.low,df.close) df['KICKING'] = talib.CDLKICKING(df.open,df.high,df.low,df.close) df['DARKCLOUDCOVER'] = talib.CDLDARKCLOUDCOVER(df.open,df.high,df.low,df.close) if return_candlelist == True: candle_list = [ 'DOJI', 'EVENINGSTAR', 'MORNINGSTAR', 'SHOOTINGSTAR', 'HAMMER', 'INVERTEDHAMMER', 'HARAMI', 'ENGULFING', 'HANGINGMAN', 'PIERCING', 'BELTHOLD', 'KICKING', 'DARKCLOUDCOVER' ] return candle_list
def hammer(exchange, symbol, timeframe, past=0) -> int: """ is the current candle a hammer pattern. returns 1 when is a hammer, and 0 when isn't """ if past != 0: candles = store.candles.get_candles(exchange, symbol, timeframe)[:-abs(past)] else: candles = store.candles.get_candles(exchange, symbol, timeframe) if len(candles) > 240: candles = candles[-240:] res = talib.CDLHAMMER(candles[:, 1], candles[:, 3], candles[:, 4], candles[:, 2])[-1] return int(res / 100)
def add_up_pattern_recognition_factor(df): df['hammer'] = talib.CDLHAMMER(df['open'], df['high'], df['low'], df['close']) df['inverted_hammer'] = talib.CDLINVERTEDHAMMER(df['open'], df['high'], df['low'], df['close']) df['engulfing'] = talib.CDLENGULFING(df['open'], df['high'], df['low'], df['close']) # not sure the direction df['three_white_soldiers'] = talib.CDL3WHITESOLDIERS( df['open'], df['high'], df['low'], df['close']) # strong up trend df['morning_doji_star'] = talib.CDLMORNINGDOJISTAR(df['open'], df['high'], df['low'], df['close'], penetration=0) return df
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
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
def bull_Rmarubozu_Rhammer_RinvertedHammer(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.CDLINVERTEDHAMMER(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 idx2: if (x - 1 in idx1 and x - 2 in idx and self.check_status( self.array[x - 1][0], self.array[x - 1][-1]) == "Bearish" and self.check_status(self.array[x][0], self.array[x][-1]) == "Bearish"): o.append(x) a = np.zeros(len(self.o)) a[o] = 1 return a
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 bear_Takuri_redBody_longLegged_redBody(self, *args): tak = talib.CDLHAMMER(self.o, self.h, self.l, self.c) long = talib.CDLLONGLEGGEDDOJI(self.o, self.h, self.l, self.c) idx = np.where(tak == 100)[0] idx2 = np.where(long == 100)[0] o = [] for x in idx: try: if (self.check_status(self.array[x + 1][0], self.array[x + 1][-1]) == "Bearish" and self.check_status(self.array[x + 3][0], self.array[x + 3][-1]) == "Bearish" and x + 2 in idx2): o.append(x + 3) except Exception: pass a = np.zeros(len(self.o)) a[o] = 1 return a
def bull_inverse_hammer(self, *args): ham = talib.CDLINVERTEDHAMMER(self.o, self.h, self.l, self.c) ham1 = talib.CDLHAMMER(self.o, self.h, self.l, self.c) idx = np.where(ham == 100)[0] idx1 = np.where(ham1 == 100)[0] o = [] for x in idx1: try: if ((x - 1 and x - 2) in idx and self.check_status( self.array[x][0], self.array[x][-1]) == "Bullish" and self.check_status(self.array[x - 1][0], self.array[x - 1][-1]) == "Bullish" and self.check_status( self.array[x - 2][0], self.array[x - 2][-1]) == "Bullish"): o.append(x) except Exception: continue a = np.zeros(len(self.o)) a[o] = 1 return a
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
def TALIB_CDLHAMMER(close): '''00421,1,1''' return talib.CDLHAMMER(close)
def hammer(time_series, a): hammmer = talib.CDLHAMMER(time_series["open"].values, time_series["high"].values, time_series["low"].values, time_series["close"].values)
df['CDLADVANCEBLOCK'] = talib.CDLADVANCEBLOCK(op, hp, lp, cp) df['CDLBELTHOLD'] = talib.CDLBELTHOLD(op, hp, lp, cp) df['CDLBREAKAWAY'] = talib.CDLBREAKAWAY(op, hp, lp, cp) df['CDLCLOSINGMARUBOZU'] = talib.CDLCLOSINGMARUBOZU(op, hp, lp, cp) df['CDLCONCEALBABYSWALL'] = talib.CDLCONCEALBABYSWALL(op, hp, lp, cp) df['CDLCOUNTERATTACK'] = talib.CDLCOUNTERATTACK(op, hp, lp, cp) df['CDLDARKCLOUDCOVER'] = talib.CDLDARKCLOUDCOVER(op, hp, lp, cp) df['CDLDOJI'] = talib.CDLDOJI(op, hp, lp, cp) df['CDLDOJISTAR'] = talib.CDLDOJISTAR(op, hp, lp, cp) df['CDLDRAGONFLYDOJI'] = talib.CDLDRAGONFLYDOJI(op, hp, lp, cp) df['CDLENGULFING'] = talib.CDLENGULFING(op, hp, lp, cp) df['CDLEVENINGDOJISTAR'] = talib.CDLEVENINGDOJISTAR(op, hp, lp, cp) df['CDLEVENINGSTAR'] = talib.CDLEVENINGSTAR(op, hp, lp, cp) df['CDLGAPSIDESIDEWHITE'] = talib.CDLGAPSIDESIDEWHITE(op, hp, lp, cp) df['CDLGRAVESTONEDOJI'] = talib.CDLGRAVESTONEDOJI(op, hp, lp, cp) df['CDLHAMMER'] = talib.CDLHAMMER(op, hp, lp, cp) 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)
np.array(df['Low']), np.array(df['Adj Close']), penetration=0) df['Evening_Star'] = ta.CDLEVENINGSTAR(np.array(df['Open']), np.array(df['High']), np.array(df['Low']), np.array(df['Adj Close']), penetration=0) df['Up_Down_gap_side_by_side_white_lines'] = ta.CDLGAPSIDESIDEWHITE( np.array(df['Open']), np.array(df['High']), np.array(df['Low']), np.array(df['Adj Close'])) df['Gravestone_Doji'] = ta.CDLGRAVESTONEDOJI(np.array(df['Open']), np.array(df['High']), np.array(df['Low']), np.array(df['Adj Close'])) df['Hammer'] = ta.CDLHAMMER(np.array(df['Open']), np.array(df['High']), np.array(df['Low']), np.array(df['Adj Close'])) df['Hanging_Man'] = ta.CDLHANGINGMAN(np.array(df['Open']), np.array(df['High']), np.array(df['Low']), np.array(df['Adj Close'])) df['Harami_Pattern'] = ta.CDLHARAMI(np.array(df['Open']), np.array(df['High']), np.array(df['Low']), np.array(df['Adj Close'])) df['Harami_Cross_Pattern'] = ta.CDLHARAMICROSS(np.array(df['Open']), np.array(df['High']), np.array(df['Low']), np.array(df['Adj Close'])) df['High_Wave_Candle'] = ta.CDLHIGHWAVE(np.array(df['Open']), np.array(df['High']), np.array(df['Low']), np.array(df['Adj Close'])) df['Hikkake_Pattern'] = ta.CDLHIKKAKE(np.array(df['Open']),
def hammer(open, high, low, close): res = talib.CDLHAMMER(open, high, low, close) return np.array(res) == 100
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)
def CDLHAMMER(DataFrame): res = talib.CDLHAMMER(DataFrame.open.values, DataFrame.high.values, DataFrame.low.values, DataFrame.close.values) return pd.DataFrame({'CDLHAMMER': res}, index=DataFrame.index)
def CDLHAMMER(data, **kwargs): _check_talib_presence() popen, phigh, plow, pclose, pvolume = _extract_ohlc(data) return talib.CDLHAMMER(popen, phigh, plow, pclose, **kwargs)