# Buggy code
def adjust_stop_loss(
    self, current_price: float, stoploss: float, initial: bool = False
):
    """
    This adjusts the stop loss to it's most recently observed setting
    :param current_price: Current rate the asset is traded
    :param stoploss: Stoploss as factor (sample -0.05 -> -5% below current price).
    :param initial: Called to initiate stop_loss.
        Skips everything if self.stop_loss is already set.
    """
    if initial and not (self.stop_loss is None or self.stop_loss == 0):
        # Don't modify if called with initial and nothing to do
        return

    new_loss = float(current_price * (1 - abs(stoploss)))

    # no stop loss assigned yet
    if not self.stop_loss:
        logger.debug(f"{self.pair} - Assigning new stoploss...")
        self.stop_loss = new_loss
        self.stop_loss_pct = -1 * abs(stoploss)
        self.initial_stop_loss = new_loss
        self.initial_stop_loss_pct = -1 * abs(stoploss)
        self.stoploss_last_update = datetime.utcnow()

    # evaluate if the stop loss needs to be updated
    else:
        if new_loss > self.stop_loss:  # stop losses only walk up, never down!
            logger.debug(f"{self.pair} - Adjusting stoploss...")
            self.stop_loss = new_loss
            self.stop_loss_pct = -1 * abs(stoploss)
            self.stoploss_last_update = datetime.utcnow()
        else:
            logger.debug(f"{self.pair} - Keeping current stoploss...")

    logger.debug(
        f"{self.pair} - Stoploss adjusted. current_price={current_price:.8f}, "
        f"open_rate={self.open_rate:.8f}, max_rate={self.max_rate:.8f}, "
        f"initial_stop_loss={self.initial_stop_loss:.8f}, "
        f"stop_loss={self.stop_loss:.8f}. "
        f"Trailing stoploss saved us: "
        f"{float(self.stop_loss) - float(self.initial_stop_loss):.8f}."
    )


# Traceback (Exception)
2020-02-20 22:47:28,025 - freqtrade - ERROR - Fatal exception!
Traceback (most recent call last):
File "/opt/tradebot/freqtrade/.env/lib/python3.7/site-packages/talib/__init__.py", line 20, in wrapper
for arg in chain(args, kwargs.values())
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/freqtrade/freqtrade/main.py", line 36, in main
return_code = args['func'](args)
File "/freqtrade/freqtrade/commands/optimize_commands.py", line 76, in start_hyperopt
hyperopt.start()
File "/freqtrade/freqtrade/optimize/hyperopt.py", line 488, in start
preprocessed = self.backtesting.strategy.tickerdata_to_dataframe(data)
File "/freqtrade/freqtrade/strategy/interface.py", line 448, in tickerdata_to_dataframe
for pair, pair_data in tickerdata.items()}
File "/freqtrade/freqtrade/strategy/interface.py", line 448, in <dictcomp>
for pair, pair_data in tickerdata.items()}
File "/freqtrade/freqtrade/strategy/interface.py", line 464, in advise_indicators
return self.populate_indicators(dataframe, metadata)
File "/freqtrade/user_data/strategies/MyDev.py", line 205, in populate_indicators
dataframe['mfi'] = ta.MFI(dataframe)
File "talib/_abstract.pxi", line 352, in talib._ta_lib.Function.__call__
File "talib/_abstract.pxi", line 383, in talib._ta_lib.Function.__call_function
File "/opt/tradebot/freqtrade/.env/lib/python3.7/site-packages/talib/__init__.py", line 24, in wrapper
return func(*args, **kwargs)
File "talib/_func.pxi", line 8454, in talib._ta_lib.MFI
Exception: volume is not double

# Fixed code
def adjust_stop_loss(
    self, current_price: float, stoploss: float, initial: bool = False
) -> None:
    """
    This adjusts the stop loss to it's most recently observed setting
    :param current_price: Current rate the asset is traded
    :param stoploss: Stoploss as factor (sample -0.05 -> -5% below current price).
    :param initial: Called to initiate stop_loss.
        Skips everything if self.stop_loss is already set.
    """
    if initial and not (self.stop_loss is None or self.stop_loss == 0):
        # Don't modify if called with initial and nothing to do
        return

    new_loss = float(current_price * (1 - abs(stoploss)))

    # no stop loss assigned yet
    if not self.stop_loss:
        logger.debug(f"{self.pair} - Assigning new stoploss...")
        self.stop_loss = new_loss
        self.stop_loss_pct = -1 * abs(stoploss)
        self.initial_stop_loss = new_loss
        self.initial_stop_loss_pct = -1 * abs(stoploss)
        self.stoploss_last_update = datetime.utcnow()

    # evaluate if the stop loss needs to be updated
    else:
        if new_loss > self.stop_loss:  # stop losses only walk up, never down!
            logger.debug(f"{self.pair} - Adjusting stoploss...")
            self.stop_loss = new_loss
            self.stop_loss_pct = -1 * abs(stoploss)
            self.stoploss_last_update = datetime.utcnow()
        else:
            logger.debug(f"{self.pair} - Keeping current stoploss...")

    logger.debug(
        f"{self.pair} - Stoploss adjusted. current_price={current_price:.8f}, "
        f"open_rate={self.open_rate:.8f}, max_rate={self.max_rate:.8f}, "
        f"initial_stop_loss={self.initial_stop_loss:.8f}, "
        f"stop_loss={self.stop_loss:.8f}. "
        f"Trailing stoploss saved us: "
        f"{float(self.stop_loss) - float(self.initial_stop_loss):.8f}."
    )