diff --git a/freqtrade/constants.py b/freqtrade/constants.py index 0a49bca13..cf4f11e7c 100644 --- a/freqtrade/constants.py +++ b/freqtrade/constants.py @@ -36,7 +36,7 @@ AVAILABLE_PAIRLISTS = ['StaticPairList', 'VolumePairList', 'ProducerPairList', 'PrecisionFilter', 'PriceFilter', 'RangeStabilityFilter', 'ShuffleFilter', 'SpreadFilter', 'VolatilityFilter'] AVAILABLE_PROTECTIONS = ['CooldownPeriod', 'LowProfitPairs', 'MaxDrawdown', - 'StoplossGuard', 'ProfitLimit'] + 'StoplossGuard', 'ProfitLimit'] AVAILABLE_DATAHANDLERS_TRADES = ['json', 'jsongz', 'hdf5'] AVAILABLE_DATAHANDLERS = AVAILABLE_DATAHANDLERS_TRADES + ['feather', 'parquet'] BACKTEST_BREAKDOWNS = ['day', 'week', 'month'] diff --git a/freqtrade/plugins/protections/profit_limit.py b/freqtrade/plugins/protections/profit_limit.py index 17d10d467..ca49795a7 100644 --- a/freqtrade/plugins/protections/profit_limit.py +++ b/freqtrade/plugins/protections/profit_limit.py @@ -9,6 +9,7 @@ from freqtrade.plugins.protections import IProtection, ProtectionReturn logger = logging.getLogger(__name__) + class ProfitLimit(IProtection): has_global_stop: bool = True @@ -16,7 +17,7 @@ class ProfitLimit(IProtection): def __init__(self, config: Config, protection_config: Dict[str, Any]) -> None: super().__init__(config, protection_config) - + self._trade_limit = protection_config.get('trade_limit', 1) self._required_profit = protection_config.get('profit_limit', 1.0) @@ -47,10 +48,10 @@ class ProfitLimit(IProtection): # Not enough trades in the relevant period return None - profit_sum = trades['profit_abs'].sum() - stake_sum = trades['stake_amount'].sum() + profit_sum = sum(trade.close_profit_abs for trade in trades if trade.close_profit_abs) + stake_sum = sum(trade.stake_amount for trade in trades) profit_ratio = profit_sum / stake_sum - + if profit_ratio >= self._required_profit: self.log_once( f"Trading stopped due to {profit_ratio:.2f} >= {self._required_profit} "