# Buggy code
def load_pair_history(
    pair: str,
    timeframe: str,
    datadir: Path,
    timerange: Optional[TimeRange] = None,
    refresh_pairs: bool = False,
    exchange: Optional[Exchange] = None,
    fill_up_missing: bool = True,
    drop_incomplete: bool = True,
    startup_candles: int = 0,
) -> DataFrame:
    """
    Loads cached ticker history for the given pair.
    :param pair: Pair to load data for
    :param timeframe: Ticker timeframe (e.g. "5m")
    :param datadir: Path to the data storage location.
    :param timerange: Limit data to be loaded to this timerange
    :param refresh_pairs: Refresh pairs from exchange.
        (Note: Requires exchange to be passed as well.)
    :param exchange: Exchange object (needed when using "refresh_pairs")
    :param fill_up_missing: Fill missing values with "No action"-candles
    :param drop_incomplete: Drop last candle assuming it may be incomplete.
    :param startup_candles: Additional candles to load at the start of the period
    :return: DataFrame with ohlcv data
    """

    timerange_startup = deepcopy(timerange)
    if startup_candles > 0 and timerange_startup:
        timerange_startup.subtract_start(
            timeframe_to_seconds(timeframe) * startup_candles
        )

    # The user forced the refresh of pairs
    if refresh_pairs:
        download_pair_history(
            datadir=datadir,
            exchange=exchange,
            pair=pair,
            timeframe=timeframe,
            timerange=timerange,
        )

    pairdata = load_tickerdata_file(
        datadir, pair, timeframe, timerange=timerange_startup
    )

    if pairdata:
        if timerange_startup:
            _validate_pairdata(pair, pairdata, timerange_startup)
        return parse_ticker_dataframe(
            pairdata,
            timeframe,
            pair=pair,
            fill_missing=fill_up_missing,
            drop_incomplete=drop_incomplete,
        )
    else:
        logger.warning(
            f'No history data for pair: "{pair}", timeframe: {timeframe}. '
            "Use `freqtrade download-data` to download the data"
        )
        return None


# Traceback (TypeError)
2019-12-03 21:11:32,009 - freqtrade - ERROR - Fatal exception!
Traceback (most recent call last):
File "c:\users\test\desktop\freqtrade-develop1\freqtrade\main.py", line 39, in main
args['func'](args)
File "c:\users\test\desktop\freqtrade-develop1\freqtrade\optimize\__init__.py", line 44, in start_backtesting
backtesting.start()
File "c:\users\test\desktop\freqtrade-develop1\freqtrade\optimize\backtesting.py", line 453, in start
preprocessed = self.strategy.tickerdata_to_dataframe(data)
File "c:\users\test\desktop\freqtrade-develop1\freqtrade\strategy\interface.py", line 429, in tickerdata_to_dataframe
for pair, pair_data in tickerdata.items()}
File "c:\users\test\desktop\freqtrade-develop1\freqtrade\strategy\interface.py", line 429, in <dictcomp>
for pair, pair_data in tickerdata.items()}
File "c:\users\test\desktop\freqtrade-develop1\freqtrade\strategy\interface.py", line 445, in advise_indicators
return self.populate_indicators(dataframe, metadata)
File "C:\Users\test\Desktop\freqtrade-develop1\freqtrade\strategy\default_strategy.py", line 71, in populate_indicators
data = self.dp.get_pair_dataframe("BTC/USDT", ticker_interval="1h")
File "c:\users\test\desktop\freqtrade-develop1\freqtrade\data\dataprovider.py", line 84, in get_pair_dataframe
if len(data) == 0:
TypeError: object of type 'NoneType' has no len()

# Fixed code
def load_pair_history(
    pair: str,
    timeframe: str,
    datadir: Path,
    timerange: Optional[TimeRange] = None,
    refresh_pairs: bool = False,
    exchange: Optional[Exchange] = None,
    fill_up_missing: bool = True,
    drop_incomplete: bool = True,
    startup_candles: int = 0,
) -> DataFrame:
    """
    Loads cached ticker history for the given pair.
    :param pair: Pair to load data for
    :param timeframe: Ticker timeframe (e.g. "5m")
    :param datadir: Path to the data storage location.
    :param timerange: Limit data to be loaded to this timerange
    :param refresh_pairs: Refresh pairs from exchange.
        (Note: Requires exchange to be passed as well.)
    :param exchange: Exchange object (needed when using "refresh_pairs")
    :param fill_up_missing: Fill missing values with "No action"-candles
    :param drop_incomplete: Drop last candle assuming it may be incomplete.
    :param startup_candles: Additional candles to load at the start of the period
    :return: DataFrame with ohlcv data, or empty DataFrame
    """

    timerange_startup = deepcopy(timerange)
    if startup_candles > 0 and timerange_startup:
        timerange_startup.subtract_start(
            timeframe_to_seconds(timeframe) * startup_candles
        )

    # The user forced the refresh of pairs
    if refresh_pairs:
        download_pair_history(
            datadir=datadir,
            exchange=exchange,
            pair=pair,
            timeframe=timeframe,
            timerange=timerange,
        )

    pairdata = load_tickerdata_file(
        datadir, pair, timeframe, timerange=timerange_startup
    )

    if pairdata:
        if timerange_startup:
            _validate_pairdata(pair, pairdata, timerange_startup)
        return parse_ticker_dataframe(
            pairdata,
            timeframe,
            pair=pair,
            fill_missing=fill_up_missing,
            drop_incomplete=drop_incomplete,
        )
    else:
        logger.warning(
            f'No history data for pair: "{pair}", timeframe: {timeframe}. '
            "Use `freqtrade download-data` to download the data"
        )
        return DataFrame()