prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Possibly slightly wrong informative pair merging
  When merging longer timeframe to a shorter one, the timedelta is added to the date:
  https://github.com/freqtrade/freqtrade/blob/f320cb0d7a12e064018967cf049dd6719fff8ddb/freqtrade/strategy/strategy_helper.py#L35
  
  then it merges to the shorter timeframe with these dates..
  https://github.com/freqtrade/freqtrade/blob/f320cb0d7a12e064018967cf049dd6719fff8ddb/freqtrade/strategy/strategy_helper.py#L42-L43
  
  So lets say we are merging a `1h` timeframe to a `5m` timeframe and there is a signal `True` at `00:00` on the `1h` timeseries. 
  With this merge, the signal will appear in the `5m` timeseries also at `00:00`. However the `00:00` candle for the `5m` timeframe is received at `00:05`, that is five minutes later than the time you actually received the `1h` candle, which should have been received at the candle with date `11:55`. 
  So after merging, the values should be shifted backward (`shift(-1)`)..or the merging dates should be reduced by one unit of timedelta of the shorter timeframe..
  ```python
  informative['date_merge'] = informative["date"] + pd.to_timedelta(minutes_inf, 'm') - pd.to_timedelta(minutes, 'm')
  ```
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `freqtrade/strategy/strategy_helper.py`
  Content:
  ```
  1 import pandas as pd
  2 
  3 from freqtrade.exchange import timeframe_to_minutes
  4 
  5 
  6 def merge_informative_pair(dataframe: pd.DataFrame, informative: pd.DataFrame,
  7                            timeframe: str, timeframe_inf: str, ffill: bool = True) -> pd.DataFrame:
  8     """
  9     Correctly merge informative samples to the original dataframe, avoiding lookahead bias.
  10 
  11     Since dates are candle open dates, merging a 15m candle that starts at 15:00, and a
  12     1h candle that starts at 15:00 will result in all candles to know the close at 16:00
  13     which they should not know.
  14 
  15     Moves the date of the informative pair by 1 time interval forward.
  16     This way, the 14:00 1h candle is merged to 15:00 15m candle, since the 14:00 1h candle is the
  17     last candle that's closed at 15:00, 15:15, 15:30 or 15:45.
  18 
  19     Assuming inf_tf = '1d' - then the resulting columns will be:
  20     date_1d, open_1d, high_1d, low_1d, close_1d, rsi_1d
  21 
  22     :param dataframe: Original dataframe
  23     :param informative: Informative pair, most likely loaded via dp.get_pair_dataframe
  24     :param timeframe: Timeframe of the original pair sample.
  25     :param timeframe_inf: Timeframe of the informative pair sample.
  26     :param ffill: Forwardfill missing values - optional but usually required
  27     """
  28 
  29     minutes_inf = timeframe_to_minutes(timeframe_inf)
  30     minutes = timeframe_to_minutes(timeframe)
  31     if minutes >= minutes_inf:
  32         # No need to forwardshift if the timeframes are identical
  33         informative['date_merge'] = informative["date"]
  34     else:
  35         informative['date_merge'] = informative["date"] + pd.to_timedelta(minutes_inf, 'm')
  36 
  37     # Rename columns to be unique
  38     informative.columns = [f"{col}_{timeframe_inf}" for col in informative.columns]
  39 
  40     # Combine the 2 dataframes
  41     # all indicators on the informative sample MUST be calculated before this point
  42     dataframe = pd.merge(dataframe, informative, left_on='date',
  43                          right_on=f'date_merge_{timeframe_inf}', how='left')
  44     dataframe = dataframe.drop(f'date_merge_{timeframe_inf}', axis=1)
  45 
  46     if ffill:
  47         dataframe = dataframe.ffill()
  48 
  49     return dataframe
  50
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/freqtrade/strategy/strategy_helper.py b/freqtrade/strategy/strategy_helper.py
  --- a/freqtrade/strategy/strategy_helper.py
  +++ b/freqtrade/strategy/strategy_helper.py
  @@ -24,15 +24,24 @@
       :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]
  
verification_info: {"golden_diff": "diff --git a/freqtrade/strategy/strategy_helper.py b/freqtrade/strategy/strategy_helper.py\n--- a/freqtrade/strategy/strategy_helper.py\n+++ b/freqtrade/strategy/strategy_helper.py\n@@ -24,15 +24,24 @@\n     :param timeframe: Timeframe of the original pair sample.\n     :param timeframe_inf: Timeframe of the informative pair sample.\n     :param ffill: Forwardfill missing values - optional but usually required\n+    :return: Merged dataframe\n+    :raise: ValueError if the secondary timeframe is shorter than the dataframe timeframe\n     \"\"\"\n \n     minutes_inf = timeframe_to_minutes(timeframe_inf)\n     minutes = timeframe_to_minutes(timeframe)\n-    if minutes >= minutes_inf:\n+    if minutes == minutes_inf:\n         # No need to forwardshift if the timeframes are identical\n         informative['date_merge'] = informative[\"date\"]\n+    elif minutes < minutes_inf:\n+        # Subtract \"small\" timeframe so merging is not delayed by 1 small candle\n+        # Detailed explanation in https://github.com/freqtrade/freqtrade/issues/4073\n+        informative['date_merge'] = (\n+            informative[\"date\"] + pd.to_timedelta(minutes_inf, 'm') - pd.to_timedelta(minutes, 'm')\n+            )\n     else:\n-        informative['date_merge'] = informative[\"date\"] + pd.to_timedelta(minutes_inf, 'm')\n+        raise ValueError(\"Tried to merge a faster timeframe to a slower timeframe.\"\n+                         \"This would create new rows, and can throw off your regular indicators.\")\n \n     # Rename columns to be unique\n     informative.columns = [f\"{col}_{timeframe_inf}\" for col in informative.columns]\n", "issue": "Possibly slightly wrong informative pair merging\nWhen merging longer timeframe to a shorter one, the timedelta is added to the date:\r\nhttps://github.com/freqtrade/freqtrade/blob/f320cb0d7a12e064018967cf049dd6719fff8ddb/freqtrade/strategy/strategy_helper.py#L35\r\n\r\nthen it merges to the shorter timeframe with these dates..\r\nhttps://github.com/freqtrade/freqtrade/blob/f320cb0d7a12e064018967cf049dd6719fff8ddb/freqtrade/strategy/strategy_helper.py#L42-L43\r\n\r\nSo lets say we are merging a `1h` timeframe to a `5m` timeframe and there is a signal `True` at `00:00` on the `1h` timeseries. \r\nWith this merge, the signal will appear in the `5m` timeseries also at `00:00`. However the `00:00` candle for the `5m` timeframe is received at `00:05`, that is five minutes later than the time you actually received the `1h` candle, which should have been received at the candle with date `11:55`. \r\nSo after merging, the values should be shifted backward (`shift(-1)`)..or the merging dates should be reduced by one unit of timedelta of the shorter timeframe..\r\n```python\r\ninformative['date_merge'] = informative[\"date\"] + pd.to_timedelta(minutes_inf, 'm') - pd.to_timedelta(minutes, 'm')\r\n```\n", "before_files": [{"content": "import pandas as pd\n\nfrom freqtrade.exchange import timeframe_to_minutes\n\n\ndef merge_informative_pair(dataframe: pd.DataFrame, informative: pd.DataFrame,\n                           timeframe: str, timeframe_inf: str, ffill: bool = True) -> pd.DataFrame:\n    \"\"\"\n    Correctly merge informative samples to the original dataframe, avoiding lookahead bias.\n\n    Since dates are candle open dates, merging a 15m candle that starts at 15:00, and a\n    1h candle that starts at 15:00 will result in all candles to know the close at 16:00\n    which they should not know.\n\n    Moves the date of the informative pair by 1 time interval forward.\n    This way, the 14:00 1h candle is merged to 15:00 15m candle, since the 14:00 1h candle is the\n    last candle that's closed at 15:00, 15:15, 15:30 or 15:45.\n\n    Assuming inf_tf = '1d' - then the resulting columns will be:\n    date_1d, open_1d, high_1d, low_1d, close_1d, rsi_1d\n\n    :param dataframe: Original dataframe\n    :param informative: Informative pair, most likely loaded via dp.get_pair_dataframe\n    :param timeframe: Timeframe of the original pair sample.\n    :param timeframe_inf: Timeframe of the informative pair sample.\n    :param ffill: Forwardfill missing values - optional but usually required\n    \"\"\"\n\n    minutes_inf = timeframe_to_minutes(timeframe_inf)\n    minutes = timeframe_to_minutes(timeframe)\n    if minutes >= minutes_inf:\n        # No need to forwardshift if the timeframes are identical\n        informative['date_merge'] = informative[\"date\"]\n    else:\n        informative['date_merge'] = informative[\"date\"] + pd.to_timedelta(minutes_inf, 'm')\n\n    # Rename columns to be unique\n    informative.columns = [f\"{col}_{timeframe_inf}\" for col in informative.columns]\n\n    # Combine the 2 dataframes\n    # all indicators on the informative sample MUST be calculated before this point\n    dataframe = pd.merge(dataframe, informative, left_on='date',\n                         right_on=f'date_merge_{timeframe_inf}', how='left')\n    dataframe = dataframe.drop(f'date_merge_{timeframe_inf}', axis=1)\n\n    if ffill:\n        dataframe = dataframe.ffill()\n\n    return dataframe\n", "path": "freqtrade/strategy/strategy_helper.py"}], "after_files": [{"content": "import pandas as pd\n\nfrom freqtrade.exchange import timeframe_to_minutes\n\n\ndef merge_informative_pair(dataframe: pd.DataFrame, informative: pd.DataFrame,\n                           timeframe: str, timeframe_inf: str, ffill: bool = True) -> pd.DataFrame:\n    \"\"\"\n    Correctly merge informative samples to the original dataframe, avoiding lookahead bias.\n\n    Since dates are candle open dates, merging a 15m candle that starts at 15:00, and a\n    1h candle that starts at 15:00 will result in all candles to know the close at 16:00\n    which they should not know.\n\n    Moves the date of the informative pair by 1 time interval forward.\n    This way, the 14:00 1h candle is merged to 15:00 15m candle, since the 14:00 1h candle is the\n    last candle that's closed at 15:00, 15:15, 15:30 or 15:45.\n\n    Assuming inf_tf = '1d' - then the resulting columns will be:\n    date_1d, open_1d, high_1d, low_1d, close_1d, rsi_1d\n\n    :param dataframe: Original dataframe\n    :param informative: Informative pair, most likely loaded via dp.get_pair_dataframe\n    :param timeframe: Timeframe of the original pair sample.\n    :param timeframe_inf: Timeframe of the informative pair sample.\n    :param ffill: Forwardfill missing values - optional but usually required\n    :return: Merged dataframe\n    :raise: ValueError if the secondary timeframe is shorter than the dataframe timeframe\n    \"\"\"\n\n    minutes_inf = timeframe_to_minutes(timeframe_inf)\n    minutes = timeframe_to_minutes(timeframe)\n    if minutes == minutes_inf:\n        # No need to forwardshift if the timeframes are identical\n        informative['date_merge'] = informative[\"date\"]\n    elif minutes < minutes_inf:\n        # Subtract \"small\" timeframe so merging is not delayed by 1 small candle\n        # Detailed explanation in https://github.com/freqtrade/freqtrade/issues/4073\n        informative['date_merge'] = (\n            informative[\"date\"] + pd.to_timedelta(minutes_inf, 'm') - pd.to_timedelta(minutes, 'm')\n            )\n    else:\n        raise ValueError(\"Tried to merge a faster timeframe to a slower timeframe.\"\n                         \"This would create new rows, and can throw off your regular indicators.\")\n\n    # Rename columns to be unique\n    informative.columns = [f\"{col}_{timeframe_inf}\" for col in informative.columns]\n\n    # Combine the 2 dataframes\n    # all indicators on the informative sample MUST be calculated before this point\n    dataframe = pd.merge(dataframe, informative, left_on='date',\n                         right_on=f'date_merge_{timeframe_inf}', how='left')\n    dataframe = dataframe.drop(f'date_merge_{timeframe_inf}', axis=1)\n\n    if ffill:\n        dataframe = dataframe.ffill()\n\n    return dataframe\n", "path": "freqtrade/strategy/strategy_helper.py"}]}