From 2743b32435ac46208c9c1f2ca18bb1476b2146f4 Mon Sep 17 00:00:00 2001 From: Joe Schr Date: Thu, 4 Mar 2021 14:53:17 +0100 Subject: [PATCH] fix(TrailingSL): add "hyperopt" check. use get_analyzed_dataframe() --- user_data/strategies/trailing_sl.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/user_data/strategies/trailing_sl.py b/user_data/strategies/trailing_sl.py index 364ac38..3469b4f 100644 --- a/user_data/strategies/trailing_sl.py +++ b/user_data/strategies/trailing_sl.py @@ -34,14 +34,19 @@ class TrailingSL(IStrategy): SL_INDICATOR_NAME = 'atr' result = 1 if self.custom_info[pair] is not None and trade is not None: - # using current_time directly (like below) will only work in backtesting. - # so check "runmode" to make sure that it's only used in backtesting - if(self.dp.runmode == RunMode.BACKTEST): - relative_sl = self.custom_info[pair].loc[current_time][SL_INDICATOR_NAME] + # using current_time directly (like below) will only work in backtesting/hyperopt. # in live / dry-run, it'll be really the current time - else: - # but we can just use the last entry to get the current value - relative_sl = self.custom_info[pair][SL_INDICATOR_NAME].iloc[ -1 ] + if self.dp: + # backtesting/hyperopt + if self.dp.runmode.value in ('backtest', 'hyperopt'): + relative_sl = self.custom_info[pair].loc[current_time][SL_INDICATOR_NAME] + # for live, dry-run, storing the dataframe is not really necessary, + # it's available from get_analyzed_dataframe() + else: + # so we need to get analyzed_dataframe from dp + dataframe, last_updated = self.dp.get_analyzed_dataframe(pair=pair, + timeframe=self.timeframe) + relative_sl = dataframe[last_updated][SL_INDICATOR_NAME] if (relative_sl is not None): print("Custom SL: {}".format(relative_sl))