From 79910870a370bd2486ca3334a43014246e7af692 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 29 Jul 2023 08:58:30 +0200 Subject: [PATCH] Fix bug resampling monthly candles closes #8972 --- freqtrade/data/converter.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/freqtrade/data/converter.py b/freqtrade/data/converter.py index 049c399e4..0eb6faf77 100644 --- a/freqtrade/data/converter.py +++ b/freqtrade/data/converter.py @@ -96,8 +96,14 @@ def ohlcv_fill_up_missing_data(dataframe: DataFrame, timeframe: str, pair: str) 'volume': 'sum' } timeframe_minutes = timeframe_to_minutes(timeframe) + resample_interval = f'{timeframe_minutes}min' + if timeframe_minutes >= 43200 and timeframe_minutes < 525600: + # Monthly candles need special treatment to stick to the 1st of the month + resample_interval = f'{timeframe}S' + elif timeframe_minutes > 43200: + resample_interval = timeframe # Resample to create "NAN" values - df = dataframe.resample(f'{timeframe_minutes}min', on='date').agg(ohlcv_dict) + df = dataframe.resample(resample_interval, on='date').agg(ohlcv_dict) # Forwardfill close for missing columns df['close'] = df['close'].fillna(method='ffill')