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 populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: dataframe['rocr'] = ta.ROCR(dataframe, period=499) dataframe['rocr_200'] = ta.ROCR(dataframe, period=200) dataframe['rocr_100'] = ta.ROCR(dataframe, period=100) dataframe['rocr_20'] = ta.ROCR(dataframe, period=20) return dataframe
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: # # Heikin Ashi Candles heikinashi = qtpylib.heikinashi(dataframe) dataframe['ha_open'] = heikinashi['open'] dataframe['ha_close'] = heikinashi['close'] dataframe['ha_high'] = heikinashi['high'] dataframe['ha_low'] = heikinashi['low'] # Set Up Bollinger Bands mid, lower = bollinger_bands(ha_typical_price(dataframe), window_size=40, num_of_std=2) dataframe['lower'] = lower dataframe['mid'] = mid dataframe['bbdelta'] = (mid - dataframe['lower']).abs() dataframe['closedelta'] = (dataframe['ha_close'] - dataframe['ha_close'].shift()).abs() dataframe['tail'] = (dataframe['ha_close'] - dataframe['ha_low']).abs() dataframe['bb_lowerband'] = dataframe['lower'] dataframe['bb_middleband'] = dataframe['mid'] dataframe['ema_fast'] = ta.EMA(dataframe['ha_close'], timeperiod=3) dataframe['ema_slow'] = ta.EMA(dataframe['ha_close'], timeperiod=50) dataframe['volume_mean_slow'] = dataframe['volume'].rolling( window=30).mean() dataframe['rocr'] = ta.ROCR(dataframe['ha_close'], timeperiod=28) rsi = ta.RSI(dataframe) dataframe["rsi"] = rsi rsi = 0.1 * (rsi - 50) dataframe["fisher"] = (np.exp(2 * rsi) - 1) / (np.exp(2 * rsi) + 1) inf_tf = '1h' informative = self.dp.get_pair_dataframe(pair=metadata['pair'], timeframe=inf_tf) inf_heikinashi = qtpylib.heikinashi(informative) informative['ha_close'] = inf_heikinashi['close'] informative['rocr'] = ta.ROCR(informative['ha_close'], timeperiod=168) dataframe = merge_informative_pair(dataframe, informative, self.timeframe, inf_tf, ffill=True) return dataframe
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: dataframe['rocr_499'] = ta.ROCR(dataframe, timeperiod=499) dataframe['rocr_200'] = ta.ROCR(dataframe, timeperiod=200) dataframe['rocr_100'] = ta.ROCR(dataframe, timeperiod=100) dataframe['rocr_50'] = ta.ROCR(dataframe, timeperiod=50) dataframe['rocr_10'] = ta.ROCR(dataframe, timeperiod=10) dataframe['rocr_5'] = ta.ROCR(dataframe, timeperiod=5) dataframe['rocr_2'] = ta.ROCR(dataframe, timeperiod=2) return dataframe
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: # Misc. calculations regarding existing open positions (reset on every loop iteration) self.custom_trade_info[metadata['pair']] = trade_data = {} trade_data['active_trade'] = trade_data['other_trades'] = False if self.config['runmode'].value in ('live', 'dry_run'): active_trade = Trade.get_trades([ Trade.pair == metadata['pair'], Trade.is_open.is_(True), ]).all() other_trades = Trade.get_trades([ Trade.pair != metadata['pair'], Trade.is_open.is_(True), ]).all() if active_trade: current_rate = self.get_current_price(metadata['pair']) active_trade[0].adjust_min_max_rates(current_rate) trade_data['active_trade'] = True trade_data['current_profit'] = active_trade[ 0].calc_profit_ratio(current_rate) trade_data['peak_profit'] = active_trade[0].calc_profit_ratio( active_trade[0].max_rate) if other_trades: trade_data['other_trades'] = True total_other_profit = tuple( trade.calc_profit_ratio(self.get_current_price(trade.pair)) for trade in other_trades) trade_data['avg_other_profit'] = mean(total_other_profit) self.custom_trade_info[metadata['pair']] = trade_data # 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'] # Set up other indicators dataframe['volume-mean-slow'] = dataframe['volume'].rolling( window=24).mean() dataframe['rmi-slow'] = RMI(dataframe, length=20, mom=5) dataframe['rmi-fast'] = RMI(dataframe, length=9, mom=3) dataframe['rocr'] = ta.ROCR(dataframe, timeperiod=28) dataframe['ema-slow'] = ta.EMA(dataframe, timeperiod=50) # Trend Calculations dataframe['max'] = dataframe['high'].rolling(12).max() dataframe['min'] = dataframe['low'].rolling(12).min() dataframe['upper'] = np.where( dataframe['max'] > dataframe['max'].shift(), 1, 0) dataframe['lower'] = np.where( dataframe['min'] < dataframe['min'].shift(), 1, 0) dataframe['up_trend'] = np.where( dataframe['upper'].rolling(3, min_periods=1).sum() != 0, 1, 0) dataframe['dn_trend'] = np.where( dataframe['lower'].rolling(3, min_periods=1).sum() != 0, 1, 0) # Informative Pair Indicators informative = self.dp.get_pair_dataframe(pair=metadata['pair'], timeframe=self.inf_timeframe) informative['rocr'] = ta.ROCR(informative, timeperiod=168) dataframe = merge_informative_pair(dataframe, informative, self.timeframe, self.inf_timeframe, ffill=True) return dataframe
def __call__(self, data: np.ndarray): return (ta.ROCR(data[OHLCVT.close], timeperiod=self.period) - 1) * 100
def do_indicators(self, dataframe: DataFrame, metadata: dict): # # Standard Settings # displacement = 26 # ichimoku = ftt.ichimoku(dataframe, # conversion_line_period=9, # base_line_periods=26, # laggin_span=52, # displacement=displacement # ) # Crypto Settings displacement = 30 ichimoku = ftt.ichimoku(dataframe, conversion_line_period=20, base_line_periods=60, laggin_span=120, displacement=displacement) dataframe['chikou_span'] = ichimoku['chikou_span'] # cross indicators dataframe['tenkan_sen'] = ichimoku['tenkan_sen'] dataframe['kijun_sen'] = ichimoku['kijun_sen'] # cloud, green a > b, red a < b dataframe['senkou_a'] = ichimoku['senkou_span_a'] dataframe['senkou_b'] = ichimoku['senkou_span_b'] dataframe['leading_senkou_span_a'] = ichimoku['leading_senkou_span_a'] dataframe['leading_senkou_span_b'] = ichimoku['leading_senkou_span_b'] dataframe['cloud_green'] = ichimoku['cloud_green'] * 1 dataframe['cloud_red'] = ichimoku['cloud_red'] * -1 # DANGER ZONE START # NOTE: Not actually the future, present data that is normally shifted forward for display as the cloud dataframe['future_green'] = ( dataframe['leading_senkou_span_a'] > dataframe['leading_senkou_span_b']).astype('int') * 2 # The chikou_span is shifted into the past, so we need to be careful not to read the # current value. But if we shift it forward again by displacement it should be safe to use. # We're effectively "looking back" at where it normally appears on the chart. dataframe['chikou_high'] = ( (dataframe['chikou_span'] > dataframe['senkou_a']) & (dataframe['chikou_span'] > dataframe['senkou_b']) ).shift(displacement).fillna(0).astype('int') # DANGER ZONE END ssl_down, ssl_up = SSLChannels(dataframe, 10) dataframe['ssl_down'] = ssl_down dataframe['ssl_up'] = ssl_up dataframe['ssl_high'] = (ssl_up > ssl_down).astype('int') * 3 dataframe['rocr'] = ta.ROCR(dataframe, timeperiod=28) dataframe['rmi-fast'] = ftt.RMI(dataframe, length=9, mom=3) dataframe['go_long'] = ( (dataframe['tenkan_sen'] > dataframe['kijun_sen']) & (dataframe['close'] > dataframe['senkou_a']) & (dataframe['close'] > dataframe['senkou_b']) & (dataframe['future_green'] > 0) & (dataframe['chikou_high'] > 0) & (dataframe['ssl_high'] > 0) & (dataframe['rocr'] > dataframe['rocr'].shift()) & (dataframe['rmi-fast'] > dataframe['rmi-fast'].shift(2)) ).astype('int') * 4 return dataframe
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: dataframe['rocr'] = ta.ROCR(dataframe, timeperiod=5) dataframe['rocr_2'] = ta.ROCR(dataframe, timeperiod=2) return dataframe