async def evaluate(self, cryptocurrency, symbol, time_frame, candle_data, candle): try: if len(candle_data) >= self.period * 2: stochrsi_value = tulipy.stochrsi( data_util.drop_nan(candle_data), self.period)[-1] if stochrsi_value * self.TULIPY_INDICATOR_MULTIPLICATOR >= self.evaluator_config[ self.HIGH_LEVEL]: self.eval_note = 1 elif stochrsi_value * self.TULIPY_INDICATOR_MULTIPLICATOR <= self.evaluator_config[ self.LOW_LEVEL]: self.eval_note = -1 else: self.eval_note = stochrsi_value - 0.5 except tulipy.lib.InvalidOptionError as e: self.logger.debug(f"Error when computing StochRSI: {e}") self.logger.exception(e, False) self.eval_note = commons_constants.START_PENDING_EVAL_NOTE await self.evaluation_completed( cryptocurrency, symbol, time_frame, eval_time=evaluators_util.get_eval_time(full_candle=candle, time_frame=time_frame))
async def eval_impl(self): stochrsi_value = tulipy.stochrsi(self.data[PriceIndexes.IND_PRICE_CLOSE.value], self.evaluator_config[self.STOCHRSI_PERIOD])[-1] if stochrsi_value * self.TULIPY_INDICATOR_MULTIPLICATOR >= self.evaluator_config[self.HIGH_LEVEL]: self.eval_note = 1 elif stochrsi_value * self.TULIPY_INDICATOR_MULTIPLICATOR <= self.evaluator_config[self.LOW_LEVEL]: self.eval_note = -1 else: self.eval_note = stochrsi_value - 0.5
async def eval_impl(self): try: stochrsi_value = tulipy.stochrsi( self.data[PriceIndexes.IND_PRICE_CLOSE.value], self.evaluator_config[self.STOCHRSI_PERIOD])[-1] if stochrsi_value * self.TULIPY_INDICATOR_MULTIPLICATOR >= self.evaluator_config[ self.HIGH_LEVEL]: self.eval_note = 1 elif stochrsi_value * self.TULIPY_INDICATOR_MULTIPLICATOR <= self.evaluator_config[ self.LOW_LEVEL]: self.eval_note = -1 else: self.eval_note = stochrsi_value - 0.5 except InvalidOptionError as e: self.logger.debug(f"Error when computing stochrsi: {e}") self.logger.exception(e) self.eval_note = START_PENDING_EVAL_NOTE
def inds(self): Indicators = {} for i in range(len(self.time)): #i/o? ''' 2 = High, 3 = Low, 4 = Close, 5 = Volume collects the needed market data into one list to push to the indicators''' close = self.time[i][4].values.copy(order='C') high = self.time[i][2].values.copy(order='C') low = self.time[i][3].values.copy(order='C') volume = self.time[i][5].values.copy(order='C') # !!!This needs to be changed. Each volume of the base time must be indexed up to the slice __time = self.time[i][6] # these are the indicators currently being used, and recored Indicators[i] = { 'stochrsi': ti.stochrsi(close, 5), 'rsi': ti.rsi(close, 5), # indicators that need to be doublechecked 'mfi': ti.mfi(high, low, close, volume, 5), 'sar': ti.psar(high, low, .2, 2), 'cci': ti.cci(high, low, close, 5), 'ema': ti.ema(close, 5) } # this one is good Indicators[i]['stoch_k'], Indicators[i]['stoch_d'] = ti.stoch( high, low, close, 5, 3, 3) # check on this, to see if it functions properly Indicators[i]['bbands_lower'], Indicators[i]['bbands_middle'], Indicators[i]['bbands_upper'] = ti.bbands(close, 5, 2) Indicators[i]['macd'], Indicators[i]['macd_signal'], Indicators[i]['macd_histogram'] = ti.macd(close, 12, 26, 9) Indicators[i]['time'] = __time Indicators[i]['close'] = close ''' below changes the length of each array to match the longest one, for a pandas df np.nan for the tail of the shorter ones''' Indicators[i] = to_pd(Indicator=Indicators[i]).dropna(how='all') return Indicators
def add_stochrsi(df, period): df[f'stochrsi_{period}'] = pad_left(ti.stochrsi( np.array(df.close), period), len(np.array(df.close)))