Merge pull request #4144 from freqtrade/improve_informativepair
Improve merge_informative_pairs to properly merge correct timeframes
This commit is contained in:
@@ -24,15 +24,24 @@ def merge_informative_pair(dataframe: pd.DataFrame, informative: pd.DataFrame,
|
||||
:param timeframe: Timeframe of the original pair sample.
|
||||
:param timeframe_inf: Timeframe of the informative pair sample.
|
||||
:param ffill: Forwardfill missing values - optional but usually required
|
||||
:return: Merged dataframe
|
||||
:raise: ValueError if the secondary timeframe is shorter than the dataframe timeframe
|
||||
"""
|
||||
|
||||
minutes_inf = timeframe_to_minutes(timeframe_inf)
|
||||
minutes = timeframe_to_minutes(timeframe)
|
||||
if minutes >= minutes_inf:
|
||||
if minutes == minutes_inf:
|
||||
# No need to forwardshift if the timeframes are identical
|
||||
informative['date_merge'] = informative["date"]
|
||||
elif minutes < minutes_inf:
|
||||
# Subtract "small" timeframe so merging is not delayed by 1 small candle
|
||||
# Detailed explanation in https://github.com/freqtrade/freqtrade/issues/4073
|
||||
informative['date_merge'] = (
|
||||
informative["date"] + pd.to_timedelta(minutes_inf, 'm') - pd.to_timedelta(minutes, 'm')
|
||||
)
|
||||
else:
|
||||
informative['date_merge'] = informative["date"] + pd.to_timedelta(minutes_inf, 'm')
|
||||
raise ValueError("Tried to merge a faster timeframe to a slower timeframe."
|
||||
"This would create new rows, and can throw off your regular indicators.")
|
||||
|
||||
# Rename columns to be unique
|
||||
informative.columns = [f"{col}_{timeframe_inf}" for col in informative.columns]
|
||||
|
Reference in New Issue
Block a user