Repository: freqtrade/freqtrade

Issue:
using informative_pair in hyperopt

## Step 2: Describe your environment

  * Operating system: ____ Windows 10
  * Python Version: _____ python 3
  * CCXT version: _____ (`pip freeze | grep ccxt`)
  * Branch: Master | Develop
  * Last Commit ID: _____ (`git log --format="%H" -n 1`)
  
## Step 3: Describe the problem:

*Explain the problem you have encountered*

### Steps to reproduce:
i just want to use informatove pair in hyperopt 
i use this code:
   ```
@staticmethod
    def informative_pairs(self):
        return [("BTC/USDT", "1h")]
        

    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:

        data = self.dp.get_pair_dataframe(pair="BTC/USDT", ticker_interval=self.ticker_interval)

        dataframe = dataframe.merge(data[["date", "low"]],on="date",how="left",suffixes=("",self.config['stake_currency']))
        dataframe2 = dataframe.merge(data[["date", "high"]],on="date",how="left",suffixes=("",self.config['stake_currency']))

```
but i got this error:
```

2019-12-03 21:57:08,251 - 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 76, in start_hyperopt
    hyperopt.start()
  File "c:\users\test\desktop\freqtrade-develop1\freqtrade\optimize\hyperopt.py", line 404, in start
    preprocessed = self.backtesting.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()}
TypeError: populate_indicators() takes 2 positional arguments but 3 were given
```


Discussion:
Assuming you copy/paste `populate_indicators` into hyperopt - then you'll need to remove the `self` - and convert it to a staticmethod (the HyperoptInterface is slightly different) than the 

```
 def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
```
becomes

```
@staticmethod
def populate_indicators(dataframe: DataFrame, metadata: dict) -> DataFrame:
```

This is not necessary if you keep `populate_indicators` in the strategy and call hyperopt via
``` 
freqtrade hyperopt --strategy MyStrategy --hyperopt MyHyperopt ... `
```
which is also simpler since you'll need populate_indicators in your strategy anyway.

**Additional Note:**
 you will need to check if dataprovider is available as shown [in the documentation](https://www.freqtrade.io/en/latest/strategy-customization/#example-fetch-live-ohlcv-historic-data-for-the-first-informative-pair):

```python
if self.dp:
    inf_pair, inf_timeframe = self.informative_pairs()[0]
    informative = self.dp.get_pair_dataframe(pair=inf_pair,
                                             timeframe=inf_timeframe)
```

We do not guarantee dataprovider to be available with all operations.
> you will need to check if dataprovider is available as shown [in the documentation]

But there is no `self` after transferring `populate_indicators` to the hyperopt...
And if he leave it in the strategy, he receives that error, as far as I understand. That's the point.
(needs to be checked)

well you can always use `HyperoptName.dp.` - since we assign it at class level, not at instance level.
any update on this issue?
Currently the informative pairs are unable to hyperopt on. @hroff-1902 and @xmatthias 
they are available by using `HyperoptName.dp.get_pair_dataframe()` (as pointed out above already)... (Replace HyperoptName with the name of your hyperopt class).

version: freqtrade develop-5cca6c74
MA2Opt is my hyperopt class name. Checkout the error message.
 `AttributeError: type object 'MA2Opt' has no attribute 'dp'`




Resolving patch:
diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py
--- a/freqtrade/optimize/backtesting.py
+++ b/freqtrade/optimize/backtesting.py
@@ -24,7 +24,6 @@
 from freqtrade.pairlist.pairlistmanager import PairListManager
 from freqtrade.persistence import Trade
 from freqtrade.resolvers import ExchangeResolver, StrategyResolver
-from freqtrade.state import RunMode
 from freqtrade.strategy.interface import IStrategy, SellCheckTuple, SellType
 
 logger = logging.getLogger(__name__)
@@ -65,9 +64,8 @@ def __init__(self, config: Dict[str, Any]) -> None:
         self.strategylist: List[IStrategy] = []
         self.exchange = ExchangeResolver.load_exchange(self.config['exchange']['name'], self.config)
 
-        if self.config.get('runmode') != RunMode.HYPEROPT:
-            self.dataprovider = DataProvider(self.config, self.exchange)
-            IStrategy.dp = self.dataprovider
+        dataprovider = DataProvider(self.config, self.exchange)
+        IStrategy.dp = dataprovider
 
         if self.config.get('strategy_list', None):
             for strat in list(self.config['strategy_list']):
diff --git a/freqtrade/optimize/hyperopt.py b/freqtrade/optimize/hyperopt.py
--- a/freqtrade/optimize/hyperopt.py
+++ b/freqtrade/optimize/hyperopt.py
@@ -4,26 +4,26 @@
 This module contains the hyperopt logic
 """
 
+import io
 import locale
 import logging
 import random
 import warnings
-from math import ceil
 from collections import OrderedDict
+from math import ceil
 from operator import itemgetter
+from os import path
 from pathlib import Path
 from pprint import pformat
 from typing import Any, Dict, List, Optional
 
+import progressbar
 import rapidjson
+import tabulate
 from colorama import Fore, Style
 from joblib import (Parallel, cpu_count, delayed, dump, load,
                     wrap_non_picklable_objects)
-from pandas import DataFrame, json_normalize, isna
-import progressbar
-import tabulate
-from os import path
-import io
+from pandas import DataFrame, isna, json_normalize
 
 from freqtrade.data.converter import trim_dataframe
 from freqtrade.data.history import get_timerange
@@ -35,6 +35,7 @@
 from freqtrade.optimize.hyperopt_loss_interface import IHyperOptLoss  # noqa: F401
 from freqtrade.resolvers.hyperopt_resolver import (HyperOptLossResolver,
                                                    HyperOptResolver)
+from freqtrade.strategy import IStrategy
 
 # Suppress scikit-learn FutureWarnings from skopt
 with warnings.catch_warnings():
@@ -634,6 +635,8 @@ def start(self) -> None:
         # We don't need exchange instance anymore while running hyperopt
         self.backtesting.exchange = None  # type: ignore
         self.backtesting.pairlists = None  # type: ignore
+        self.backtesting.strategy.dp = None  # type: ignore
+        IStrategy.dp = None  # type: ignore
 
         self.epochs = self.load_previous_results(self.results_file)
 


Test patch: