def populate_indicators(dataframe: DataFrame, metadata: dict) -> DataFrame: dataframe["rsi"] = ta.RSI(dataframe) bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=1) dataframe["bb1_lowerband"] = bollinger["lower"] dataframe["bb1_middleband"] = bollinger["mid"] dataframe["bb1_upperband"] = bollinger["upper"] bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=2) dataframe["bb2_lowerband"] = bollinger["lower"] dataframe["bb2_middleband"] = bollinger["mid"] dataframe["bb2_upperband"] = bollinger["upper"] bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=3) dataframe["bb3_lowerband"] = bollinger["lower"] dataframe["bb3_middleband"] = bollinger["mid"] dataframe["bb3_upperband"] = bollinger["upper"] bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=4) dataframe["bb4_lowerband"] = bollinger["lower"] dataframe["bb4_middleband"] = bollinger["mid"] dataframe["bb4_upperband"] = bollinger["upper"] return dataframe
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14) # Bollinger bands bollinger1 = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=1) dataframe['bb1_lowerband'] = bollinger1['lower'] dataframe['bb1_middleband'] = bollinger1['mid'] dataframe['bb1_upperband'] = bollinger1['upper'] bollinger2 = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=2) dataframe['bb2_lowerband'] = bollinger2['lower'] dataframe['bb2_middleband'] = bollinger2['mid'] dataframe['bb2_upperband'] = bollinger2['upper'] bollinger3 = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=3) dataframe['bb3_lowerband'] = bollinger3['lower'] dataframe['bb3_middleband'] = bollinger3['mid'] dataframe['bb3_upperband'] = bollinger3['upper'] bollinger4 = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=4) dataframe['bb4_lowerband'] = bollinger4['lower'] dataframe['bb4_middleband'] = bollinger4['mid'] dataframe['bb4_upperband'] = bollinger4['upper'] return dataframe
def populate_indicators(dataframe: DataFrame, metadata: dict) -> DataFrame: dataframe['rsi-buy'] = ta.RSI(dataframe) dataframe['rsi-sell'] = ta.RSI(dataframe) # Bollinger bands bollinger_1sd = qtpylib.bollinger_bands( qtpylib.typical_price(dataframe), window=20, stds=1) dataframe['bb_lowerband_1sd'] = bollinger_1sd['lower'] dataframe['bb_middleband_1sd'] = bollinger_1sd['mid'] dataframe['bb_upperband_1sd'] = bollinger_1sd['upper'] bollinger_2sd = qtpylib.bollinger_bands( qtpylib.typical_price(dataframe), window=20, stds=2) dataframe['bb_lowerband_2sd'] = bollinger_2sd['lower'] dataframe['bb_middleband_2sd'] = bollinger_2sd['mid'] dataframe['bb_upperband_2sd'] = bollinger_2sd['upper'] bollinger_3sd = qtpylib.bollinger_bands( qtpylib.typical_price(dataframe), window=20, stds=3) dataframe['bb_lowerband_3sd'] = bollinger_3sd['lower'] dataframe['bb_middleband_3sd'] = bollinger_3sd['mid'] dataframe['bb_upperband_3sd'] = bollinger_3sd['upper'] bollinger_4sd = qtpylib.bollinger_bands( qtpylib.typical_price(dataframe), window=20, stds=4) dataframe['bb_lowerband_4sd'] = bollinger_4sd['lower'] dataframe['bb_middleband_4sd'] = bollinger_4sd['mid'] dataframe['bb_upperband_4sd'] = bollinger_4sd['upper'] 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 """ # Momentum Indicators # ------------------------------------ # RSI dataframe['rsi'] = ta.RSI(dataframe) dataframe['sell-rsi'] = ta.RSI(dataframe) # Bollinger Bands 1 STD bollinger1 = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=1) dataframe['bb_lowerband1'] = bollinger1['lower'] dataframe['bb_middleband1'] = bollinger1['mid'] dataframe['bb_upperband1'] = bollinger1['upper'] # Bollinger Bands 4 STD bollinger4 = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=4) dataframe['bb_lowerband4'] = bollinger4['lower'] dataframe['bb_middleband4'] = bollinger4['mid'] dataframe['bb_upperband4'] = bollinger4['upper'] return dataframe
def populate_indicators(dataframe: DataFrame, metadata: dict) -> DataFrame: dataframe['rsi'] = ta.RSI(dataframe) dataframe['sell-rsi'] = ta.RSI(dataframe) # Bollinger bands bollinger1 = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=1) dataframe['bb_lowerband1'] = bollinger1['lower'] dataframe['bb_middleband1'] = bollinger1['mid'] dataframe['bb_upperband1'] = bollinger1['upper'] bollinger2 = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=2) dataframe['bb_lowerband2'] = bollinger2['lower'] dataframe['bb_middleband2'] = bollinger2['mid'] dataframe['bb_upperband2'] = bollinger2['upper'] bollinger3 = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=3) dataframe['bb_lowerband3'] = bollinger3['lower'] dataframe['bb_middleband3'] = bollinger3['mid'] dataframe['bb_upperband3'] = bollinger3['upper'] bollinger4 = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=4) dataframe['bb_lowerband4'] = bollinger4['lower'] dataframe['bb_middleband4'] = bollinger4['mid'] dataframe['bb_upperband4'] = bollinger4['upper'] return dataframe
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: # RSI dataframe['rsi'] = ta.RSI(dataframe) # Bollinger bands bollinger_1sd = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=1) dataframe['bb_upperband_1sd'] = bollinger_1sd['upper'] dataframe['bb_lowerband_1sd'] = bollinger_1sd['lower'] bollinger_4sd = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=4) dataframe['bb_lowerband_4sd'] = bollinger_4sd['lower'] return dataframe
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: # Set Up Bollinger Bands mid, lower = bollinger_bands(dataframe['close'], window_size=40, num_of_std=2) dataframe['lower'] = lower dataframe['bbdelta'] = (mid - dataframe['lower']).abs() dataframe['closedelta'] = (dataframe['close'] - dataframe['close'].shift()).abs() dataframe['tail'] = (dataframe['close'] - dataframe['low']).abs() bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=2) dataframe['bb_lowerband'] = bollinger['lower'] dataframe['bb_middleband'] = bollinger['mid'] dataframe['ema_slow'] = ta.EMA(dataframe, timeperiod=50) dataframe['volume_mean_slow'] = dataframe['volume'].rolling( window=30).mean() dataframe['rocr'] = ta.ROCR(dataframe, timeperiod=28) inf_tf = '1h' informative = self.dp.get_pair_dataframe(pair=metadata['pair'], timeframe=inf_tf) informative['rocr'] = ta.ROCR(informative, timeperiod=168) dataframe = merge_informative_pair(dataframe, informative, self.timeframe, inf_tf, ffill=True) return dataframe
def normal_tf_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: # strategy BinHV45 bb_40 = qtpylib.bollinger_bands(dataframe['close'], window=40, stds=2) dataframe['lower'] = bb_40['lower'] dataframe['mid'] = bb_40['mid'] dataframe['bbdelta'] = (bb_40['mid'] - dataframe['lower']).abs() dataframe['closedelta'] = (dataframe['close'] - dataframe['close'].shift()).abs() dataframe['tail'] = (dataframe['close'] - dataframe['low']).abs() # strategy ClucMay72018 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['ema_slow'] = ta.EMA(dataframe, timeperiod=50) dataframe['volume_mean_slow'] = dataframe['volume'].rolling(window=30).mean() # EMA dataframe['ema_50'] = ta.EMA(dataframe, timeperiod=50) dataframe['ema_200'] = ta.EMA(dataframe, timeperiod=200) # SMA dataframe['sma_5'] = ta.EMA(dataframe, timeperiod=5) # RSI dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14) return dataframe
def populate_indicators(dataframe: DataFrame, metadata: dict) -> DataFrame: """ Add several indicators needed for buy and sell strategies defined below. """ # ADX dataframe['adx'] = ta.ADX(dataframe) # MACD macd = ta.MACD(dataframe) dataframe['macd'] = macd['macd'] dataframe['macdsignal'] = macd['macdsignal'] # MFI dataframe['mfi'] = ta.MFI(dataframe) # RSI dataframe['rsi'] = ta.RSI(dataframe) # Stochastic Fast stoch_fast = ta.STOCHF(dataframe) dataframe['fastd'] = stoch_fast['fastd'] # Minus-DI dataframe['minus_di'] = ta.MINUS_DI(dataframe) # Bollinger bands bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=2) dataframe['bb_lowerband'] = bollinger['lower'] dataframe['bb_upperband'] = bollinger['upper'] # SAR dataframe['sar'] = ta.SAR(dataframe) return dataframe
def do_populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: """ Adds multiple TA indicators to MoniGoMani's DataFrame per pair. Should be called with 'informative_pair' (1h candles) during backtesting/hyperopting with TimeFrame-Zoom! Performance Note: For the best performance be frugal on the number of indicators you are using. Only add in indicators that you are using in your weighted signal configuration for MoniGoMani, otherwise you will waste your memory and CPU usage. :param dataframe: (DataFrame) DataFrame with data from the exchange :param metadata: (dict) Additional information, like the currently traded pair :return DataFrame: DataFrame for MoniGoMani with all mandatory indicator data populated """ # Momentum Indicators (timeperiod is expressed in candles) # ------------------- # Parabolic SAR dataframe['sar'] = ta.SAR(dataframe) # Stochastic Slow stoch = ta.STOCH(dataframe) dataframe['slowk'] = stoch['slowk'] # MACD - Moving Average Convergence Divergence macd = ta.MACD(dataframe) dataframe['macd'] = macd[ 'macd'] # MACD - Blue TradingView Line (Bullish if on top) dataframe['macdsignal'] = macd[ 'macdsignal'] # Signal - Orange TradingView Line (Bearish if on top) # MFI - Money Flow Index (Under bought / Over sold & Over bought / Under sold / volume Indicator) dataframe['mfi'] = ta.MFI(dataframe) # Overlap Studies # --------------- # Bollinger Bands bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=2) dataframe['bb_middleband'] = bollinger['mid'] # SMA's & EMA's are trend following tools (Should not be used when line goes sideways) # SMA - Simple Moving Average (Moves slower compared to EMA, price trend over X periods) dataframe['sma9'] = ta.SMA(dataframe, timeperiod=9) dataframe['sma50'] = ta.SMA(dataframe, timeperiod=50) dataframe['sma200'] = ta.SMA(dataframe, timeperiod=200) # TEMA - Triple Exponential Moving Average dataframe['tema'] = ta.TEMA(dataframe, timeperiod=9) # Volume Indicators # ----------------- # Rolling VWAP - Volume Weighted Average Price dataframe['rolling_vwap'] = qtpylib.rolling_vwap(dataframe) return dataframe
def normal_tf_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: 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['volume_mean_slow'] = dataframe['volume'].rolling(window=48).mean() # EMA dataframe['ema_200'] = ta.EMA(dataframe, timeperiod=200) dataframe['ema_26'] = ta.EMA(dataframe, timeperiod=26) dataframe['ema_12'] = ta.EMA(dataframe, timeperiod=12) # MACD dataframe['macd'], dataframe['signal'], dataframe['hist'] = ta.MACD(dataframe['close'], fastperiod=12, slowperiod=26, signalperiod=9) # SMA dataframe['sma_5'] = ta.EMA(dataframe, timeperiod=5) # RSI dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14) # ------ ATR stuff dataframe['atr'] = ta.ATR(dataframe, timeperiod=14) # Calculate all ma_sell values for val in self.base_nb_candles_sell.range: dataframe[f'ma_sell_{val}'] = ta.EMA(dataframe, timeperiod=val) 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. """ dataframe['gap'] = dataframe['close'].shift(1) - ( (dataframe['high'].shift(1) - dataframe['low'].shift(1)) * 0.1) dataframe['adx'] = ta.ADX(dataframe) # MFI dataframe['mfi'] = ta.MFI(dataframe) # RSI dataframe['rsi'] = ta.RSI(dataframe) # Stochastic Fast stoch_fast = ta.STOCH(dataframe) dataframe['slowd'] = stoch_fast['slowd'] # Bollinger bands bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=2) dataframe['bb_lowerband'] = bollinger['lower'] dataframe['bb_upperband'] = bollinger['upper'] return dataframe
def populate_indicators(self, dataframe: DataFrame) -> DataFrame: ################################################################################## # buy and sell indicators 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'] macd = ta.MACD(dataframe) dataframe['macd'] = macd['macd'] dataframe['macdsignal'] = macd['macdsignal'] dataframe['macdhist'] = macd['macdhist'] # dataframe['cci'] = ta.CCI(dataframe) # dataframe['mfi'] = ta.MFI(dataframe) # dataframe['rsi'] = ta.RSI(dataframe, timeperiod=7) # dataframe['canbuy'] = np.NaN # dataframe['canbuy2'] = np.NaN # dataframe.loc[dataframe.close.rolling(49).min() <= 1.1 * dataframe.close, 'canbuy'] == 1 # dataframe.loc[dataframe.close.rolling(600).max() < 1.2 * dataframe.close, 'canbuy'] = 1 # dataframe.loc[dataframe.close.rolling(600).max() * 0.8 > dataframe.close, 'canbuy2'] = 1 ################################################################################## # 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) -> 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. """ # Stoch stoch = ta.STOCH(dataframe) dataframe['slowk'] = stoch['slowk'] # 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) 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 """ # RSI dataframe['rsi'] = ta.RSI(dataframe) for std in range(1, 5): # Bollinger bands bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=std) dataframe[f'bb_lowerband{std}'] = bollinger['lower'] dataframe[f'bb_middleband{std}'] = bollinger['mid'] dataframe[f'bb_upperband{std}'] = bollinger['upper'] # TEMA - Triple Exponential Moving Average dataframe[f'tema'] = ta.TEMA(dataframe, timeperiod=9) """ # 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 normal_tf_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: 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['volume_mean_slow'] = dataframe['volume'].rolling(window=48).mean() # EMA dataframe['ema_200'] = ta.EMA(dataframe, timeperiod=200) dataframe['ema_26'] = ta.EMA(dataframe, timeperiod=26) dataframe['ema_12'] = ta.EMA(dataframe, timeperiod=12) # MACD dataframe['macd'], dataframe['signal'], dataframe['hist'] = ta.MACD(dataframe['close'], fastperiod=12, slowperiod=26, signalperiod=9) # SMA dataframe['sma_5'] = ta.EMA(dataframe, timeperiod=5) # RSI dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14) return dataframe
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: # Set Up Bollinger Bands upper_bb1, mid_bb1, lower_bb1 = ta.BBANDS(dataframe['close'], timeperiod=40) upper_bb2, mid_bb2, lower_bb2 = ta.BBANDS( qtpylib.typical_price(dataframe), timeperiod=20) # only putting some bands into dataframe as the others are not used elsewhere in the strategy dataframe['lower-bb1'] = lower_bb1 dataframe['lower-bb2'] = lower_bb2 dataframe['mid-bb2'] = mid_bb2 dataframe['bb1-delta'] = (mid_bb1 - dataframe['lower-bb1']).abs() dataframe['closedelta'] = (dataframe['close'] - dataframe['close'].shift()).abs() dataframe['tail'] = (dataframe['close'] - dataframe['low']).abs() dataframe['ema_slow'] = ta.EMA(dataframe['close'], timeperiod=48) dataframe['volume_mean_slow'] = dataframe['volume'].rolling( window=24).mean() dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14) # # 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) dataframe['tema'] = ta.TEMA(dataframe, timeperiod=9) dataframe['adx'] = ta.ADX(dataframe) 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: Raw data from the exchange and parsed by parse_ticker_dataframe() :param metadata: Additional information, like the currently traded pair :return: a Dataframe with all mandatory indicators for the strategies """ length = 70 # Bollinger bands bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=length, stds=2) dataframe['lower'] = bollinger['lower'] dataframe['middle'] = bollinger['mid'] dataframe['upper'] = bollinger['upper'] # EMA dataframe['ema'] = ta.EMA(dataframe, timeperiod=length) return dataframe
def populate_indicators(self, dataframe: DataFrame) -> DataFrame: """ Adds several different TA indicators to the given DataFrame """ 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) return dataframe
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: # ADX dataframe['adx'] = ta.ADX(dataframe) # RSI dataframe['rsi'] = ta.RSI(dataframe) # 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"]) # TEMA dataframe['tema'] = ta.TEMA(dataframe, timeperiod=9) return dataframe
def pivots_points(dataframe: pd.DataFrame, timeperiod=1, levels=4) -> pd.DataFrame: """ Pivots Points https://www.tradingview.com/support/solutions/43000521824-pivot-points-standard/ Formula: Pivot = (Previous High + Previous Low + Previous Close)/3 Resistance #1 = (2 x Pivot) - Previous Low Support #1 = (2 x Pivot) - Previous High Resistance #2 = (Pivot - Support #1) + Resistance #1 Support #2 = Pivot - (Resistance #1 - Support #1) Resistance #3 = (Pivot - Support #2) + Resistance #2 Support #3 = Pivot - (Resistance #2 - Support #2) ... :param dataframe: :param timeperiod: Period to compare (in ticker) :param levels: Num of support/resistance desired :return: dataframe """ data = {} low = qtpylib.rolling_mean(series=pd.Series(index=dataframe.index, data=dataframe["low"]), window=timeperiod) high = qtpylib.rolling_mean(series=pd.Series(index=dataframe.index, data=dataframe["high"]), window=timeperiod) # Pivot data["pivot"] = qtpylib.rolling_mean( series=qtpylib.typical_price(dataframe), window=timeperiod) # Resistance #1 # data["r1"] = (2 * data["pivot"]) - low ... Standard # R1 = PP + 0.382 * (HIGHprev - LOWprev) ... fibonacci data["r1"] = data['pivot'] + 0.382 * (high - low) data["rS1"] = data['pivot'] + 0.0955 * (high - low) # Resistance #2 # data["s1"] = (2 * data["pivot"]) - high ... Standard # S1 = PP - 0.382 * (HIGHprev - LOWprev) ... fibonacci data["s1"] = data["pivot"] - 0.382 * (high - low) # Calculate Resistances and Supports >1 for i in range(2, levels + 1): prev_support = data["s" + str(i - 1)] prev_resistance = data["r" + str(i - 1)] # Resitance data["r" + str(i)] = (data["pivot"] - prev_support) + prev_resistance # Support data["s" + str(i)] = data["pivot"] - (prev_resistance - prev_support) return pd.DataFrame(index=dataframe.index, data=data)
def pivots_points(dataframe: pd.DataFrame, timeperiod=30, levels=3) -> pd.DataFrame: """ Pivots Points https://www.tradingview.com/support/solutions/43000521824-pivot-points-standard/ Formula: Pivot = (Previous High + Previous Low + Previous Close)/3 Resistance #1 = (2 x Pivot) - Previous Low Support #1 = (2 x Pivot) - Previous High Resistance #2 = (Pivot - Support #1) + Resistance #1 Support #2 = Pivot - (Resistance #1 - Support #1) Resistance #3 = (Pivot - Support #2) + Resistance #2 Support #3 = Pivot - (Resistance #2 - Support #2) ... :param dataframe: :param timeperiod: Period to compare (in ticker) :param levels: Num of support/resistance desired :return: dataframe """ data = {} low = qtpylib.rolling_mean(series=pd.Series(index=dataframe.index, data=dataframe['low']), window=timeperiod) high = qtpylib.rolling_mean(series=pd.Series(index=dataframe.index, data=dataframe['high']), window=timeperiod) # Pivot data['pivot'] = qtpylib.rolling_mean( series=qtpylib.typical_price(dataframe), window=timeperiod) # Resistance #1 data['r1'] = (2 * data['pivot']) - low # Resistance #2 data['s1'] = (2 * data['pivot']) - high # Calculate Resistances and Supports >1 for i in range(2, levels + 1): prev_support = data['s' + str(i - 1)] prev_resistance = data['r' + str(i - 1)] # Resitance data['r' + str(i)] = (data['pivot'] - prev_support) + prev_resistance # Support data['s' + str(i)] = data['pivot'] - (prev_resistance - prev_support) return pd.DataFrame(index=dataframe.index, data=data)
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: # Set Up Bollinger Bands upper_bb1, mid_bb1, lower_bb1 = ta.BBANDS(dataframe['close'], timeperiod=36) upper_bb2, mid_bb2, lower_bb2 = ta.BBANDS( qtpylib.typical_price(dataframe), timeperiod=12) # Only putting some bands into dataframe as the others are not used elsewhere in the strategy dataframe['lower-bb1'] = lower_bb1 dataframe['lower-bb2'] = lower_bb2 dataframe['mid-bb2'] = mid_bb2 dataframe['bb1-delta'] = (mid_bb1 - dataframe['lower-bb1']).abs() dataframe['closedelta'] = (dataframe['close'] - dataframe['close'].shift()).abs() dataframe['tail'] = (dataframe['close'] - dataframe['low']).abs() # Additional indicators dataframe['ema_fast'] = ta.EMA(dataframe['close'], timeperiod=6) dataframe['ema_slow'] = ta.EMA(dataframe['close'], timeperiod=48) dataframe['volume_mean_slow'] = dataframe['volume'].rolling( window=24).mean() dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14) # 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) # Informative Pair Indicators coin, stake = metadata['pair'].split('/') fiat = self.fiat stake_fiat = f"{stake}/{self.fiat}" coin_fiat = f"{coin}/{self.fiat}" coin_fiat_inf = self.dp.get_pair_dataframe(pair=f"{coin}/{fiat}", timeframe=self.timeframe) dataframe['coin-fiat-adx'] = ta.ADX(coin_fiat_inf, timeperiod=21) coin_aroon = ta.AROON(coin_fiat_inf, timeperiod=25) dataframe['coin-fiat-aroon-down'] = coin_aroon['aroondown'] dataframe['coin-fiat-aroon-up'] = coin_aroon['aroonup'] stake_fiat_inf = self.dp.get_pair_dataframe(pair=f"{stake}/{fiat}", timeframe=self.timeframe) dataframe['stake-fiat-adx'] = ta.ADX(stake_fiat_inf, timeperiod=21) stake_aroon = ta.AROON(stake_fiat_inf, timeperiod=25) dataframe['stake-fiat-aroon-down'] = stake_aroon['aroondown'] dataframe['stake-fiat-aroon-up'] = stake_aroon['aroonup'] # These indicators are used to persist a buy signal in live trading only # They dramatically slow backtesting down if self.config['runmode'].value in ('live', 'dry_run'): dataframe['sar'] = ta.SAR(dataframe) return dataframe
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: # RSI dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14) dataframe['rsi_84'] = ta.RSI(dataframe, timeperiod=84) dataframe['rsi_112'] = ta.RSI(dataframe, timeperiod=112) # Bollinger bands bollinger1 = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=17, stds=1) dataframe['bb_lowerband'] = bollinger1['lower'] dataframe['bb_middleband'] = bollinger1['mid'] dataframe['bb_upperband'] = bollinger1['upper'] # Close delta dataframe['closedelta'] = (dataframe['close'] - dataframe['close'].shift()).abs() # Dip Protection dataframe['tpct_change_0'] = top_percent_change(dataframe, 0) dataframe['tpct_change_1'] = top_percent_change(dataframe, 1) dataframe['tpct_change_2'] = top_percent_change(dataframe, 2) dataframe['tpct_change_4'] = top_percent_change(dataframe, 4) dataframe['tpct_change_5'] = top_percent_change(dataframe, 5) dataframe['tpct_change_9'] = top_percent_change(dataframe, 9) # SMA dataframe['sma_50'] = ta.SMA(dataframe['close'], timeperiod=50) dataframe['sma_200'] = ta.SMA(dataframe['close'], timeperiod=200) # CTI dataframe['cti'] = pta.cti(dataframe["close"], length=20) # ADX dataframe['adx'] = ta.ADX(dataframe) # %R dataframe['r_14'] = williams_r(dataframe, period=14) dataframe['r_96'] = williams_r(dataframe, period=96) # MAMA / FAMA dataframe['hl2'] = (dataframe['high'] + dataframe['low']) / 2 dataframe['mama'], dataframe['fama'] = ta.MAMA(dataframe['hl2'], 0.5, 0.05) dataframe['mama_diff'] = ((dataframe['mama'] - dataframe['fama']) / dataframe['hl2']) # CRSI (3, 2, 100) crsi_closechange = dataframe['close'] / dataframe['close'].shift(1) crsi_updown = np.where(crsi_closechange.gt(1), 1.0, np.where(crsi_closechange.lt(1), -1.0, 0.0)) dataframe['crsi'] = (ta.RSI(dataframe['close'], timeperiod=3) + ta.RSI( crsi_updown, timeperiod=2) + ta.ROC(dataframe['close'], 100)) / 3 return dataframe
def populate_indicators(dataframe: DataFrame, metadata: dict) -> DataFrame: # 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['rsi'] = ta.RSI(dataframe, timeperiod=14) return dataframe
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: # Adding EMA's into the dataframe dataframe["s1_ema_xs"] = ta.EMA(dataframe, timeperiod=self.s1_ema_xs) dataframe["s1_ema_sm"] = ta.EMA(dataframe, timeperiod=self.s1_ema_sm) dataframe["s1_ema_md"] = ta.EMA(dataframe, timeperiod=self.s1_ema_md) dataframe["s1_ema_xl"] = ta.EMA(dataframe, timeperiod=self.s1_ema_xl) dataframe["s1_ema_xxl"] = ta.EMA(dataframe, timeperiod=self.s1_ema_xxl) s2_ema_value = ta.EMA(dataframe, timeperiod=self.s2_ema_input) s2_ema_xxl_value = ta.EMA(dataframe, timeperiod=200) dataframe[ "s2_ema"] = s2_ema_value - s2_ema_value * self.s2_ema_offset_input dataframe[ "s2_ema_xxl_off"] = s2_ema_xxl_value - s2_ema_xxl_value * self.s2_fib_lower_value dataframe["s2_ema_xxl"] = ta.EMA(dataframe, timeperiod=200) s2_bb_sma_value = ta.SMA(dataframe, timeperiod=self.s2_bb_sma_length) s2_bb_std_dev_value = ta.STDDEV(dataframe, self.s2_bb_std_dev_length) dataframe["s2_bb_std_dev_value"] = s2_bb_std_dev_value dataframe["s2_bb_lower_band"] = s2_bb_sma_value - ( s2_bb_std_dev_value * self.s2_bb_lower_offset) s2_fib_atr_value = ta.ATR(dataframe, timeframe=self.s2_fib_atr_len) s2_fib_sma_value = ta.SMA(dataframe, timeperiod=self.s2_fib_sma_len) dataframe[ "s2_fib_lower_band"] = s2_fib_sma_value - s2_fib_atr_value * self.s2_fib_lower_value s3_bollinger = qtpylib.bollinger_bands( qtpylib.typical_price(dataframe), window=20, stds=3) dataframe["s3_bb_lowerband"] = s3_bollinger["lower"] dataframe["s3_ema_long"] = ta.EMA(dataframe, timeperiod=self.s3_ema_long) dataframe["s3_ema_short"] = ta.EMA(dataframe, timeperiod=self.s3_ema_short) dataframe["s3_fast_ma"] = ta.EMA( dataframe["volume"] * dataframe["close"], self.s3_ma_fast) / ta.EMA(dataframe["volume"], self.s3_ma_fast) dataframe["s3_slow_ma"] = ta.EMA( dataframe["volume"] * dataframe["close"], self.s3_ma_slow) / ta.EMA(dataframe["volume"], self.s3_ma_slow) # Volume weighted MACD dataframe["fastMA"] = ta.EMA(dataframe["volume"] * dataframe["close"], 12) / ta.EMA(dataframe["volume"], 12) dataframe["slowMA"] = ta.EMA(dataframe["volume"] * dataframe["close"], 26) / ta.EMA(dataframe["volume"], 26) dataframe["vwmacd"] = dataframe["fastMA"] - dataframe["slowMA"] dataframe["signal"] = ta.EMA(dataframe["vwmacd"], 9) dataframe["hist"] = dataframe["vwmacd"] - dataframe["signal"] return dataframe
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: # Bollinger bands bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=21, stds=2.7) dataframe['bblow'] = bollinger['lower'] bollinger3 = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=21, stds=2.1) dataframe['bbhi'] = bollinger3['upper'] # MACD macd = ta.MACD(dataframe) dataframe['macd'] = macd['macd'] dataframe['macdsignal'] = macd['macdsignal'] dataframe['macdhist'] = macd['macdhist'] # #RSI dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14) # #StochRSI period = 14 smoothD = 3 SmoothK = 3 stochrsi = (dataframe['rsi'] - dataframe['rsi'].rolling(period).min() ) / (dataframe['rsi'].rolling(period).max() - dataframe['rsi'].rolling(period).min()) dataframe['srsi_k'] = stochrsi.rolling(SmoothK).mean() * 100 dataframe['srsi_d'] = dataframe['srsi_k'].rolling(smoothD).mean() # dataframe_5m = resample_to_interval(dataframe, 5) # dataframe_5m['rsi']=ta.RSI(dataframe_5m, timeperiod=14) # stochrsi_5m = (dataframe_5m['rsi'] - dataframe_5m['rsi'].rolling(period).min()) / (dataframe_5m['rsi'].rolling(period).max() - dataframe_5m['rsi'].rolling(period).min()) # dataframe_5m['srsik']= stochrsi_5m.rolling(SmoothK).mean() * 100 # dataframe_5m['srsid'] = dataframe_5m['srsi_k'].rolling(smoothD).mean() # dataframe = resampled_merge(dataframe, dataframe_5m, fill_na=True) return dataframe
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: # RSI dataframe['rsi'] = ta.RSI(dataframe) # Stochastic Slow stoch = ta.STOCH(dataframe) dataframe['slowd'] = stoch['slowd'] dataframe['slowk'] = stoch['slowk'] # Bollinger Bands bollinger1 = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=1) dataframe['bb_lowerband1'] = bollinger1['lower'] dataframe['bb_middleband1'] = bollinger1['mid'] dataframe['bb_upperband1'] = bollinger1['upper'] bollinger2 = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=2) dataframe['bb_lowerband2'] = bollinger2['lower'] dataframe['bb_middleband2'] = bollinger2['mid'] dataframe['bb_upperband2'] = bollinger2['upper'] bollinger3 = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=3) dataframe['bb_lowerband3'] = bollinger3['lower'] dataframe['bb_middleband3'] = bollinger3['mid'] dataframe['bb_upperband3'] = bollinger3['upper'] bollinger4 = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=4) dataframe['bb_lowerband4'] = bollinger4['lower'] dataframe['bb_middleband4'] = bollinger4['mid'] dataframe['bb_upperband4'] = bollinger4['upper'] 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 """ # Momentum Indicator # ------------------------------------ # ADX dataframe['adx'] = ta.ADX(dataframe) # MACD macd = ta.MACD(dataframe) dataframe['macd'] = macd['macd'] dataframe['macdsignal'] = macd['macdsignal'] dataframe['macdhist'] = macd['macdhist'] # Minus Directional Indicator / Movement dataframe['minus_di'] = ta.MINUS_DI(dataframe) # Plus Directional Indicator / Movement dataframe['plus_di'] = ta.PLUS_DI(dataframe) # RSI dataframe['rsi'] = ta.RSI(dataframe) # Stoch fast stoch_fast = ta.STOCHF(dataframe) dataframe['fastd'] = stoch_fast['fastd'] dataframe['fastk'] = stoch_fast['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['ema10'] = ta.EMA(dataframe, timeperiod=10) 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 """ # Momentum Indicators # ------------------------------------ dataframe['rsi'] = ta.RSI(dataframe) # # Stochastic RSI stoch_rsi = ta.STOCHRSI(dataframe) # dataframe['fastd_rsi'] = stoch_rsi['fastd'] dataframe['fastk_rsi'] = stoch_rsi['fastk'] # # 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) # MACD macd = ta.MACD(dataframe) dataframe['macd'] = macd['macd'] # dataframe['macdsignal'] = macd['macdsignal'] # dataframe['macdhist'] = macd['macdhist'] # Parabolic SAR dataframe['sar'] = ta.SAR(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'] # 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"] # ) return dataframe