# Buggy code
def create_cum_profit(
    df: pd.DataFrame, trades: pd.DataFrame, col_name: str, timeframe: str
) -> pd.DataFrame:
    """
    Adds a column `col_name` with the cumulative profit for the given trades array.
    :param df: DataFrame with date index
    :param trades: DataFrame containing trades (requires columns close_time and profitperc)
    :param col_name: Column name that will be assigned the results
    :param timeframe: Timeframe used during the operations
    :return: Returns df with one additional column, col_name, containing the cumulative profit.
    """
    from freqtrade.exchange import timeframe_to_minutes

    timeframe_minutes = timeframe_to_minutes(timeframe)
    # Resample to timeframe to make sure trades match candles
    _trades_sum = trades.resample(f"{timeframe_minutes}min", on="close_time")[
        ["profitperc"]
    ].sum()
    df.loc[:, col_name] = _trades_sum.cumsum()
    # Set first value to 0
    df.loc[df.iloc[0].name, col_name] = 0
    # FFill to get continuous
    df[col_name] = df[col_name].ffill()
    return df


# Traceback (TypeError)
Traceback (most recent call last):
File "/freqtrade/freqtrade/main.py", line 36, in main
return_code = args['func'](args)
File "/freqtrade/freqtrade/commands/plot_commands.py", line 36, in start_plot_profit
plot_profit(config)
File "/freqtrade/freqtrade/plot/plotting.py", line 510, in plot_profit
fig = generate_profit_graph(plot_elements["pairs"], plot_elements["ohlcv"],
File "/freqtrade/freqtrade/plot/plotting.py", line 392, in generate_profit_graph
df_comb = create_cum_profit(df_comb, trades, 'cum_profit', timeframe)
File "/freqtrade/freqtrade/data/btanalysis.py", line 201, in create_cum_profit
_trades_sum = trades.resample(f'{timeframe_minutes}min', on='close_time')[['profitperc']].sum()
File "/usr/local/lib/python3.8/site-packages/pandas/core/generic.py", line 8104, in resample
return resample(
File "/usr/local/lib/python3.8/site-packages/pandas/core/resample.py", line 1270, in resample
return tg._get_resampler(obj, kind=kind)
File "/usr/local/lib/python3.8/site-packages/pandas/core/resample.py", line 1403, in _get_resampler
raise TypeError(
TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'Index'

# Fixed code
def create_cum_profit(
    df: pd.DataFrame, trades: pd.DataFrame, col_name: str, timeframe: str
) -> pd.DataFrame:
    """
    Adds a column `col_name` with the cumulative profit for the given trades array.
    :param df: DataFrame with date index
    :param trades: DataFrame containing trades (requires columns close_time and profitperc)
    :param col_name: Column name that will be assigned the results
    :param timeframe: Timeframe used during the operations
    :return: Returns df with one additional column, col_name, containing the cumulative profit.
    :raise: ValueError if trade-dataframe was found empty.
    """
    if len(trades) == 0:
        raise ValueError("Trade dataframe empty.")
    from freqtrade.exchange import timeframe_to_minutes

    timeframe_minutes = timeframe_to_minutes(timeframe)
    # Resample to timeframe to make sure trades match candles
    _trades_sum = trades.resample(f"{timeframe_minutes}min", on="close_time")[
        ["profitperc"]
    ].sum()
    df.loc[:, col_name] = _trades_sum.cumsum()
    # Set first value to 0
    df.loc[df.iloc[0].name, col_name] = 0
    # FFill to get continuous
    df[col_name] = df[col_name].ffill()
    return df