From: Jérôme Benoit Date: Tue, 18 Mar 2025 23:41:10 +0000 (+0100) Subject: refactor(qav3): add some tunable for custom dynamic stoploss X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=b0f64096493450bfa5a7671e3f45717fccf9e567;p=freqai-strategies.git refactor(qav3): add some tunable for custom dynamic stoploss Signed-off-by: Jérôme Benoit --- diff --git a/quickadapter/user_data/strategies/QuickAdapterV3.py b/quickadapter/user_data/strategies/QuickAdapterV3.py index 3cde9c3..f2c05aa 100644 --- a/quickadapter/user_data/strategies/QuickAdapterV3.py +++ b/quickadapter/user_data/strategies/QuickAdapterV3.py @@ -44,22 +44,31 @@ class QuickAdapterV3(IStrategy): INTERFACE_VERSION = 3 def version(self) -> str: - return "3.1.5" + return "3.1.6" timeframe = "5m" stoploss = -0.02 use_custom_stoploss = True + + @property + def trailing_stoploss_positive_offset(self) -> float: + return self.config.get("trailing_stoploss_positive_offset", 0.01) + + @property + def trailing_stoploss_only_offset_is_reached(self) -> bool: + return self.config.get("trailing_stoploss_only_offset_is_reached", True) + + @property + def trailing_stoploss_natr_ratio(self) -> float: + return self.config.get("trailing_stoploss_natr_ratio", 0.025) + # Trailing stop: trailing_stop = False trailing_stop_positive = 0.01 trailing_stop_positive_offset = 0.011 trailing_only_offset_is_reached = True - @property - def stoploss_natr_ratio(self) -> float: - return self.config.get("stoploss_natr_ratio", 0.025) - @property def entry_natr_ratio(self) -> float: return self.config.get("entry_pricing", {}).get("entry_natr_ratio", 0.0025) @@ -405,7 +414,9 @@ class QuickAdapterV3(IStrategy): return 0.0 last_natr = df["natr_ratio_labeling_window"].iloc[-1] return ( - trade.open_rate * fmean([entry_natr, last_natr]) * self.stoploss_natr_ratio + trade.open_rate + * fmean([entry_natr, last_natr]) + * self.trailing_stoploss_natr_ratio ) def custom_stoploss( @@ -417,8 +428,10 @@ class QuickAdapterV3(IStrategy): current_profit: float, **kwargs, ) -> float | None: - # Trailing stoploss starts at 1% profit - if current_profit < 0.01: + if ( + self.trailing_stoploss_only_offset_is_reached + and current_profit < self.trailing_stoploss_positive_offset + ): return None df, _ = self.dp.get_analyzed_dataframe(pair=pair, timeframe=self.timeframe)