mirror of
https://github.com/freqtrade/freqtrade.git
synced 2025-12-16 12:51:14 +00:00
Fix ShuffleFilter behavior in backtesting
This commit is contained in:
@@ -173,6 +173,7 @@ class Backtesting:
|
||||
self.disable_database_use()
|
||||
self.init_backtest_detail()
|
||||
self.pairlists = PairListManager(self.exchange, self.config, self.dataprovider)
|
||||
self.dinamic_pairlist = False
|
||||
self._validate_pairlists_for_backtesting()
|
||||
|
||||
self.dataprovider.add_pairlisthandler(self.pairlists)
|
||||
@@ -226,6 +227,9 @@ class Backtesting:
|
||||
"PrecisionFilter not allowed for backtesting multiple strategies."
|
||||
)
|
||||
|
||||
if "ShuffleFilter" in self.pairlists.name_list:
|
||||
self.dinamic_pairlist = True
|
||||
|
||||
def log_once(self, msg: str) -> None:
|
||||
"""
|
||||
Partial reimplementation of log_once from the Login mixin.
|
||||
@@ -1582,6 +1586,11 @@ class Backtesting:
|
||||
for current_time in self._time_generator(start_date, end_date):
|
||||
# Loop for each main candle.
|
||||
self.check_abort()
|
||||
|
||||
if self.dinamic_pairlist:
|
||||
self.pairlists.refresh_pairlist()
|
||||
pairs = self.pairlists.whitelist
|
||||
|
||||
# Reset open trade count for this candle
|
||||
# Critical to avoid exceeding max_open_trades in backtesting
|
||||
# when timeframe-detail is used and trades close within the opening candle.
|
||||
|
||||
@@ -93,6 +93,8 @@ class ShuffleFilter(IPairList):
|
||||
return pairlist_new
|
||||
# Shuffle is done inplace
|
||||
self._random.shuffle(pairlist)
|
||||
self.__pairlist_cache[pairlist_bef] = pairlist
|
||||
|
||||
if self._config.get("runmode") in (RunMode.LIVE, RunMode.DRY_RUN):
|
||||
self.__pairlist_cache[pairlist_bef] = pairlist
|
||||
|
||||
return pairlist
|
||||
|
||||
Reference in New Issue
Block a user