def apply_indicators(df: pd.DataFrame): # ADX df['adx'] = ta.ADX(df) # EMA df['ema_5'] = ta.EMA(df, 5) df['ema_10'] = ta.EMA(df, 10) df['ema_20'] = ta.EMA(df, 20) df['ema_50'] = ta.EMA(df, 50) df['ema_100'] = ta.EMA(df, 100) df['ema_200'] = ta.EMA(df, 200) # MACD macd = ta.MACD(df) df['macd'] = macd['macd'] df['macdsignal'] = macd['macdsignal'] df['macdhist'] = macd['macdhist'] # inverse Fisher rsi/ RSI df['rsi'] = ta.RSI(df) rsi = 0.1 - (df['rsi'] - 50) df['i_rsi'] = (np.exp(2 * rsi) - 1) / (np.exp(2 * rsi) + 1) # Stoch fast stoch_fast = ta.STOCHF(df) df['fastd'] = stoch_fast['fastd'] df['fastk'] = stoch_fast['fastk'] # Stock slow stoch_slow = ta.STOCH(df) df['slowd'] = stoch_slow['slowd'] df['slowk'] = stoch_slow['slowk'] # Bollinger bands bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(df), window=20, stds=2) df['bb_lowerband'] = bollinger['lower'] df['bb_middleband'] = bollinger['mid'] df['bb_upperband'] = bollinger['upper'] # ROC df['roc'] = ta.ROC(df, 10) # CCI df['cci'] = ta.CCI(df, 14) # on balance volume df['obv'] = ta.OBV(df) # Average True Range df['atr'] = ta.ATR(df, 14) df = ichimoku(df) return df
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: macd = ta.MACD(dataframe) dataframe['macd'] = macd['macd'] dataframe['macdsignal'] = macd['macdsignal'] dataframe['macdhist'] = macd['macdhist'] dataframe['cci'] = ta.CCI(dataframe) return dataframe
def technical_index(self): df = self.max_min_price() df2 = self.institutional_investors() df['RSI'] = abstract.RSI(df) / 100 df['CMO'] =(abstract.CMO(df)+100) / (2 *100) df['MACD'] =(abstract.MACD(df)['macd']+abstract.MACD(df)['macd'].max()) / (2 *abstract.MACD(df)['macd'].max()) df['WILLR'] =(abstract.WILLR(df)+100) / (2 *100) df['WMA'] =abstract.WMA(df) / abstract.WMA(df).max() df['PPO'] =(abstract.PPO(df)+abstract.PPO(df).max()) / (2 *abstract.PPO(df).max()) df['EMA'] =abstract.EMA(df) / abstract.EMA(df).max() df['ROC'] =(abstract.ROC(df)+abstract.ROC(df).max()) / (2 *abstract.ROC(df).max()) df['SMA'] =abstract.SMA(df) / abstract.SMA(df).max() df['TEMA'] =abstract.TEMA(df) / abstract.TEMA(df).max() df['CCI'] =(abstract.CCI(df)+abstract.CCI(df).max()) / (2 *abstract.CCI(df).max()) df['investment_trust'] = (df2['investment_trust'] + df2['investment_trust'].max()) / (2*df2['investment_trust'].max()) df['foreign_investor'] = (df2['foreign_investor'] + df2['foreign_investor'].max()) / (2*df2['foreign_investor'].max()) df = df.drop(columns=['volume', 'open', 'high', 'low', 'close', 'close_max', 'close_min']) df = df.dropna() return df
def populate_indicators(dataframe: DataFrame, metadata: dict) -> DataFrame: macd = ta.MACD(dataframe) dataframe["macd"] = macd["macd"] dataframe["macdsignal"] = macd["macdsignal"] for cciTime in cciTimeRange: cciName = "cci-" + str(cciTime) dataframe[cciName] = ta.CCI(dataframe, timeperiod=cciTime) return dataframe
def CCI(self): CCI = tb.CCI(self.dataframe, timeperiod=20) value = CCI[len(CCI) - 1] preValue = CCI[len(CCI) - 2] if (value > cciUpperLimit): return "sell" elif (value < cciLowerLimit): return "buy" else: return "neutral"
def populate_indicators(self, dataframe: DataFrame) -> DataFrame: macd = ta.MACD(dataframe) dataframe = CCIStrategy.resample(dataframe, self.ticker_interval, 5) dataframe['cci_one'] = ta.CCI(dataframe, timeperiod=170) dataframe['cci_two'] = ta.CCI(dataframe, timeperiod=34) dataframe['rsi'] = ta.RSI(dataframe) dataframe['mfi'] = ta.MFI(dataframe) dataframe['cmf'] = self.chaikin_mf(dataframe) # required for graphing bollinger = qtpylib.bollinger_bands(dataframe['close'], window=20, stds=2) dataframe['bb_lowerband'] = bollinger['lower'] dataframe['bb_upperband'] = bollinger['upper'] dataframe['bb_middleband'] = bollinger['mid'] return dataframe
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: dataframe['hma'] = hull_moving_average(dataframe, 14, 'close') dataframe['cci'] = ta.CCI(dataframe, timeperiod=14) dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14) rsi = 0.1 * (dataframe['rsi'] - 50) dataframe['fisher_rsi'] = (np.exp(2 * rsi) - 1) / (np.exp(2 * rsi) + 1) return dataframe
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: dataframe = self.resample(dataframe, self.timeframe, 5) dataframe["cci_one"] = ta.CCI(dataframe, timeperiod=170) dataframe["cci_two"] = ta.CCI(dataframe, timeperiod=34) dataframe["rsi"] = ta.RSI(dataframe) dataframe["mfi"] = ta.MFI(dataframe) dataframe["cmf"] = self.chaikin_mf(dataframe) # required for graphing bollinger = qtpylib.bollinger_bands(dataframe["close"], window=20, stds=2) dataframe["bb_lowerband"] = bollinger["lower"] dataframe["bb_upperband"] = bollinger["upper"] dataframe["bb_middleband"] = bollinger["mid"] return dataframe
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: bollinger = qtpylib.bollinger_bands(dataframe['close'], window=20, stds=2) dataframe['bb_lowerband'] = bollinger['lower'] dataframe['bb_middleband'] = bollinger['mid'] dataframe['bb_upperband'] = bollinger['upper'] dataframe['bb_width'] = ( (dataframe['bb_upperband'] - dataframe['bb_lowerband']) / dataframe['bb_middleband']) dataframe['bb_bottom_cross'] = qtpylib.crossed_below( dataframe['close'], dataframe['bb_lowerband']).astype('int') dataframe['rsi'] = ta.RSI(dataframe, timeperiod=10) dataframe['plus_di'] = ta.PLUS_DI(dataframe) dataframe['minus_di'] = ta.MINUS_DI(dataframe) dataframe['cci'] = ta.CCI(dataframe, 30) dataframe['mfi'] = ta.MFI(dataframe, timeperiod=14) dataframe['cmf'] = chaikin_mf(dataframe) dataframe['rmi'] = RMI(dataframe, length=8, mom=4) stoch = ta.STOCHRSI(dataframe, 15, 20, 2, 2) dataframe['srsi_fk'] = stoch['fastk'] dataframe['srsi_fd'] = stoch['fastd'] dataframe['fastEMA'] = ta.EMA(dataframe['volume'], timeperiod=12) dataframe['slowEMA'] = ta.EMA(dataframe['volume'], timeperiod=26) dataframe['pvo'] = ((dataframe['fastEMA'] - dataframe['slowEMA']) / dataframe['slowEMA']) * 100 dataframe['is_dip'] = ((dataframe['rmi'] < 20) & (dataframe['cci'] <= -150) & (dataframe['srsi_fk'] < 20) # Maybe comment mfi and cmf to make more trades & (dataframe['mfi'] < 25) & (dataframe['cmf'] <= -0.1)).astype('int') dataframe['is_break'] = ( (dataframe['bb_width'] > 0.025) & (dataframe['bb_bottom_cross'].rolling(10).sum() > 1) & (dataframe['close'] < 0.99 * dataframe['bb_lowerband']) ).astype('int') dataframe['buy_signal'] = ((dataframe['is_dip'] > 0) & (dataframe['is_break'] > 0)).astype('int') return dataframe
def populate_indicators(dataframe: DataFrame, metadata: dict) -> DataFrame: macd = ta.MACD(dataframe, fastperiod=12, slowperiod=26, signalperiod=9) dataframe['macdhist'] = macd['macdhist'] dataframe['macd'] = macd['macd'] dataframe['macdsignal'] = macd['macdsignal'] for cciTime in cciTimeRange: cciName = "cci-" + str(cciTime) dataframe[cciName] = ta.CCI(dataframe, timeperiod=cciTime) return dataframe
def populate_indicators(dataframe: DataFrame, metadata: dict) -> DataFrame: """ Dynamic TA indicators Used so hyperopt can optimized around the period of various indicators """ for kshort in range(kshortStart, (kshortEnd + 1)): dataframe[f'kama-short({kshort})'] = ta.KAMA(dataframe, timeperiod=kshort) for klong in range(klongStart, (klongEnd + 1)): dataframe[f'kama-long({klong})'] = ta.KAMA(dataframe, timeperiod=klong) for klong in range(klongStart, (klongEnd + 1)): dataframe[f'kama-long-slope({klong})'] = ( dataframe[f'kama-long({klong})'] / dataframe[f'kama-long({klong})'].shift()) for ccip in range(cciStart, (cciEnd + 1)): dataframe[f'cci({ccip})'] = ta.CCI(dataframe, timeperiod=ccip) for rsip in range(rsiStart, (rsiEnd + 1)): dataframe[f'rsi({rsip})'] = ta.RSI(dataframe, timeperiod=rsip) """ Static TA indicators. Only used when --spaces does not include buy or sell """ dataframe['cci'] = ta.CCI(dataframe, timeperiod=cciStatic) # RSI dataframe['rsi'] = ta.RSI(dataframe, timeperiod=rsiStatic) # KAMA - Kaufman Adaptive Moving Average dataframe['kama-short'] = ta.KAMA(dataframe, timeperiod=kamaShortStatic) dataframe['kama-long'] = ta.KAMA(dataframe, timeperiod=kamaLongStatic) dataframe['kama-long-slope'] = (dataframe['kama-long'] / dataframe['kama-long'].shift()) return dataframe
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: """ Dynamic TA indicators Used so hyperopt can optimized around the period of various indicators """ dataframe['kama-short'] = ta.KAMA(dataframe, timeperiod=5) dataframe['kama-long'] = ta.KAMA(dataframe, timeperiod=20) dataframe['cci'] = ta.CCI(dataframe, timeperiod=21) dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14) return dataframe
def populate_indicators(dataframe: DataFrame, metadata: dict) -> DataFrame: for cciTime in cciTimeRange: cciName = "cci-" + str(cciTime) dataframe[cciName] = ta.CCI(dataframe, timeperiod=cciTime) for rsiTime in rsiTimeRange: rsiName = "rsi-" + str(rsiTime) dataframe[rsiName] = ta.RSI(dataframe, timeperiod=rsiTime) return dataframe
def populate_indicators(dataframe: DataFrame) -> DataFrame: """ Adds several different TA indicators to the given DataFrame """ dataframe['sar'] = ta.SAR(dataframe) dataframe['adx'] = ta.ADX(dataframe) stoch = ta.STOCHF(dataframe) dataframe['fastd'] = stoch['fastd'] dataframe['fastk'] = stoch['fastk'] dataframe['blower'] = ta.BBANDS(dataframe, nbdevup=2, nbdevdn=2)['lowerband'] dataframe['sma'] = ta.SMA(dataframe, timeperiod=40) dataframe['tema'] = ta.TEMA(dataframe, timeperiod=9) dataframe['mfi'] = ta.MFI(dataframe) dataframe['cci'] = ta.CCI(dataframe) return dataframe
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: dataframe = self.resample(dataframe, self.ticker_interval, self.resample_factor) ################################################################################## # buy and sell indicators dataframe['ema_{}'.format(self.EMA_SHORT_TERM)] = ta.EMA( dataframe, timeperiod=self.EMA_SHORT_TERM) dataframe['ema_{}'.format(self.EMA_MEDIUM_TERM)] = ta.EMA( dataframe, timeperiod=self.EMA_MEDIUM_TERM) dataframe['ema_{}'.format(self.EMA_LONG_TERM)] = ta.EMA( dataframe, timeperiod=self.EMA_LONG_TERM) bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=2) dataframe['bb_lowerband'] = bollinger['lower'] dataframe['bb_middleband'] = bollinger['mid'] dataframe['bb_upperband'] = bollinger['upper'] dataframe['min'] = ta.MIN(dataframe, timeperiod=self.EMA_MEDIUM_TERM) dataframe['max'] = ta.MAX(dataframe, timeperiod=self.EMA_MEDIUM_TERM) dataframe['cci'] = ta.CCI(dataframe) dataframe['mfi'] = ta.MFI(dataframe) dataframe['rsi'] = ta.RSI(dataframe, timeperiod=7) dataframe['average'] = (dataframe['close'] + dataframe['open'] + dataframe['high'] + dataframe['low']) / 4 ################################################################################## # required for graphing bollinger = qtpylib.bollinger_bands(dataframe['close'], window=20, stds=2) dataframe['bb_lowerband'] = bollinger['lower'] dataframe['bb_upperband'] = bollinger['upper'] dataframe['bb_middleband'] = bollinger['mid'] macd = ta.MACD(dataframe) dataframe['macd'] = macd['macd'] dataframe['macdsignal'] = macd['macdsignal'] dataframe['macdhist'] = macd['macdhist'] return dataframe
def populate_indicators(self, dataframe: DataFrame) -> DataFrame: """ Adds several different TA indicators to the given DataFrame Performance Note: For the best performance be frugal on the number of indicators you are using. Let uncomment only the indicator you are using in your strategies or your hyperopt configuration, otherwise you will waste your memory and CPU usage. """ # Commodity Channel Index: values Oversold:<-100, Overbought:>100 dataframe['cci'] = ta.CCI(dataframe) # MFI dataframe['mfi'] = ta.MFI(dataframe) # CMO dataframe['cmo'] = ta.CMO(dataframe) return dataframe
def TA_processing(dataframe): bias(dataframe, days=[3, 6, 10, 25]) moving_average(dataframe, days=[5, 10, 20]) dataframe['ROC'] = abstract.ROC(dataframe, timeperiod=10) dataframe['MACD'] = abstract.MACD(dataframe, fastperiod=12, slowperiod=26, signalperiod=9)['macd'] dataframe['MACD_signal'] = abstract.MACD(dataframe, fastperiod=12, slowperiod=26, signalperiod=9)['macdsignal'] dataframe['UBBANDS'] = abstract.BBANDS(dataframe, timeperiod=20, nbdevup=2, nbdevdn=2, matype=0)['upperband'] dataframe['MBBANDS'] = abstract.BBANDS(dataframe, timeperiod=20, nbdevup=2, nbdevdn=2, matype=0)['middleband'] dataframe['LBBANDS'] = abstract.BBANDS(dataframe, timeperiod=20, nbdevup=2, nbdevdn=2, matype=0)['lowerband'] dataframe['%K'] = abstract.STOCH(dataframe, fastk_period=9)['slowk']/100 dataframe['%D'] = abstract.STOCH(dataframe, fastk_period=9)['slowd']/100 dataframe['W%R'] = abstract.WILLR(dataframe, timeperiod=14)/100 dataframe['RSI9'] = abstract.RSI(dataframe, timeperiod = 9)/100 dataframe['RSI14'] = abstract.RSI(dataframe, timeperiod = 14)/100 dataframe['CCI'] = abstract.CCI(dataframe, timeperiod=14)/100 counter_daily_potential(dataframe) dataframe['MOM'] = abstract.MOM(dataframe, timeperiod=10) dataframe['DX'] = abstract.DX(dataframe, timeperiod=14)/100 psy_line(dataframe) volumn_ratio(dataframe, d=26) on_balance_volume(dataframe)
def populate_indicators(self, dataframe: DataFrame) -> DataFrame: dataframe = self.resample(dataframe, self.ticker_interval, self.resample_factor) dataframe['ema_high'] = ta.EMA(dataframe, timeperiod=5, price='high') dataframe['ema_close'] = ta.EMA(dataframe, timeperiod=5, price='close') dataframe['ema_low'] = ta.EMA(dataframe, timeperiod=5, price='low') stoch_fast = ta.STOCHF(dataframe, 5.0, 3.0, 0.0, 3.0, 0.0) dataframe['fastd'] = stoch_fast['fastd'] dataframe['fastk'] = stoch_fast['fastk'] dataframe['adx'] = ta.ADX(dataframe) dataframe['cci'] = ta.CCI(dataframe, timeperiod=20) dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14) dataframe['mfi'] = ta.MFI(dataframe) # required for graphing bollinger = qtpylib.bollinger_bands(dataframe['close'], window=20, stds=2) dataframe['bb_lowerband'] = bollinger['lower'] dataframe['bb_upperband'] = bollinger['upper'] dataframe['bb_middleband'] = bollinger['mid'] return dataframe
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: """ Adds several different TA indicators to the given DataFrame Performance Note: For the best performance be frugal on the number of indicators you are using. Let uncomment only the indicator you are using in your strategies or your hyperopt configuration, otherwise you will waste your memory and CPU usage. """ # ADX dataframe['adx'] = ta.ADX(dataframe) dataframe['slowadx'] = ta.ADX(dataframe, 35) # Commodity Channel Index: values Oversold:<-100, Overbought:>100 dataframe['cci'] = ta.CCI(dataframe) # Stoch stoch = ta.STOCHF(dataframe, 5) dataframe['fastd'] = stoch['fastd'] dataframe['fastk'] = stoch['fastk'] dataframe['fastk-previous'] = dataframe.fastk.shift(1) dataframe['fastd-previous'] = dataframe.fastd.shift(1) # Slow Stoch slowstoch = ta.STOCHF(dataframe, 50) dataframe['slowfastd'] = slowstoch['fastd'] dataframe['slowfastk'] = slowstoch['fastk'] dataframe['slowfastk-previous'] = dataframe.slowfastk.shift(1) dataframe['slowfastd-previous'] = dataframe.slowfastd.shift(1) # EMA - Exponential Moving Average dataframe['ema5'] = ta.EMA(dataframe, timeperiod=5) dataframe['mean-volume'] = dataframe['volume'].mean() return dataframe
def TKE(dataframe, *, length=14, emaperiod=5): """ Source: https://www.tradingview.com/script/Pcbvo0zG/ Author: Dr Yasar ERDINC The calculation is simple: TKE=(RSI+STOCHASTIC+ULTIMATE OSCILLATOR+MFI+WIILIAMS %R+MOMENTUM+CCI)/7 Buy signal: when TKE crosses above 20 value Oversold region: under 20 value Overbought region: over 80 value Another usage of TKE is with its EMA , the default value is defined as 5 bars of EMA of the TKE line, Go long: when TKE crosses above EMALine Go short: when TKE crosses below EMALine Usage: `dataframe['TKE'], dataframe['TKEema'] = TKE1(dataframe)` """ import talib.abstract as ta df = dataframe.copy() # TKE=(RSI+STOCHASTIC+ULTIMATE OSCILLATOR+MFI+WIILIAMS %R+MOMENTUM+CCI)/7 df["rsi"] = ta.RSI(df, timeperiod=length) df['stoch'] = (100 * (df['close'] - df['low'].rolling(window=length).min()) / (df['high'].rolling(window=length).max() - df['low'].rolling(window=length).min())) df["ultosc"] = ta.ULTOSC(df, timeperiod1=7, timeperiod2=14, timeperiod3=28) df["mfi"] = ta.MFI(df, timeperiod=length) df["willr"] = ta.WILLR(df, timeperiod=length) df["mom"] = ta.ROCR100(df, timeperiod=length) df["cci"] = ta.CCI(df, timeperiod=length) df['TKE'] = df[['rsi', 'stoch', 'ultosc', 'mfi', 'willr', 'mom', 'cci']].mean(axis='columns') df["TKEema"] = ta.EMA(df["TKE"], timeperiod=emaperiod) return df["TKE"], df["TKEema"]
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: # Momentum Indicators # ------------------------------------ # ADX dataframe['adx'] = ta.ADX(dataframe) # Plus Directional Indicator / Movement dataframe['plus_dm'] = ta.PLUS_DM(dataframe) dataframe['plus_di'] = ta.PLUS_DI(dataframe) # # Minus Directional Indicator / Movement dataframe['minus_dm'] = ta.MINUS_DM(dataframe) dataframe['minus_di'] = ta.MINUS_DI(dataframe) # Aroon, Aroon Oscillator aroon = ta.AROON(dataframe) dataframe['aroonup'] = aroon['aroonup'] dataframe['aroondown'] = aroon['aroondown'] dataframe['aroonosc'] = ta.AROONOSC(dataframe) # Awesome Oscillator dataframe['ao'] = qtpylib.awesome_oscillator(dataframe) # # Keltner Channel # keltner = qtpylib.keltner_channel(dataframe) # dataframe["kc_upperband"] = keltner["upper"] # dataframe["kc_lowerband"] = keltner["lower"] # dataframe["kc_middleband"] = keltner["mid"] # dataframe["kc_percent"] = ( # (dataframe["close"] - dataframe["kc_lowerband"]) / # (dataframe["kc_upperband"] - dataframe["kc_lowerband"]) # ) # dataframe["kc_width"] = ( # (dataframe["kc_upperband"] - dataframe["kc_lowerband"]) / dataframe["kc_middleband"] # ) # Ultimate Oscillator dataframe['uo'] = ta.ULTOSC(dataframe) # Commodity Channel Index: values [Oversold:-100, Overbought:100] dataframe['cci'] = ta.CCI(dataframe) # RSI dataframe['rsi'] = ta.RSI(dataframe) # Inverse Fisher transform on RSI: values [-1.0, 1.0] (https://goo.gl/2JGGoy) rsi = 0.1 * (dataframe['rsi'] - 50) dataframe['fisher_rsi'] = (np.exp(2 * rsi) - 1) / (np.exp(2 * rsi) + 1) # Inverse Fisher transform on RSI normalized: values [0.0, 100.0] (https://goo.gl/2JGGoy) dataframe['fisher_rsi_norma'] = 50 * (dataframe['fisher_rsi'] + 1) # Stochastic Slow stoch = ta.STOCH(dataframe) dataframe['slowd'] = stoch['slowd'] dataframe['slowk'] = stoch['slowk'] # Stochastic Fast stoch_fast = ta.STOCHF(dataframe) dataframe['fastd'] = stoch_fast['fastd'] dataframe['fastk'] = stoch_fast['fastk'] # Stochastic RSI stoch_rsi = ta.STOCHRSI(dataframe) dataframe['fastd_rsi'] = stoch_rsi['fastd'] dataframe['fastk_rsi'] = stoch_rsi['fastk'] # MACD macd = ta.MACD(dataframe) dataframe['macd'] = macd['macd'] dataframe['macdsignal'] = macd['macdsignal'] dataframe['macdhist'] = macd['macdhist'] # MFI dataframe['mfi'] = ta.MFI(dataframe) # # ROC dataframe['roc'] = ta.ROC(dataframe) # Overlap Studies # ------------------------------------ # # Bollinger Bands # bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=2) # dataframe['bb_lowerband'] = bollinger['lower'] # dataframe['bb_middleband'] = bollinger['mid'] # dataframe['bb_upperband'] = bollinger['upper'] # dataframe["bb_percent"] = ( # (dataframe["close"] - dataframe["bb_lowerband"]) / # (dataframe["bb_upperband"] - dataframe["bb_lowerband"]) # ) # dataframe["bb_width"] = ( # (dataframe["bb_upperband"] - dataframe["bb_lowerband"]) / dataframe["bb_middleband"] # ) # # Bollinger Bands - Weighted (EMA based instead of SMA) # weighted_bollinger = qtpylib.weighted_bollinger_bands( # qtpylib.typical_price(dataframe), window=20, stds=2 # ) # dataframe["wbb_upperband"] = weighted_bollinger["upper"] # dataframe["wbb_lowerband"] = weighted_bollinger["lower"] # dataframe["wbb_middleband"] = weighted_bollinger["mid"] # dataframe["wbb_percent"] = ( # (dataframe["close"] - dataframe["wbb_lowerband"]) / # (dataframe["wbb_upperband"] - dataframe["wbb_lowerband"]) # ) # dataframe["wbb_width"] = ( # (dataframe["wbb_upperband"] - dataframe["wbb_lowerband"]) / # dataframe["wbb_middleband"] # ) # # EMA - Exponential Moving Average # dataframe['ema3'] = ta.EMA(dataframe, timeperiod=3) # dataframe['ema5'] = ta.EMA(dataframe, timeperiod=5) # dataframe['ema10'] = ta.EMA(dataframe, timeperiod=10) # dataframe['ema21'] = ta.EMA(dataframe, timeperiod=21) # dataframe['ema50'] = ta.EMA(dataframe, timeperiod=50) # dataframe['ema100'] = ta.EMA(dataframe, timeperiod=100) # # SMA - Simple Moving Average # dataframe['sma3'] = ta.SMA(dataframe, timeperiod=3) # dataframe['sma5'] = ta.SMA(dataframe, timeperiod=5) # dataframe['sma10'] = ta.SMA(dataframe, timeperiod=10) # dataframe['sma21'] = ta.SMA(dataframe, timeperiod=21) # dataframe['sma50'] = ta.SMA(dataframe, timeperiod=50) # dataframe['sma100'] = ta.SMA(dataframe, timeperiod=100) # Parabolic SAR # dataframe['sar'] = ta.SAR(dataframe) # TEMA - Triple Exponential Moving Average # dataframe['tema'] = ta.TEMA(dataframe, timeperiod=9) # # Cycle Indicator # # ------------------------------------ # # Hilbert Transform Indicator - SineWave # hilbert = ta.HT_SINE(dataframe) # dataframe['htsine'] = hilbert['sine'] # dataframe['htleadsine'] = hilbert['leadsine'] # # Pattern Recognition - Bullish candlestick patterns # # ------------------------------------ # # Hammer: values [0, 100] # dataframe['CDLHAMMER'] = ta.CDLHAMMER(dataframe) # # Inverted Hammer: values [0, 100] # dataframe['CDLINVERTEDHAMMER'] = ta.CDLINVERTEDHAMMER(dataframe) # # Dragonfly Doji: values [0, 100] # dataframe['CDLDRAGONFLYDOJI'] = ta.CDLDRAGONFLYDOJI(dataframe) # # Piercing Line: values [0, 100] # dataframe['CDLPIERCING'] = ta.CDLPIERCING(dataframe) # values [0, 100] # # Morningstar: values [0, 100] # dataframe['CDLMORNINGSTAR'] = ta.CDLMORNINGSTAR(dataframe) # values [0, 100] # # Three White Soldiers: values [0, 100] # dataframe['CDL3WHITESOLDIERS'] = ta.CDL3WHITESOLDIERS(dataframe) # values [0, 100] # # Pattern Recognition - Bearish candlestick patterns # # ------------------------------------ # # Hanging Man: values [0, 100] # dataframe['CDLHANGINGMAN'] = ta.CDLHANGINGMAN(dataframe) # # Shooting Star: values [0, 100] # dataframe['CDLSHOOTINGSTAR'] = ta.CDLSHOOTINGSTAR(dataframe) # # Gravestone Doji: values [0, 100] # dataframe['CDLGRAVESTONEDOJI'] = ta.CDLGRAVESTONEDOJI(dataframe) # # Dark Cloud Cover: values [0, 100] # dataframe['CDLDARKCLOUDCOVER'] = ta.CDLDARKCLOUDCOVER(dataframe) # # Evening Doji Star: values [0, 100] # dataframe['CDLEVENINGDOJISTAR'] = ta.CDLEVENINGDOJISTAR(dataframe) # # Evening Star: values [0, 100] # dataframe['CDLEVENINGSTAR'] = ta.CDLEVENINGSTAR(dataframe) # # Pattern Recognition - Bullish/Bearish candlestick patterns # # ------------------------------------ # # Three Line Strike: values [0, -100, 100] # dataframe['CDL3LINESTRIKE'] = ta.CDL3LINESTRIKE(dataframe) # # Spinning Top: values [0, -100, 100] # dataframe['CDLSPINNINGTOP'] = ta.CDLSPINNINGTOP(dataframe) # values [0, -100, 100] # # Engulfing: values [0, -100, 100] # dataframe['CDLENGULFING'] = ta.CDLENGULFING(dataframe) # values [0, -100, 100] # # Harami: values [0, -100, 100] # dataframe['CDLHARAMI'] = ta.CDLHARAMI(dataframe) # values [0, -100, 100] # # Three Outside Up/Down: values [0, -100, 100] # dataframe['CDL3OUTSIDE'] = ta.CDL3OUTSIDE(dataframe) # values [0, -100, 100] # # Three Inside Up/Down: values [0, -100, 100] # dataframe['CDL3INSIDE'] = ta.CDL3INSIDE(dataframe) # values [0, -100, 100] # # Chart type # # ------------------------------------ # # Heikin Ashi Strategy # heikinashi = qtpylib.heikinashi(dataframe) # dataframe['ha_open'] = heikinashi['open'] # dataframe['ha_close'] = heikinashi['close'] # dataframe['ha_high'] = heikinashi['high'] # dataframe['ha_low'] = heikinashi['low'] # Retrieve best bid and best ask from the orderbook # ------------------------------------ """ # first check if dataprovider is available if self.dp: if self.dp.runmode in ('live', 'dry_run'): ob = self.dp.orderbook(metadata['pair'], 1) dataframe['best_bid'] = ob['bids'][0][0] dataframe['best_ask'] = ob['asks'][0][0] """ return dataframe
def populate_indicators(dataframe: DataFrame) -> DataFrame: """ Adds several different TA indicators to the given DataFrame """ dataframe['sar'] = ta.SAR(dataframe) dataframe['adx'] = ta.ADX(dataframe) stoch = ta.STOCHF(dataframe) dataframe['fastd'] = stoch['fastd'] dataframe['fastk'] = stoch['fastk'] dataframe['blower'] = ta.BBANDS(dataframe, nbdevup=2, nbdevdn=2)['lowerband'] dataframe['sma'] = ta.SMA(dataframe, timeperiod=40) dataframe['tema'] = ta.TEMA(dataframe, timeperiod=9) dataframe['mfi'] = ta.MFI(dataframe) dataframe['cci'] = ta.CCI(dataframe) dataframe['rsi'] = ta.RSI(dataframe) dataframe['mom'] = ta.MOM(dataframe) dataframe['ema5'] = ta.EMA(dataframe, timeperiod=5) dataframe['ema10'] = ta.EMA(dataframe, timeperiod=10) dataframe['ema50'] = ta.EMA(dataframe, timeperiod=50) dataframe['ema100'] = ta.EMA(dataframe, timeperiod=100) dataframe['ao'] = awesome_oscillator(dataframe) macd = ta.MACD(dataframe) dataframe['macd'] = macd['macd'] dataframe['macdsignal'] = macd['macdsignal'] dataframe['macdhist'] = macd['macdhist'] # add volatility indicators dataframe['natr'] = ta.NATR(dataframe) # add volume indicators dataframe['obv'] = ta.OBV(dataframe) # add more momentum indicators dataframe['rocp'] = ta.ROCP(dataframe) # add some pattern recognition dataframe['CDL2CROWS'] = ta.CDL2CROWS(dataframe) dataframe['CDL3BLACKCROWS'] = ta.CDL3BLACKCROWS(dataframe) dataframe['CDL3INSIDE'] = ta.CDL3INSIDE(dataframe) dataframe['CDL3LINESTRIKE'] = ta.CDL3LINESTRIKE(dataframe) dataframe['CDL3OUTSIDE'] = ta.CDL3OUTSIDE(dataframe) dataframe['CDL3STARSINSOUTH'] = ta.CDL3STARSINSOUTH(dataframe) dataframe['CDL3WHITESOLDIERS'] = ta.CDL3WHITESOLDIERS(dataframe) dataframe['CDLADVANCEBLOCK'] = ta.CDLADVANCEBLOCK(dataframe) dataframe['CDLBELTHOLD'] = ta.CDLBELTHOLD(dataframe) dataframe['CDLBREAKAWAY'] = ta.CDLBREAKAWAY(dataframe) dataframe['CDLDOJI'] = ta.CDLDOJI(dataframe) dataframe['CDLDOJISTAR'] = ta.CDLDOJISTAR(dataframe) dataframe['CDLDRAGONFLYDOJI'] = ta.CDLDRAGONFLYDOJI(dataframe) dataframe['CDLENGULFING'] = ta.CDLENGULFING(dataframe) dataframe['CDLHAMMER'] = ta.CDLHAMMER(dataframe) dataframe['CDLBREAKAWAY'] = ta.CDLBREAKAWAY(dataframe) dataframe['CDLBREAKAWAY'] = ta.CDLBREAKAWAY(dataframe) # enter categorical time hour = datetime.strptime(str(dataframe['date'][len(dataframe) - 1]), "%Y-%m-%d %H:%M:%S").hour for h in range(24): dataframe['hour_{0:02}'.format(h)] = int(h == hour) return dataframe
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: """ Adds several different TA indicators to the given DataFrame Performance Note: For the best performance be frugal on the number of indicators you are using. Let uncomment only the indicator you are using in your strategies or your hyperopt configuration, otherwise you will waste your memory and CPU usage. :param dataframe: Dataframe with data from the exchange :param metadata: Additional information, like the currently traded pair :return: a Dataframe with all mandatory indicators for the strategies """ #divergences # - - - - # - # 4 3 2 1 0 #src[4] > src[2] and src[3] > src[2] and src[2] < src[1] and src[2] < src[0] dataframe['bullish_div'] = ( ( dataframe['close'].shift(4) > dataframe['close'].shift(2) ) & ( dataframe['close'].shift(3) > dataframe['close'].shift(2) ) & ( dataframe['close'].shift(2) < dataframe['close'].shift(1) ) & ( dataframe['close'].shift(2) < dataframe['close'] ) ) #queremos el volumen medio de las ultimas 24 velas, si es mayor queremos comprar, si es que no es volumen a la baja, esto habria que compararlo tomando el precio unas horas antes dataframe['mean24volume'] = dataframe.volume.rolling(24).mean() dataframe['mean68close'] = dataframe.close.rolling(68).mean() # - # - - - - # 4 3 2 1 0 #src[4] < src[2] and src[3] < src[2] and src[2] > src[1] and src[2] > src[0] dataframe['bearish_div'] = ( ( dataframe['close'].shift(4) < dataframe['close'].shift(2) ) & ( dataframe['close'].shift(3) < dataframe['close'].shift(2) ) & ( dataframe['close'].shift(2) > dataframe['close'].shift(1) ) & ( dataframe['close'].shift(2) > dataframe['close'] ) ) dataframe['cci_one'] = ta.CCI(dataframe, timeperiod=170) dataframe['cci_two'] = ta.CCI(dataframe, timeperiod=34) # Momentum Indicators # ------------------------------------ # ADX dataframe['adx'] = ta.ADX(dataframe) # # Plus Directional Indicator / Movement # dataframe['plus_dm'] = ta.PLUS_DM(dataframe) # dataframe['plus_di'] = ta.PLUS_DI(dataframe) # # Minus Directional Indicator / Movement # dataframe['minus_dm'] = ta.MINUS_DM(dataframe) # dataframe['minus_di'] = ta.MINUS_DI(dataframe) # # Aroon, Aroon Oscillator # aroon = ta.AROON(dataframe) # dataframe['aroonup'] = aroon['aroonup'] # dataframe['aroondown'] = aroon['aroondown'] # dataframe['aroonosc'] = ta.AROONOSC(dataframe) # # Awesome Oscillator # dataframe['ao'] = qtpylib.awesome_oscillator(dataframe) # # Keltner Channel # keltner = qtpylib.keltner_channel(dataframe) # dataframe["kc_upperband"] = keltner["upper"] # dataframe["kc_lowerband"] = keltner["lower"] # dataframe["kc_middleband"] = keltner["mid"] # dataframe["kc_percent"] = ( # (dataframe["close"] - dataframe["kc_lowerband"]) / # (dataframe["kc_upperband"] - dataframe["kc_lowerband"]) # ) # dataframe["kc_width"] = ( # (dataframe["kc_upperband"] - dataframe["kc_lowerband"]) / dataframe["kc_middleband"] # ) # # Ultimate Oscillator # dataframe['uo'] = ta.ULTOSC(dataframe) # # Commodity Channel Index: values [Oversold:-100, Overbought:100] dataframe['cci'] = ta.CCI(dataframe) # RSI dataframe['rsi'] = ta.RSI(dataframe) # # Inverse Fisher transform on RSI: values [-1.0, 1.0] (https://goo.gl/2JGGoy) # rsi = 0.1 * (dataframe['rsi'] - 50) # dataframe['fisher_rsi'] = (np.exp(2 * rsi) - 1) / (np.exp(2 * rsi) + 1) # # Inverse Fisher transform on RSI normalized: values [0.0, 100.0] (https://goo.gl/2JGGoy) # dataframe['fisher_rsi_norma'] = 50 * (dataframe['fisher_rsi'] + 1) # # Stochastic Slow # stoch = ta.STOCH(dataframe) # dataframe['slowd'] = stoch['slowd'] # dataframe['slowk'] = stoch['slowk'] # Stochastic Fast stoch_fast = ta.STOCHF(dataframe) dataframe['fastd'] = stoch_fast['fastd'] dataframe['fastk'] = stoch_fast['fastk'] # # Stochastic RSI # Please read https://github.com/freqtrade/freqtrade/issues/2961 before using this. # STOCHRSI is NOT aligned with tradingview, which may result in non-expected results. # stoch_rsi = ta.STOCHRSI(dataframe) # dataframe['fastd_rsi'] = stoch_rsi['fastd'] # dataframe['fastk_rsi'] = stoch_rsi['fastk'] # MACD macd = ta.MACD(dataframe) dataframe['macd'] = macd['macd'] dataframe['macdsignal'] = macd['macdsignal'] dataframe['macdhist'] = macd['macdhist'] # MFI dataframe['mfi'] = ta.MFI(dataframe) # # ROC # dataframe['roc'] = ta.ROC(dataframe) # Overlap Studies # ------------------------------------ # Bollinger Bands bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=2) dataframe['bb_lowerband'] = bollinger['lower'] dataframe['bb_middleband'] = bollinger['mid'] dataframe['bb_upperband'] = bollinger['upper'] dataframe["bb_percent"] = ( (dataframe["close"] - dataframe["bb_lowerband"]) / (dataframe["bb_upperband"] - dataframe["bb_lowerband"]) ) dataframe["bb_width"] = ( (dataframe["bb_upperband"] - dataframe["bb_lowerband"]) / dataframe["bb_middleband"] ) # Bollinger Bands - Weighted (EMA based instead of SMA) # weighted_bollinger = qtpylib.weighted_bollinger_bands( # qtpylib.typical_price(dataframe), window=20, stds=2 # ) # dataframe["wbb_upperband"] = weighted_bollinger["upper"] # dataframe["wbb_lowerband"] = weighted_bollinger["lower"] # dataframe["wbb_middleband"] = weighted_bollinger["mid"] # dataframe["wbb_percent"] = ( # (dataframe["close"] - dataframe["wbb_lowerband"]) / # (dataframe["wbb_upperband"] - dataframe["wbb_lowerband"]) # ) # dataframe["wbb_width"] = ( # (dataframe["wbb_upperband"] - dataframe["wbb_lowerband"]) / # dataframe["wbb_middleband"] # ) # # EMA - Exponential Moving Average dataframe['ema3'] = ta.EMA(dataframe, timeperiod=3) dataframe['ema5'] = ta.EMA(dataframe, timeperiod=5) dataframe['ema10'] = ta.EMA(dataframe, timeperiod=10) dataframe['ema21'] = ta.EMA(dataframe, timeperiod=21) dataframe['ema50'] = ta.EMA(dataframe, timeperiod=50) dataframe['ema100'] = ta.EMA(dataframe, timeperiod=100) dataframe['ema200'] = ta.EMA(dataframe, timeperiod=200) # # SMA - Simple Moving Average # dataframe['sma3'] = ta.SMA(dataframe, timeperiod=3) # dataframe['sma5'] = ta.SMA(dataframe, timeperiod=5) # dataframe['sma10'] = ta.SMA(dataframe, timeperiod=10) # dataframe['sma21'] = ta.SMA(dataframe, timeperiod=21) # dataframe['sma50'] = ta.SMA(dataframe, timeperiod=50) # dataframe['sma100'] = ta.SMA(dataframe, timeperiod=100) # Parabolic SAR dataframe['sar'] = ta.SAR(dataframe) # TEMA - Triple Exponential Moving Average dataframe['tema'] = ta.TEMA(dataframe, timeperiod=9) # Cycle Indicator # ------------------------------------ # Hilbert Transform Indicator - SineWave hilbert = ta.HT_SINE(dataframe) dataframe['htsine'] = hilbert['sine'] dataframe['htleadsine'] = hilbert['leadsine'] # Pattern Recognition - Bullish candlestick patterns # ------------------------------------ # # Hammer: values [0, 100] # dataframe['CDLHAMMER'] = ta.CDLHAMMER(dataframe) # # Inverted Hammer: values [0, 100] # dataframe['CDLINVERTEDHAMMER'] = ta.CDLINVERTEDHAMMER(dataframe) # # Dragonfly Doji: values [0, 100] # dataframe['CDLDRAGONFLYDOJI'] = ta.CDLDRAGONFLYDOJI(dataframe) # # Piercing Line: values [0, 100] # dataframe['CDLPIERCING'] = ta.CDLPIERCING(dataframe) # values [0, 100] # # Morningstar: values [0, 100] # dataframe['CDLMORNINGSTAR'] = ta.CDLMORNINGSTAR(dataframe) # values [0, 100] # # Three White Soldiers: values [0, 100] # dataframe['CDL3WHITESOLDIERS'] = ta.CDL3WHITESOLDIERS(dataframe) # values [0, 100] # Pattern Recognition - Bearish candlestick patterns # ------------------------------------ # # Hanging Man: values [0, 100] # dataframe['CDLHANGINGMAN'] = ta.CDLHANGINGMAN(dataframe) # # Shooting Star: values [0, 100] # dataframe['CDLSHOOTINGSTAR'] = ta.CDLSHOOTINGSTAR(dataframe) # # Gravestone Doji: values [0, 100] # dataframe['CDLGRAVESTONEDOJI'] = ta.CDLGRAVESTONEDOJI(dataframe) # # Dark Cloud Cover: values [0, 100] # dataframe['CDLDARKCLOUDCOVER'] = ta.CDLDARKCLOUDCOVER(dataframe) # # Evening Doji Star: values [0, 100] # dataframe['CDLEVENINGDOJISTAR'] = ta.CDLEVENINGDOJISTAR(dataframe) # # Evening Star: values [0, 100] # dataframe['CDLEVENINGSTAR'] = ta.CDLEVENINGSTAR(dataframe) # Pattern Recognition - Bullish/Bearish candlestick patterns # ------------------------------------ # # Three Line Strike: values [0, -100, 100] # dataframe['CDL3LINESTRIKE'] = ta.CDL3LINESTRIKE(dataframe) # # Spinning Top: values [0, -100, 100] # dataframe['CDLSPINNINGTOP'] = ta.CDLSPINNINGTOP(dataframe) # values [0, -100, 100] # # Engulfing: values [0, -100, 100] # dataframe['CDLENGULFING'] = ta.CDLENGULFING(dataframe) # values [0, -100, 100] # # Harami: values [0, -100, 100] # dataframe['CDLHARAMI'] = ta.CDLHARAMI(dataframe) # values [0, -100, 100] # # Three Outside Up/Down: values [0, -100, 100] # dataframe['CDL3OUTSIDE'] = ta.CDL3OUTSIDE(dataframe) # values [0, -100, 100] # # Three Inside Up/Down: values [0, -100, 100] # dataframe['CDL3INSIDE'] = ta.CDL3INSIDE(dataframe) # values [0, -100, 100] # # Chart type # # ------------------------------------ # Heikin Ashi Strategy heikinashi = qtpylib.heikinashi(dataframe) dataframe['ha_open'] = heikinashi['open'] dataframe['close'] = heikinashi['close'] dataframe['ha_high'] = heikinashi['high'] dataframe['ha_low'] = heikinashi['low'] dataframe['haclosestrat'] = (dataframe['ha_open'] + dataframe['ha_high'] + dataframe['ha_low'] + dataframe['close']) / 4 dataframe['haopenstrat'] = (dataframe['ha_open'] + dataframe['close']) / 2 dataframe['highstrat'] = max(dataframe['ha_high'] , max(dataframe['ha_open'], dataframe['close'] )) dataframe['lowstrat'] = min(dataframe['haLow'] , min(dataframe['ha_open'], dataframe['close'] )) # Retrieve best bid and best ask from the orderbook # ------------------------------------ return dataframe
while True: cci_total_today_buy = [] cci_total_yesterday_buy = [] df_sell = [] print("START") try: for i in range(len(coin_buy)): df_buy = pyupbit.get_ohlcv(coin_buy[i]) #print(df_buy) high_buy = df_buy['high'] #print(high_buy) low_buy = df_buy['low'] close_buy = df_buy['close'] cci_buy = ta.CCI(high_buy, low_buy, close_buy, timeperiod=20) print(coin_buy[i], cci_buy[-1]) cci_total_today_buy.append(int(cci_buy[-1])) cci_total_yesterday_buy.append(int(cci_buy[-2])) time.sleep(0.1) if cci_total_yesterday_buy[i] <= 50 < cci_total_today_buy[i]: print("매수시작") my_coin_buy = [] coin_list = [] for j in range(len(upbit.get_balances()[0])): coin_list.append(upbit.get_balances()[0][j]) my_coin_buy.append("KRW-" + coin_list[j].get('currency')) if my_coin_buy != "KRW-BTC": if my_coin_buy.count(coin_buy[i]) == 0: upbit.buy_market_order(coin_buy[i], 5000)
def populate_indicators(self, dataframe: DataFrame) -> DataFrame: # resampled dataframe to establish if we are in an uptrend, downtrend or sideways trend dataframe = StrategyHelper.resample(dataframe, self.ticker_interval, self.resample_factor) ################################################################################## # required for entry and exit # CCI dataframe['cci'] = ta.CCI(dataframe, timeperiod=20) dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14) dataframe['adx'] = ta.ADX(dataframe) dataframe['mfi'] = ta.MFI(dataframe) dataframe['mfi_smooth'] = ta.EMA(dataframe, timeperiod=11, price='mfi') dataframe['cci_smooth'] = ta.EMA(dataframe, timeperiod=11, price='cci') dataframe['rsi_smooth'] = ta.EMA(dataframe, timeperiod=11, price='rsi') ################################################################################## # required for graphing bollinger = qtpylib.bollinger_bands(dataframe['close'], window=20, stds=2) dataframe['bb_lowerband'] = bollinger['lower'] dataframe['bb_upperband'] = bollinger['upper'] dataframe['bb_middleband'] = bollinger['mid'] # MACD macd = ta.MACD(dataframe) dataframe['macd'] = macd['macd'] dataframe['macdsignal'] = macd['macdsignal'] dataframe['macdhist'] = macd['macdhist'] ################################################################################## # required for entry bollinger = qtpylib.bollinger_bands(dataframe['close'], window=20, stds=1.6) dataframe['entry_bb_lowerband'] = bollinger['lower'] dataframe['entry_bb_upperband'] = bollinger['upper'] dataframe['entry_bb_middleband'] = bollinger['mid'] dataframe['bpercent'] = (dataframe['close'] - dataframe['bb_lowerband']) / ( dataframe['bb_upperband'] - dataframe['bb_lowerband']) * 100 dataframe['bsharp'] = (dataframe['bb_upperband'] - dataframe['bb_lowerband']) / ( dataframe['bb_middleband']) # these seem to be kind useful to measure when bands widen # but than they are directly based on the moving average dataframe['bsharp_slow'] = ta.SMA(dataframe, price='bsharp', timeperiod=11) dataframe['bsharp_medium'] = ta.SMA(dataframe, price='bsharp', timeperiod=8) dataframe['bsharp_fast'] = ta.SMA(dataframe, price='bsharp', timeperiod=5) ################################################################################## # rsi and mfi are slightly weighted dataframe['mfi_rsi_cci_smooth'] = (dataframe['rsi_smooth'] * 1.125 + dataframe['mfi_smooth'] * 1.125 + dataframe[ 'cci_smooth']) / 3 dataframe['mfi_rsi_cci_smooth'] = ta.TEMA(dataframe, timeperiod=21, price='mfi_rsi_cci_smooth') # playgound dataframe['candle_size'] = (dataframe['close'] - dataframe['open']) * ( dataframe['close'] - dataframe['open']) / 2 # helps with pattern recognition dataframe['average'] = (dataframe['close'] + dataframe['open'] + dataframe['high'] + dataframe['low']) / 4 dataframe['sma_slow'] = ta.SMA(dataframe, timeperiod=200, price='close') dataframe['sma_medium'] = ta.SMA(dataframe, timeperiod=100, price='close') dataframe['sma_fast'] = ta.SMA(dataframe, timeperiod=50, price='close') return dataframe
def populate_indicators(dataframe: DataFrame) -> DataFrame: """ Adds several different TA indicators to the given DataFrame """ dataframe['adx'] = ta.ADX(dataframe) dataframe['ao'] = qtpylib.awesome_oscillator(dataframe) dataframe['cci'] = ta.CCI(dataframe) macd = ta.MACD(dataframe) dataframe['macd'] = macd['macd'] dataframe['macdsignal'] = macd['macdsignal'] dataframe['macdhist'] = macd['macdhist'] dataframe['mfi'] = ta.MFI(dataframe) dataframe['minus_dm'] = ta.MINUS_DM(dataframe) dataframe['minus_di'] = ta.MINUS_DI(dataframe) dataframe['plus_dm'] = ta.PLUS_DM(dataframe) dataframe['plus_di'] = ta.PLUS_DI(dataframe) dataframe['roc'] = ta.ROC(dataframe) dataframe['rsi'] = ta.RSI(dataframe) # Inverse Fisher transform on RSI, values [-1.0, 1.0] (https://goo.gl/2JGGoy) rsi = 0.1 * (dataframe['rsi'] - 50) dataframe['fisher_rsi'] = (numpy.exp(2 * rsi) - 1) / (numpy.exp(2 * rsi) + 1) # Inverse Fisher transform on RSI normalized, value [0.0, 100.0] (https://goo.gl/2JGGoy) dataframe['fisher_rsi_norma'] = 50 * (dataframe['fisher_rsi'] + 1) # Stoch stoch = ta.STOCH(dataframe) dataframe['slowd'] = stoch['slowd'] dataframe['slowk'] = stoch['slowk'] # Stoch fast stoch_fast = ta.STOCHF(dataframe) dataframe['fastd'] = stoch_fast['fastd'] dataframe['fastk'] = stoch_fast['fastk'] # Stoch RSI stoch_rsi = ta.STOCHRSI(dataframe) dataframe['fastd_rsi'] = stoch_rsi['fastd'] dataframe['fastk_rsi'] = stoch_rsi['fastk'] # Bollinger bands bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=2) dataframe['bb_lowerband'] = bollinger['lower'] dataframe['bb_middleband'] = bollinger['mid'] dataframe['bb_upperband'] = bollinger['upper'] # EMA - Exponential Moving Average dataframe['ema3'] = ta.EMA(dataframe, timeperiod=3) dataframe['ema5'] = ta.EMA(dataframe, timeperiod=5) dataframe['ema10'] = ta.EMA(dataframe, timeperiod=10) dataframe['ema50'] = ta.EMA(dataframe, timeperiod=50) dataframe['ema100'] = ta.EMA(dataframe, timeperiod=100) # SAR Parabolic dataframe['sar'] = ta.SAR(dataframe) # SMA - Simple Moving Average dataframe['sma'] = ta.SMA(dataframe, timeperiod=40) # TEMA - Triple Exponential Moving Average dataframe['tema'] = ta.TEMA(dataframe, timeperiod=9) # Hilbert Transform Indicator - SineWave hilbert = ta.HT_SINE(dataframe) dataframe['htsine'] = hilbert['sine'] dataframe['htleadsine'] = hilbert['leadsine'] # Pattern Recognition - Bullish candlestick patterns # ------------------------------------ """ # Hammer: values [0, 100] dataframe['CDLHAMMER'] = ta.CDLHAMMER(dataframe) # Inverted Hammer: values [0, 100] dataframe['CDLINVERTEDHAMMER'] = ta.CDLINVERTEDHAMMER(dataframe) # Dragonfly Doji: values [0, 100] dataframe['CDLDRAGONFLYDOJI'] = ta.CDLDRAGONFLYDOJI(dataframe) # Piercing Line: values [0, 100] dataframe['CDLPIERCING'] = ta.CDLPIERCING(dataframe) # values [0, 100] # Morningstar: values [0, 100] dataframe['CDLMORNINGSTAR'] = ta.CDLMORNINGSTAR(dataframe) # values [0, 100] # Three White Soldiers: values [0, 100] dataframe['CDL3WHITESOLDIERS'] = ta.CDL3WHITESOLDIERS(dataframe) # values [0, 100] """ # Pattern Recognition - Bearish candlestick patterns # ------------------------------------ """ # Hanging Man: values [0, 100] dataframe['CDLHANGINGMAN'] = ta.CDLHANGINGMAN(dataframe) # Shooting Star: values [0, 100] dataframe['CDLSHOOTINGSTAR'] = ta.CDLSHOOTINGSTAR(dataframe) # Gravestone Doji: values [0, 100] dataframe['CDLGRAVESTONEDOJI'] = ta.CDLGRAVESTONEDOJI(dataframe) # Dark Cloud Cover: values [0, 100] dataframe['CDLDARKCLOUDCOVER'] = ta.CDLDARKCLOUDCOVER(dataframe) # Evening Doji Star: values [0, 100] dataframe['CDLEVENINGDOJISTAR'] = ta.CDLEVENINGDOJISTAR(dataframe) # Evening Star: values [0, 100] dataframe['CDLEVENINGSTAR'] = ta.CDLEVENINGSTAR(dataframe) """ # Pattern Recognition - Bullish/Bearish candlestick patterns # ------------------------------------ """ # Three Line Strike: values [0, -100, 100] dataframe['CDL3LINESTRIKE'] = ta.CDL3LINESTRIKE(dataframe) # Spinning Top: values [0, -100, 100] dataframe['CDLSPINNINGTOP'] = ta.CDLSPINNINGTOP(dataframe) # values [0, -100, 100] # Engulfing: values [0, -100, 100] dataframe['CDLENGULFING'] = ta.CDLENGULFING(dataframe) # values [0, -100, 100] # Harami: values [0, -100, 100] dataframe['CDLHARAMI'] = ta.CDLHARAMI(dataframe) # values [0, -100, 100] # Three Outside Up/Down: values [0, -100, 100] dataframe['CDL3OUTSIDE'] = ta.CDL3OUTSIDE(dataframe) # values [0, -100, 100] # Three Inside Up/Down: values [0, -100, 100] dataframe['CDL3INSIDE'] = ta.CDL3INSIDE(dataframe) # values [0, -100, 100] """ # Chart type # ------------------------------------ # Heikinashi stategy heikinashi = qtpylib.heikinashi(dataframe) dataframe['ha_open'] = heikinashi['open'] dataframe['ha_close'] = heikinashi['close'] dataframe['ha_high'] = heikinashi['high'] dataframe['ha_low'] = heikinashi['low'] return dataframe
def cal_cci(self, period=14): self.analysis_data['cci'] = ta.CCI(self.high, self.low, self.close, timeperiod=period)
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: """ Adds several different TA indicators to the given DataFrame Performance Note: For the best performance be frugal on the number of indicators you are using. Let uncomment only the indicator you are using in your strategies or your hyperopt configuration, otherwise you will waste your memory and CPU usage. """ dataframe['ema20'] = ta.EMA(dataframe, timeperiod=20) dataframe['ema50'] = ta.EMA(dataframe, timeperiod=50) dataframe['ema100'] = ta.EMA(dataframe, timeperiod=100) heikinashi = qtpylib.heikinashi(dataframe) dataframe['ha_open'] = heikinashi['open'] dataframe['ha_close'] = heikinashi['close'] dataframe['adx'] = ta.ADX(dataframe) dataframe['rsi'] = ta.RSI(dataframe) macd = ta.MACD(dataframe) dataframe['macd'] = macd['macd'] dataframe['macdsignal'] = macd['macdsignal'] dataframe['macdhist'] = macd['macdhist'] bollinger = ta.BBANDS(dataframe, timeperiod=20, nbdevup=2.0, nbdevdn=2.0) dataframe['bb_lowerband'] = bollinger['lowerband'] dataframe['bb_middleband'] = bollinger['middleband'] dataframe['bb_upperband'] = bollinger['upperband'] # Stoch stoch = ta.STOCH(dataframe) dataframe['slowk'] = stoch['slowk'] # Commodity Channel Index: values Oversold:<-100, Overbought:>100 dataframe['cci'] = ta.CCI(dataframe) # Stoch stoch = ta.STOCHF(dataframe, 5) dataframe['fastd'] = stoch['fastd'] dataframe['fastk'] = stoch['fastk'] dataframe['fastk-previous'] = dataframe.fastk.shift(1) dataframe['fastd-previous'] = dataframe.fastd.shift(1) # Slow Stoch slowstoch = ta.STOCHF(dataframe, 50) dataframe['slowfastd'] = slowstoch['fastd'] dataframe['slowfastk'] = slowstoch['fastk'] dataframe['slowfastk-previous'] = dataframe.slowfastk.shift(1) dataframe['slowfastd-previous'] = dataframe.slowfastd.shift(1) # RSI dataframe['rsi'] = ta.RSI(dataframe) # Inverse Fisher transform on RSI, values [-1.0, 1.0] (https://goo.gl/2JGGoy) rsi = 0.1 * (dataframe['rsi'] - 50) dataframe['fisher_rsi'] = (numpy.exp(2 * rsi) - 1) / (numpy.exp(2 * rsi) + 1) # Bollinger bands bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=2) dataframe['bb_lowerband'] = bollinger['lower'] # SAR Parabol dataframe['sar'] = ta.SAR(dataframe) # Hammer: values [0, 100] dataframe['CDLHAMMER'] = ta.CDLHAMMER(dataframe) # SMA - Simple Moving Average dataframe['sma'] = ta.SMA(dataframe, timeperiod=40) return dataframe
def CCI(self): #14 cci = abstract.CCI(self.company_stock, timeperiod=14) self.company_stock['CCI'] = cci
def __countCCI(self): self.cci = ta.CCI(self.stock.inputs)