diff --git a/docs/strategy-callbacks.md b/docs/strategy-callbacks.md index 2a14a3c84..74eef53c1 100644 --- a/docs/strategy-callbacks.md +++ b/docs/strategy-callbacks.md @@ -165,7 +165,9 @@ E.g. If the `current_rate` is 200 USD, then returning `0.02` will set the stoplo During backtesting, `current_rate` (and `current_profit`) are provided against the candle's high (or low for short trades) - while the resulting stoploss is evaluated against the candle's low (or high for short trades). The absolute value of the return value is used (the sign is ignored), so returning `0.05` or `-0.05` have the same result, a stoploss 5% below the current price. -Returning None will be interpreted as "no desire to change", and is the only safe way to return when you'd like to not modify the stoploss. +Returning `None` will be interpreted as "no desire to change", and is the only safe way to return when you'd like to not modify the stoploss. +`NaN` and `inf` values are considered invalid and will be ignored (identical to `None`). + Stoploss on exchange works similar to `trailing_stop`, and the stoploss on exchange is updated as configured in `stoploss_on_exchange_interval` ([More details about stoploss on exchange](stoploss.md#stop-loss-on-exchangefreqtrade)). diff --git a/freqtrade/strategy/interface.py b/freqtrade/strategy/interface.py index de3d0f349..e6d86926b 100644 --- a/freqtrade/strategy/interface.py +++ b/freqtrade/strategy/interface.py @@ -6,6 +6,7 @@ This module defines the interface to apply for strategies import logging from abc import ABC, abstractmethod from datetime import datetime, timedelta, timezone +from math import isinf, isnan from typing import Dict, List, Optional, Tuple, Union from pandas import DataFrame @@ -1423,7 +1424,9 @@ class IStrategy(ABC, HyperStrategyMixin): after_fill=after_fill, ) # Sanity check - error cases will return None - if stop_loss_value_custom: + if stop_loss_value_custom and not ( + isnan(stop_loss_value_custom) or isinf(stop_loss_value_custom) + ): stop_loss_value = stop_loss_value_custom trade.adjust_stop_loss( bound or current_rate, stop_loss_value, allow_refresh=after_fill