From 6ee3c82588e85ec0d048acc1f6c47cebd128d352 Mon Sep 17 00:00:00 2001 From: iterativ Date: Wed, 22 Sep 2021 18:51:24 +0300 Subject: [PATCH] sell_stoploss: switch to ATR based stoploss. --- NostalgiaForInfinityNext.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/NostalgiaForInfinityNext.py b/NostalgiaForInfinityNext.py index 6746627201..2572ca6a14 100644 --- a/NostalgiaForInfinityNext.py +++ b/NostalgiaForInfinityNext.py @@ -3377,9 +3377,19 @@ def sell_under_min(self, current_profit: float, last_candle) -> tuple: return False, None def sell_stoploss(self, current_profit: float, max_profit: float, max_loss: float, last_candle, previous_candle_1, trade: 'Trade', current_time: 'datetime') -> tuple: - if (current_profit < -0.0) and (last_candle['close'] < last_candle['ema_200']) and (last_candle['cmf'] < 0.0) and (((last_candle['ema_200'] - last_candle['close']) / last_candle['close']) < 0.004) and last_candle['rsi_14'] > previous_candle_1['rsi_14'] and (last_candle['rsi_14'] > (last_candle['rsi_14_1h'] + 10.0)) and (last_candle['sma_200_dec_24']) and (current_time - timedelta(minutes=1440) > trade.open_date_utc): - return True, 'signal_stoploss_u_e_1' - + if (last_candle['close'] < last_candle['ema_200']) and (last_candle['sma_200_dec_24']) and (last_candle['ema_25'] < last_candle['ema_50']) and (current_time - timedelta(minutes=1440) > trade.open_date_utc): + if (-0.12 <= current_profit < -0.08): + if (last_candle['close'] < last_candle['atr_high_thresh_1']) and (previous_candle_1['close'] > previous_candle_1['atr_high_thresh_1']): + return True, 'signal_stoploss_atr_1' + elif (-0.16 <= current_profit < -0.12): + if (last_candle['close'] < last_candle['atr_high_thresh_2']) and (previous_candle_1['close'] > previous_candle_1['atr_high_thresh_2']): + return True, 'signal_stoploss_atr_2' + elif (-0.2 <= current_profit < -0.16): + if (last_candle['close'] < last_candle['atr_high_thresh_3']) and (previous_candle_1['close'] > previous_candle_1['atr_high_thresh_3']): + return True, 'signal_stoploss_atr_3' + elif (current_profit < -0.2): + if (last_candle['close'] < last_candle['atr_high_thresh_4']) and (previous_candle_1['close'] > previous_candle_1['atr_high_thresh_4']): + return True, 'signal_stoploss_atr_4' return False, None def sell_pump_dec(self, current_profit: float, last_candle) -> tuple: @@ -4457,6 +4467,13 @@ def normal_tf_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFram dataframe['momdiv_coh'] = mom['momdiv_coh'] dataframe['momdiv_col'] = mom['momdiv_col'] + # ATR + dataframe['atr'] = ta.ATR(dataframe, timeperiod=14) + dataframe['atr_high_thresh_1'] = (dataframe['high'] - (dataframe['atr'] * 3.4)) + dataframe['atr_high_thresh_2'] = (dataframe['high'] - (dataframe['atr'] * 3.2)) + dataframe['atr_high_thresh_3'] = (dataframe['high'] - (dataframe['atr'] * 3.0)) + dataframe['atr_high_thresh_4'] = (dataframe['high'] - (dataframe['atr'] * 2.0)) + # Dip protection dataframe['tpct_change_0'] = self.top_percent_change(dataframe,0) dataframe['tpct_change_2'] = self.top_percent_change(dataframe,2)