# Buggy code
def load_trades_from_db(db_url: str) -> pd.DataFrame:
    """
    Load trades from a DB (using dburl)
    :param db_url: Sqlite url (default format sqlite:///tradesv3.dry-run.sqlite)
    :return: Dataframe containing Trades
    """
    trades: pd.DataFrame = pd.DataFrame([], columns=BT_DATA_COLUMNS)
    persistence.init(db_url, clean_open_orders=False)
    columns = [
        "pair",
        "profit",
        "open_time",
        "close_time",
        "open_rate",
        "close_rate",
        "duration",
        "sell_reason",
        "max_rate",
        "min_rate",
    ]

    trades = pd.DataFrame(
        [
            (
                t.pair,
                t.calc_profit(),
                t.open_date.replace(tzinfo=pytz.UTC),
                t.close_date.replace(tzinfo=pytz.UTC) if t.close_date else None,
                t.open_rate,
                t.close_rate,
                t.close_date.timestamp() - t.open_date.timestamp()
                if t.close_date
                else None,
                t.sell_reason,
                t.max_rate,
                t.min_rate,
            )
            for t in Trade.query.all()
        ],
        columns=columns,
    )

    return trades


# Traceback (TypeError)
(.env) (base) root@vmanager6003:~/freqtrade# python3 scripts/plot_dataframe.py --config config.json  --config configC.json --db-url sqlite:///MACDStrategy_LINK_live.sqlite -p LINK/BTC --trade-source DB
2019-08-02 21:01:53,435 - freqtrade.loggers - INFO - Verbosity set to 0
2019-08-02 21:01:53,436 - freqtrade.configuration.configuration - INFO - Parameter --db-url detected ...
2019-08-02 21:01:53,436 - freqtrade.configuration.configuration - INFO - Dry run is disabled
2019-08-02 21:01:53,436 - freqtrade.configuration.configuration - INFO - Using DB: "sqlite:///MACDStrategy_LINK_live.sqlite"
2019-08-02 21:01:53,436 - freqtrade.configuration.check_exchange - INFO - Checking exchange...
2019-08-02 21:01:53,437 - freqtrade.configuration.check_exchange - INFO - Exchange "binance" is officially supported by the Freqtrade development team.
2019-08-02 21:01:53,437 - freqtrade.configuration.configuration - INFO - Using max_open_trades: 2 ...
2019-08-02 21:01:53,438 - freqtrade.configuration.configuration - INFO - Using data directory: user_data/data/binance ...
2019-08-02 21:01:53,438 - freqtrade.configuration.configuration - INFO - Storing backtest results to user_data/backtest_data/backtest-result.json ...
2019-08-02 21:01:53,438 - freqtrade.configuration.configuration - INFO - Using pairs LINK/BTC
2019-08-02 21:01:53,439 - freqtrade.configuration.configuration - INFO - Using indicators1: sma,ema3,ema5
2019-08-02 21:01:53,439 - freqtrade.configuration.configuration - INFO - Using indicators2: macd,macdsignal
2019-08-02 21:01:53,439 - freqtrade.configuration.configuration - INFO - Limiting plot to: 750
2019-08-02 21:01:53,439 - freqtrade.configuration.configuration - INFO - Using trades from: DB
2019-08-02 21:01:53,721 - freqtrade.resolvers.iresolver - INFO - Using resolved strategy MACDStrategy1 from '/root/freqtrade/user_data/strategies/MACDStrategy1.py'...
2019-08-02 21:01:53,722 - freqtrade.resolvers.strategy_resolver - INFO - Override strategy 'process_only_new_candles' with value in config file: False.
2019-08-02 21:01:53,722 - freqtrade.resolvers.strategy_resolver - INFO - Override strategy 'order_types' with value in config file: {'buy': 'limit', 'sell': 'limit', 'stoploss': 'limit', 'stoploss_on_exchange': True, 'stoploss_on_exchange_interval': 60}.
2019-08-02 21:01:53,722 - freqtrade.resolvers.strategy_resolver - INFO - Override strategy 'stake_currency' with value in config file: BTC.
2019-08-02 21:01:53,723 - freqtrade.resolvers.strategy_resolver - INFO - Override strategy 'stake_amount' with value in config file: 0.025.
2019-08-02 21:01:53,723 - freqtrade.resolvers.strategy_resolver - INFO - Override strategy 'use_sell_signal' with value in config file: True.
2019-08-02 21:01:53,723 - freqtrade.resolvers.strategy_resolver - INFO - Override strategy 'sell_profit_only' with value in config file: True.
2019-08-02 21:01:53,723 - freqtrade.resolvers.strategy_resolver - INFO - Override strategy 'ignore_roi_if_buy_signal' with value in config file: False.
2019-08-02 21:01:53,723 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using minimal_roi: {'195': 0.0, '75': 0.023, '38': 0.06, '0': 0.17}
2019-08-02 21:01:53,723 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using ticker_interval: 5m
2019-08-02 21:01:53,723 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using stoploss: -0.28
2019-08-02 21:01:53,723 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using trailing_stop: True
2019-08-02 21:01:53,723 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using trailing_stop_positive: 0.0025
2019-08-02 21:01:53,724 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using trailing_stop_positive_offset: 0.01
2019-08-02 21:01:53,724 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using trailing_only_offset_is_reached: False
2019-08-02 21:01:53,724 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using process_only_new_candles: False
2019-08-02 21:01:53,724 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using order_types: {'buy': 'limit', 'sell': 'limit', 'stoploss': 'limit', 'stoploss_on_exchange': True, 'stoploss_on_exchange_interval': 60}
2019-08-02 21:01:53,724 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using order_time_in_force: {'buy': 'gtc', 'sell': 'gtc'}
2019-08-02 21:01:53,724 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using stake_currency: BTC
2019-08-02 21:01:53,724 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using stake_amount: 0.025
2019-08-02 21:01:53,724 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using use_sell_signal: True
2019-08-02 21:01:53,724 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using sell_profit_only: True
2019-08-02 21:01:53,724 - freqtrade.resolvers.strategy_resolver - INFO - Strategy using ignore_roi_if_buy_signal: False
2019-08-02 21:01:53,725 - freqtrade.data.history - INFO - Using local backtesting data ...
2019-08-02 21:01:55,704 - freqtrade.data.converter - INFO - Missing data fillup for LINK/BTC: before: 169409 - after: 170419
2019-08-02 21:01:55,923 - __main__ - INFO - analyse pair LINK/BTC
2019-08-02 21:02:04,385 - freqtrade.plot.plotting - INFO - Indicator "sma" ignored. Reason: This indicator is not found in your strategy.
2019-08-02 21:02:04,385 - freqtrade.plot.plotting - INFO - Indicator "ema3" ignored. Reason: This indicator is not found in your strategy.
2019-08-02 21:02:04,385 - freqtrade.plot.plotting - INFO - Indicator "ema5" ignored. Reason: This indicator is not found in your strategy.
Traceback (most recent call last):
File "/root/freqtrade/.env/lib/python3.7/site-packages/pandas/core/indexes/base.py", line 4729, in get_value
return libindex.get_value_box(s, key)
File "pandas/_libs/index.pyx", line 51, in pandas._libs.index.get_value_box
File "pandas/_libs/index.pyx", line 47, in pandas._libs.index.get_value_at
File "pandas/_libs/util.pxd", line 98, in pandas._libs.util.get_value_at
File "pandas/_libs/util.pxd", line 83, in pandas._libs.util.validate_indexer
TypeError: 'str' object cannot be interpreted as an integer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "scripts/plot_dataframe.py", line 113, in <module>
main(sys.argv[1:])
File "scripts/plot_dataframe.py", line 107, in main
plot_parse_args(sysargv)
File "scripts/plot_dataframe.py", line 77, in analyse_and_plot_pairs
indicators2=config["indicators2"].split(",")
File "/root/freqtrade/freqtrade/plot/plotting.py", line 253, in generate_candlestick_graph
fig = plot_trades(fig, trades)
File "/root/freqtrade/freqtrade/plot/plotting.py", line 134, in plot_trades
axis=1)
File "/root/freqtrade/.env/lib/python3.7/site-packages/pandas/core/frame.py", line 6906, in apply
return op.get_result()
File "/root/freqtrade/.env/lib/python3.7/site-packages/pandas/core/apply.py", line 186, in get_result
return self.apply_standard()
File "/root/freqtrade/.env/lib/python3.7/site-packages/pandas/core/apply.py", line 292, in apply_standard
self.apply_series_generator()
File "/root/freqtrade/.env/lib/python3.7/site-packages/pandas/core/apply.py", line 321, in apply_series_generator
results[i] = self.f(v)
File "/root/freqtrade/freqtrade/plot/plotting.py", line 132, in <lambda>
desc = trades.apply(lambda row: f"{round(row['profitperc'], 3)}%, {row['sell_reason']}, "
File "/root/freqtrade/.env/lib/python3.7/site-packages/pandas/core/series.py", line 1064, in __getitem__
result = self.index.get_value(self, key)
File "/root/freqtrade/.env/lib/python3.7/site-packages/pandas/core/indexes/base.py", line 4737, in get_value
raise e1
File "/root/freqtrade/.env/lib/python3.7/site-packages/pandas/core/indexes/base.py", line 4723, in get_value
return self._engine.get_value(s, k, tz=getattr(series.dtype, "tz", None))
File "pandas/_libs/index.pyx", line 80, in pandas._libs.index.IndexEngine.get_value
File "pandas/_libs/index.pyx", line 88, in pandas._libs.index.IndexEngine.get_value
File "pandas/_libs/index.pyx", line 131, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/hashtable_class_helper.pxi", line 1607, in pandas._libs.hashtable.PyObjectHashTable.get_item
File "pandas/_libs/hashtable_class_helper.pxi", line 1614, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: ('profitperc', 'occurred at index 0')
(.env) (base) root@vmanager6003:~/freqtrade#

# Fixed code
def load_trades_from_db(db_url: str) -> pd.DataFrame:
    """
    Load trades from a DB (using dburl)
    :param db_url: Sqlite url (default format sqlite:///tradesv3.dry-run.sqlite)
    :return: Dataframe containing Trades
    """
    trades: pd.DataFrame = pd.DataFrame([], columns=BT_DATA_COLUMNS)
    persistence.init(db_url, clean_open_orders=False)

    columns = [
        "pair",
        "open_time",
        "close_time",
        "profit",
        "profitperc",
        "open_rate",
        "close_rate",
        "amount",
        "duration",
        "sell_reason",
        "fee_open",
        "fee_close",
        "open_rate_requested",
        "close_rate_requested",
        "stake_amount",
        "max_rate",
        "min_rate",
        "id",
        "exchange",
        "stop_loss",
        "initial_stop_loss",
        "strategy",
        "ticker_interval",
    ]

    trades = pd.DataFrame(
        [
            (
                t.pair,
                t.open_date.replace(tzinfo=pytz.UTC),
                t.close_date.replace(tzinfo=pytz.UTC) if t.close_date else None,
                t.calc_profit(),
                t.calc_profit_percent(),
                t.open_rate,
                t.close_rate,
                t.amount,
                (
                    t.close_date.timestamp() - t.open_date.timestamp()
                    if t.close_date
                    else None
                ),
                t.sell_reason,
                t.fee_open,
                t.fee_close,
                t.open_rate_requested,
                t.close_rate_requested,
                t.stake_amount,
                t.max_rate,
                t.min_rate,
                t.id,
                t.exchange,
                t.stop_loss,
                t.initial_stop_loss,
                t.strategy,
                t.ticker_interval,
            )
            for t in Trade.query.all()
        ],
        columns=columns,
    )

    return trades