Пример #1
0
    def populate_indicators(self, dataframe: DataFrame,
                            metadata: dict) -> DataFrame:
        dataframe['adx'] = ta.ADX(dataframe, timeperiod=14)
        dataframe['plus_di'] = ta.PLUS_DI(dataframe, timeperiod=25)
        dataframe['minus_di'] = ta.MINUS_DI(dataframe, timeperiod=25)
        dataframe['sar'] = ta.SAR(dataframe)
        dataframe['mom'] = ta.MOM(dataframe, timeperiod=14)

        dataframe['sell-adx'] = ta.ADX(dataframe, timeperiod=14)
        dataframe['sell-plus_di'] = ta.PLUS_DI(dataframe, timeperiod=25)
        dataframe['sell-minus_di'] = ta.MINUS_DI(dataframe, timeperiod=25)
        dataframe['sell-sar'] = ta.SAR(dataframe)
        dataframe['sell-mom'] = ta.MOM(dataframe, timeperiod=14)

        return dataframe
    def populate_indicators(dataframe: DataFrame, metadata: dict) -> DataFrame:
        """
        Add several indicators needed for buy and sell strategies defined below.
        """
        # ADX
        dataframe['adx'] = ta.ADX(dataframe)
        # MACD
        macd = ta.MACD(dataframe)
        dataframe['macd'] = macd['macd']
        dataframe['macdsignal'] = macd['macdsignal']
        # MFI
        dataframe['mfi'] = ta.MFI(dataframe)
        # RSI
        dataframe['rsi'] = ta.RSI(dataframe)
        # Stochastic Fast
        stoch_fast = ta.STOCHF(dataframe)
        dataframe['fastd'] = stoch_fast['fastd']
        # Minus-DI
        dataframe['minus_di'] = ta.MINUS_DI(dataframe)
        # Bollinger bands
        bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=2)
        dataframe['bb_lowerband'] = bollinger['lower']
        dataframe['bb_upperband'] = bollinger['upper']
        # SAR
        dataframe['sar'] = ta.SAR(dataframe)

        return dataframe
Пример #3
0
    def run(self):
        print("Bot is running")
        while True:
            for coin in self.coins:
                try:
                    klines = self.client.get_klines(symbol=coin, interval=Bot.interval)
                    array = np.array(klines, dtype='f8')
                    df = pd.DataFrame(data=array[:, 0:6], columns=["date", "open", "high", "low", "close", "volume"])
                    plus_di = tb.PLUS_DI(df, timeperiod=20)
                    minus_di = tb.MINUS_DI(df, timeperiod=20)
                    upperBB, lowerBB, old_upperBB, old_lowerBB = self.BBANDS(df, length=20, mult=1.75)
                    upperKC, lowerKC, old_upperKC, old_lowerKC = self.KELCH(df, length=20, mult=1.5)
                    plus = plus_di[len(plus_di) - 2]
                    old_plus = plus_di[len(plus_di) - 1]
                    minus = minus_di[len(minus_di) - 2]
                    old_minus = minus_di[len(minus_di) - 1]
                    print(coin, plus, minus, lowerKC, lowerBB, upperBB, upperKC)
                    if plus > minus and old_plus > old_minus and plus > 27 and old_plus > 27 and \
                                    lowerBB < lowerKC and old_lowerBB < old_lowerKC and \
                                    upperBB > upperKC and old_upperBB > old_upperKC:
                        self.buyCoin(coin, df)
                    if (plus < minus and old_plus < old_minus) or (plus < 20 and old_plus < 20):
                        self.sellCoin(coin, df)

                except Exception as ex:
                    print("Exception", ex)
                    time.sleep(60.0)
                    pass

            time.sleep(60 * 10)
Пример #4
0
    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        dataframe['rsi'] = numpy.nan_to_num(ta.RSI(dataframe, timeperiod=5))
        dataframe['emarsi'] = numpy.nan_to_num(ta.EMA(dataframe['rsi'], timeperiod=5))

        dataframe['adx'] = numpy.nan_to_num(ta.ADX(dataframe))

        dataframe['minusdi'] = numpy.nan_to_num(ta.MINUS_DI(dataframe))
        dataframe['minusdiema'] = numpy.nan_to_num(ta.EMA(dataframe['minusdi'], timeperiod=25))
        dataframe['plusdi'] = numpy.nan_to_num(ta.PLUS_DI(dataframe))
        dataframe['plusdiema'] = numpy.nan_to_num(ta.EMA(dataframe['plusdi'], timeperiod=5))

        dataframe['lowsma'] = numpy.nan_to_num(ta.EMA(dataframe, timeperiod=60))
        dataframe['highsma'] = numpy.nan_to_num(ta.EMA(dataframe, timeperiod=120))
        dataframe['fastsma'] = numpy.nan_to_num(ta.SMA(dataframe, timeperiod=120))
        dataframe['slowsma'] = numpy.nan_to_num(ta.SMA(dataframe, timeperiod=240))

        dataframe['bigup'] = dataframe['fastsma'].gt(dataframe['slowsma']) & ((dataframe['fastsma'] - dataframe['slowsma']) > dataframe['close'] / 300)
        dataframe['bigdown'] = ~dataframe['bigup']
        dataframe['trend'] = dataframe['fastsma'] - dataframe['slowsma']

        dataframe['preparechangetrend'] = dataframe['trend'].gt(dataframe['trend'].shift())
        dataframe['preparechangetrendconfirm'] = dataframe['preparechangetrend'] & dataframe['trend'].shift().gt(dataframe['trend'].shift(2))
        dataframe['continueup'] = dataframe['slowsma'].gt(dataframe['slowsma'].shift()) & dataframe['slowsma'].shift().gt(dataframe['slowsma'].shift(2))

        dataframe['delta'] = dataframe['fastsma'] - dataframe['fastsma'].shift()
        dataframe['slowingdown'] = dataframe['delta'].lt(dataframe['delta'].shift())
        return dataframe
Пример #5
0
def ta_detect(symbol):
    try:
        data = exchange.fetch_ohlcv(symbol.symbol, TA_TIME_FRAME)
        df = DataFrame(
            data, columns=['time', 'open', 'high', 'low', 'close', 'volume'])
        df.set_index('time', inplace=True, drop=True)
        df['rsi'] = ta.RSI(df)
        df['adx'] = ta.ADX(df)
        df['plus_di'] = ta.PLUS_DI(df)
        df['minus_di'] = ta.MINUS_DI(df)
        df['fastd'] = ta.STOCHF(df)['fastd']
        df.loc[((df['rsi'] < 35) & (df['fastd'] < 35) & (df['adx'] > 30) &
                (df['plus_di'] > 0.5)) | ((df['adx'] > 65) &
                                          (df['plus_di'] > 0.5)), 'buy'] = 1
        df.loc[(((crossed_above(df['rsi'], 70)) |
                 (crossed_above(df['fastd'], 70))) & (df['adx'] > 10) &
                (df['minus_di'] > 0)) | ((df['adx'] > 70) &
                                         (df['minus_di'] > 0.5)), 'sell'] = 1
        buy_signal, sell_signal = df.iloc[-1]['buy'], df.iloc[-1]['sell']
        if buy_signal == 1:
            log('{} TA BUY'.format(symbol.symbol))
            rd.publish('ta_buy', symbol.symbol)
            return True
        elif sell_signal == 1:
            log('{} TA SELL'.format(symbol.symbol))
            rd.publish('ta_sell', symbol.symbol)
            return True
        return False
    except Exception as e:
        log('{} error: {}'.format(symbol.symbol, str(e)))
        time.sleep(30)
    return False
Пример #6
0
 def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
     dataframe['adx'] = ta.ADX(dataframe, timeperiod=14)
     dataframe['plus_di'] = ta.PLUS_DI(dataframe, timeperiod=25)
     dataframe['minus_di'] = ta.MINUS_DI(dataframe, timeperiod=25)
     dataframe['sar'] = ta.SAR(dataframe)
     dataframe['mom'] = ta.MOM(dataframe, timeperiod=14)
     #print(f"\"{metadata['pair']}\"")
     return dataframe
Пример #7
0
    def populate_indicators(self, dataframe: DataFrame,
                            metadata: dict) -> DataFrame:
        # Populate/update the trade data if there is any, set trades to false if not live/dry
        self.custom_trade_info[metadata['pair']] = self.populate_trades(
            metadata['pair'])

        dataframe['rsi'] = np.nan_to_num(ta.RSI(dataframe, timeperiod=5))
        dataframe['emarsi'] = np.nan_to_num(
            ta.EMA(dataframe['rsi'], timeperiod=5))

        dataframe['adx'] = np.nan_to_num(ta.ADX(dataframe))

        dataframe['minusdi'] = np.nan_to_num(ta.MINUS_DI(dataframe))
        dataframe['minusdiema'] = np.nan_to_num(
            ta.EMA(dataframe['minusdi'], timeperiod=25))
        dataframe['plusdi'] = np.nan_to_num(ta.PLUS_DI(dataframe))
        dataframe['plusdiema'] = np.nan_to_num(
            ta.EMA(dataframe['plusdi'], timeperiod=5))

        dataframe['lowsma'] = np.nan_to_num(ta.EMA(dataframe, timeperiod=60))
        dataframe['highsma'] = np.nan_to_num(ta.EMA(dataframe, timeperiod=120))
        dataframe['fastsma'] = np.nan_to_num(ta.SMA(dataframe, timeperiod=120))
        dataframe['slowsma'] = np.nan_to_num(ta.SMA(dataframe, timeperiod=240))

        dataframe['bigup'] = dataframe['fastsma'].gt(dataframe['slowsma']) & (
            (dataframe['fastsma'] - dataframe['slowsma']) >
            dataframe['close'] / 300)
        dataframe['bigdown'] = ~dataframe['bigup']
        dataframe['trend'] = dataframe['fastsma'] - dataframe['slowsma']

        dataframe['preparechangetrend'] = dataframe['trend'].gt(
            dataframe['trend'].shift())
        dataframe['preparechangetrendconfirm'] = dataframe[
            'preparechangetrend'] & dataframe['trend'].shift().gt(
                dataframe['trend'].shift(2))
        dataframe['continueup'] = dataframe['slowsma'].gt(
            dataframe['slowsma'].shift()) & dataframe['slowsma'].shift().gt(
                dataframe['slowsma'].shift(2))

        dataframe['delta'] = dataframe['fastsma'] - dataframe['fastsma'].shift(
        )
        dataframe['slowingdown'] = dataframe['delta'].lt(
            dataframe['delta'].shift())

        dataframe['rmi-slow'] = RMI(dataframe, length=21, mom=5)
        dataframe['rmi-fast'] = RMI(dataframe, length=8, mom=4)

        dataframe['rmi-up'] = np.where(
            dataframe['rmi-slow'] >= dataframe['rmi-slow'].shift(), 1, 0)
        dataframe['rmi-dn'] = np.where(
            dataframe['rmi-slow'] <= dataframe['rmi-slow'].shift(), 1, 0)
        dataframe['rmi-up-trend'] = np.where(
            dataframe['rmi-up'].rolling(3, min_periods=1).sum() >= 2, 1, 0)
        dataframe['rmi-dn-trend'] = np.where(
            dataframe['rmi-dn'].rolling(3, min_periods=1).sum() >= 2, 1, 0)

        return dataframe
Пример #8
0
    def populate_indicators(self, dataframe: DataFrame,
                            metadata: dict) -> DataFrame:
        dataframe["adx"] = ta.ADX(dataframe, timeperiod=14)
        dataframe["plus_di"] = ta.PLUS_DI(dataframe, timeperiod=25)
        dataframe["minus_di"] = ta.MINUS_DI(dataframe, timeperiod=25)
        dataframe["sar"] = ta.SAR(dataframe)
        dataframe["mom"] = ta.MOM(dataframe, timeperiod=14)

        return dataframe
    def populate_indicators(self, dataframe: DataFrame,
                            metadata: dict) -> DataFrame:

        bollinger = qtpylib.bollinger_bands(dataframe['close'],
                                            window=20,
                                            stds=2)
        dataframe['bb_lowerband'] = bollinger['lower']
        dataframe['bb_middleband'] = bollinger['mid']
        dataframe['bb_upperband'] = bollinger['upper']
        dataframe['bb_width'] = (
            (dataframe['bb_upperband'] - dataframe['bb_lowerband']) /
            dataframe['bb_middleband'])
        dataframe['bb_bottom_cross'] = qtpylib.crossed_below(
            dataframe['close'], dataframe['bb_lowerband']).astype('int')

        dataframe['rsi'] = ta.RSI(dataframe, timeperiod=10)

        dataframe['plus_di'] = ta.PLUS_DI(dataframe)
        dataframe['minus_di'] = ta.MINUS_DI(dataframe)

        dataframe['cci'] = ta.CCI(dataframe, 30)

        dataframe['mfi'] = ta.MFI(dataframe, timeperiod=14)

        dataframe['cmf'] = chaikin_mf(dataframe)

        dataframe['rmi'] = RMI(dataframe, length=8, mom=4)

        stoch = ta.STOCHRSI(dataframe, 15, 20, 2, 2)
        dataframe['srsi_fk'] = stoch['fastk']
        dataframe['srsi_fd'] = stoch['fastd']

        dataframe['fastEMA'] = ta.EMA(dataframe['volume'], timeperiod=12)
        dataframe['slowEMA'] = ta.EMA(dataframe['volume'], timeperiod=26)
        dataframe['pvo'] = ((dataframe['fastEMA'] - dataframe['slowEMA']) /
                            dataframe['slowEMA']) * 100

        dataframe['is_dip'] = ((dataframe['rmi'] < 20)
                               & (dataframe['cci'] <= -150)
                               & (dataframe['srsi_fk'] < 20)
                               # Maybe comment mfi and cmf to make more trades
                               & (dataframe['mfi'] < 25)
                               & (dataframe['cmf'] <= -0.1)).astype('int')

        dataframe['is_break'] = (
            (dataframe['bb_width'] > 0.025)
            & (dataframe['bb_bottom_cross'].rolling(10).sum() > 1)
            & (dataframe['close'] < 0.99 * dataframe['bb_lowerband'])
        ).astype('int')

        dataframe['buy_signal'] = ((dataframe['is_dip'] > 0)
                                   & (dataframe['is_break'] > 0)).astype('int')

        return dataframe
    def populate_indicators(self, dataframe: DataFrame,
                            metadata: dict) -> DataFrame:
        """
        Adds several different TA indicators to the given DataFrame

        Performance Note: For the best performance be frugal on the number of indicators
        you are using. Let uncomment only the indicator you are using in your strategies
        or your hyperopt configuration, otherwise you will waste your memory and CPU usage.
        :param dataframe: Dataframe with data from the exchange
        :param metadata: Additional information, like the currently traded pair
        :return: a Dataframe with all mandatory indicators for the strategies
        """

        # Momentum Indicators (timeperiod is expressed in candles)
        # -------------------

        # ADX - Average Directional Index (The Trend Strength Indicator)
        dataframe['adx'] = ta.ADX(
            dataframe, timeperiod=14)  # 14 timeperiods is usually used for ADX

        # +DM (Positive Directional Indicator) = current high - previous high
        dataframe['plus_di'] = ta.PLUS_DI(dataframe, timeperiod=25)
        # -DM (Negative Directional Indicator) = previous low - current low
        dataframe['minus_di'] = ta.MINUS_DI(dataframe, timeperiod=25)

        # RSI - Relative Strength Index (Under bought / Over sold & Over bought / Under sold indicator Indicator)
        dataframe['rsi'] = ta.RSI(dataframe)

        # MACD - Moving Average Convergence Divergence
        macd = ta.MACD(dataframe)
        dataframe['macd'] = macd[
            'macd']  # MACD - Blue TradingView Line (Bullish if on top)
        dataframe['macdsignal'] = macd[
            'macdsignal']  # Signal - Orange TradingView Line (Bearish if on top)

        # Initialize total signal variables (should be 0 = false by default)
        dataframe['total_buy_signal_strength'] = dataframe[
            'total_sell_signal_strength'] = 0

        #divergences
        dataframe = self.divergences(dataframe)

        #get trend
        dataframe.loc[(dataframe['adx'] > 20) &
                      (dataframe['plus_di'] < dataframe['minus_di']),
                      'trend'] = 'downwards'
        dataframe.loc[dataframe['adx'] < 20, 'trend'] = 'sideways'
        dataframe.loc[(dataframe['adx'] > 20) &
                      (dataframe['plus_di'] > dataframe['minus_di']),
                      'trend'] = 'upwards'

        return dataframe
Пример #11
0
 def analyze(self, historical_data, period_count=14,
             signal=['minus_di'], hot_thresh=None, cold_thresh=None):
     
     dataframe = self.convert_to_dataframe(historical_data)
     dmi_values = abstract.MINUS_DI(dataframe).to_frame()
     dmi_values.dropna(how='all', inplace=True)
     dmi_values.rename(columns={0: 'minus_di'}, inplace=True)
     
     if dmi_values[signal[0]].shape[0]:
         dmi_values['is_hot'] = dmi_values[signal[0]] < hot_thresh
         dmi_values['is_cold'] = dmi_values[signal[0]] > cold_thresh
    
     return dmi_values
Пример #12
0
    def populate_indicators(self, dataframe: DataFrame,
                            metadata: dict) -> DataFrame:
        """
        Adds several different TA indicators to the given DataFrame

        Performance Note: For the best performance be frugal on the number of indicators
        you are using. Let uncomment only the indicator you are using in your strategies
        or your hyperopt configuration, otherwise you will waste your memory and CPU usage.
        :param dataframe: Dataframe with data from the exchange
        :param metadata: Additional information, like the currently traded pair
        :return: a Dataframe with all mandatory indicators for the strategies
        """

        # Momentum Indicator
        # ------------------------------------

        # ADX
        dataframe['adx'] = ta.ADX(dataframe)

        # MACD
        macd = ta.MACD(dataframe)
        dataframe['macd'] = macd['macd']
        dataframe['macdsignal'] = macd['macdsignal']
        dataframe['macdhist'] = macd['macdhist']

        # Minus Directional Indicator / Movement
        dataframe['minus_di'] = ta.MINUS_DI(dataframe)

        # Plus Directional Indicator / Movement
        dataframe['plus_di'] = ta.PLUS_DI(dataframe)

        # RSI
        dataframe['rsi'] = ta.RSI(dataframe)

        # Stoch fast
        stoch_fast = ta.STOCHF(dataframe)
        dataframe['fastd'] = stoch_fast['fastd']
        dataframe['fastk'] = stoch_fast['fastk']

        # Bollinger bands
        bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe),
                                            window=20,
                                            stds=2)
        dataframe['bb_lowerband'] = bollinger['lower']
        dataframe['bb_middleband'] = bollinger['mid']
        dataframe['bb_upperband'] = bollinger['upper']

        # EMA - Exponential Moving Average
        dataframe['ema10'] = ta.EMA(dataframe, timeperiod=10)

        return dataframe
Пример #13
0
    def populate_indicators(self, dataframe: DataFrame,
                            metadata: dict) -> DataFrame:
        # ADX
        dataframe['adx'] = ta.ADX(dataframe)

        # Plus Directional Indicator / Movement
        dataframe['plus_di'] = ta.PLUS_DI(dataframe)

        # Minus Directional Indicator / Movement
        dataframe['minus_di'] = ta.MINUS_DI(dataframe)

        # RSI
        dataframe['rsi'] = ta.RSI(dataframe)

        return dataframe
Пример #14
0
 def populate_indicators(dataframe: DataFrame, metadata: dict) -> DataFrame:
     dataframe['adx'] = ta.ADX(dataframe)
     macd = ta.MACD(dataframe)
     dataframe['macd'] = macd['macd']
     dataframe['macdsignal'] = macd['macdsignal']
     dataframe['mfi'] = ta.MFI(dataframe)
     dataframe['rsi'] = ta.RSI(dataframe)
     stoch_fast = ta.STOCHF(dataframe)
     dataframe['fastd'] = stoch_fast['fastd']
     dataframe['minus_di'] = ta.MINUS_DI(dataframe)
     # Bollinger bands
     bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=2)
     dataframe['bb_lowerband'] = bollinger['lower']
     dataframe['bb_upperband'] = bollinger['upper']
     dataframe['sar'] = ta.SAR(dataframe)
     return dataframe
Пример #15
0
    def evaluate_adx(self,
                     period=14,
                     prefix="adx",
                     trend_line=25,
                     use_di=True,
                     impact_buy=1,
                     impact_sell=1):
        """
        evaluates the adx (optionally use plus_di and minus_di to detect buy or sell)
        :param dataframe:
        :param period:
        :param prefix:
        :param trend_line: The ADX value at which we consider that a trend is present (Default: 25)
        :param use_di: Enable/disable the usage of plus_di and minus_di (Default: Enabled)
        :return:
        """

        self._weights(impact_buy, impact_sell)
        dataframe = self.dataframe
        name = f"{prefix}_{period}"
        dataframe[name] = ta.ADX(dataframe, timeperiod=period)

        # We can use PLUS_DI and MINUS_DI to be able to detect if we should buy or sell
        # See https://www.investopedia.com/articles/trading/07/adx-trend-indicator.asp
        if use_di:
            dataframe[f"{name}_plus_di"] = ta.PLUS_DI(dataframe,
                                                      timeperiod=period)
            dataframe[f"{name}_minus_di"] = ta.MINUS_DI(dataframe,
                                                        timeperiod=period)

            dataframe.loc[(
                (dataframe[name] > trend_line)
                &
                (dataframe[f"{name}_plus_di"] > dataframe[f"{name}_minus_di"])
            ), f"buy_{name}", ] = (1 * impact_buy)

            dataframe.loc[(
                (dataframe[name] > trend_line)
                &
                (dataframe[f"{name}_plus_di"] < dataframe[f"{name}_minus_di"])
            ), f"sell_{name}", ] = (1 * impact_sell)
        else:
            dataframe.loc[((dataframe[name] > trend_line)),
                          f"buy_{name}"] = 1 * impact_buy

            dataframe.loc[((dataframe[name] > trend_line)),
                          f"sell_{name}"] = 1 * impact_sell
Пример #16
0
def populateindicators(dataframe):
    bardata = dataframe.assign(mfi=ta.MFI(dataframe['high'],
                                          dataframe['low'],
                                          dataframe['close'],
                                          np.asarray(dataframe['volume'],
                                                     dtype='float'),
                                          timeperiod=14),
                               ultosc=ta.ULTOSC(dataframe['high'],
                                                dataframe['low'],
                                                dataframe['close']),
                               minusdi=tab.MINUS_DI(dataframe, timeperiod=14),
                               plusdi=tab.PLUS_DI(dataframe, timeperiod=14),
                               rsi=tab.RSI(dataframe,
                                           timeperiod=14,
                                           price='close'),
                               adx=tab.ADX(dataframe))
    return bardata
Пример #17
0
    def populate_indicators(self, dataframe: DataFrame,
                            metadata: dict) -> DataFrame:
        # ADX
        dataframe['adx'] = ta.ADX(dataframe)

        # Plus Directional Indicator / Movement
        dataframe['plus_di'] = ta.PLUS_DI(dataframe)

        # Minus Directional Indicator / Movement
        dataframe['minus_di'] = ta.MINUS_DI(dataframe)

        # MACD
        macd = ta.MACD(dataframe)
        dataframe['macd'] = macd['macd']
        dataframe['macdsignal'] = macd['macdsignal']
        dataframe['macdhist'] = macd['macdhist']

        return dataframe
Пример #18
0
    def buyCoin(self, coin, df):
        self.refreshBalance()

        if (coin not in self.available_currencies):
            print("Buying coin attempt: " + coin)
            print("Available currencies: " + str(self.available_currencies))

            if float(self.BTC) < 0.0011:
                print("Less than 0.001 BTC", self.BTC)
                min_coin = ""
                min_plus = 100
                min_df = None

                for curr_coin in self.available_currencies:
                    klines = self.client.get_klines(symbol=curr_coin, interval=Bot.interval)
                    array = np.array(klines, dtype='f8')
                    df = pd.DataFrame(data=array[:, 0:6], columns=["date", "open", "high", "low", "close", "volume"])
                    plus_di = tb.PLUS_DI(df, timeperiod=20)
                    minus_di = tb.MINUS_DI(df, timeperiod=20)
                    upperBB, lowerBB, old_upperBB, old_lowerBB = self.BBANDS(df, length=20, mult=1.75)
                    upperKC, lowerKC, old_upperKC, old_lowerKC = self.KELCH(df, length=20, mult=1.5)
                    plus = plus_di[len(plus_di) - 2]

                    if min_plus > plus and lowerBB > lowerKC and upperBB < upperKC:
                        min_coin = curr_coin
                        min_plus = plus
                        min_df = df

                    if min_plus < 25:
                        self.sellCoin(min_coin, min_df)
                        self.refreshBalance()
                        time.sleep(30.0)

            else:
                price = df["close"][len(df) - 1]
                min_amount = int(Bot.min_amount_dict[coin])
                amount = self.maxSpendInBTC / float(price)
                amount = round(amount, min_amount)
                while amount * price < 0.001:
                    amount += pow(10, -min_amount)
                print("Buying", amount, coin, "at", price)
                self.client.create_order(symbol=coin, side="BUY", type="MARKET", quantity=amount)
                self.refreshBalance()
Пример #19
0
    def populate_indicators(self, dataframe: DataFrame,
                            metadata: dict) -> DataFrame:
        """
        Adds several different TA indicators to the given DataFrame

        Performance Note: For the best performance be frugal on the number of indicators
        you are using. Let uncomment only the indicator you are using in your strategies
        or your hyperopt configuration, otherwise you will waste your memory and CPU usage.
        """

        # MACD
        macd = ta.MACD(dataframe)
        dataframe['macd'] = macd['macd']
        dataframe['macdsignal'] = macd['macdsignal']

        # Minus Directional Indicator / Movement
        dataframe['minus_di'] = ta.MINUS_DI(dataframe)

        # RSI
        dataframe['rsi'] = ta.RSI(dataframe)

        # Inverse Fisher transform on RSI, values [-1.0, 1.0] (https://goo.gl/2JGGoy)
        rsi = 0.1 * (dataframe['rsi'] - 50)
        dataframe['fisher_rsi'] = (numpy.exp(2 * rsi) -
                                   1) / (numpy.exp(2 * rsi) + 1)
        # Inverse Fisher transform on RSI normalized, value [0.0, 100.0] (https://goo.gl/2JGGoy)
        dataframe['fisher_rsi_norma'] = 50 * (dataframe['fisher_rsi'] + 1)

        # Stoch fast
        stoch_fast = ta.STOCHF(dataframe)
        dataframe['fastd'] = stoch_fast['fastd']
        dataframe['fastk'] = stoch_fast['fastk']

        # Overlap Studies
        # ------------------------------------

        # SAR Parabol
        dataframe['sar'] = ta.SAR(dataframe)

        # SMA - Simple Moving Average
        dataframe['sma'] = ta.SMA(dataframe, timeperiod=40)

        return dataframe
 def populate_indicators(dataframe: DataFrame, metadata: dict) -> DataFrame:
     """
     This method can also be loaded from the strategy, if it doesn't exist in the hyperopt class.
     """
     dataframe['adx'] = ta.ADX(dataframe)
     macd = ta.MACD(dataframe)
     dataframe['macd'] = macd['macd']
     dataframe['macdsignal'] = macd['macdsignal']
     dataframe['mfi'] = ta.MFI(dataframe)
     dataframe['rsi'] = ta.RSI(dataframe)
     stoch_fast = ta.STOCHF(dataframe)
     dataframe['fastd'] = stoch_fast['fastd']
     dataframe['minus_di'] = ta.MINUS_DI(dataframe)
     # Bollinger bands
     bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=2)
     dataframe['bb_lowerband'] = bollinger['lower']
     dataframe['bb_upperband'] = bollinger['upper']
     dataframe['sar'] = ta.SAR(dataframe)
     return dataframe
Пример #21
0
 def populate_indicators(self, dataframe: DataFrame,
                         metadata: dict) -> DataFrame:
     dataframe["rsi"] = numpy.nan_to_num(ta.RSI(dataframe, timeperiod=5))
     rsiframe = DataFrame(dataframe["rsi"]).rename(columns={"rsi": "close"})
     dataframe["emarsi"] = numpy.nan_to_num(ta.EMA(rsiframe, timeperiod=5))
     dataframe["adx"] = numpy.nan_to_num(ta.ADX(dataframe))
     dataframe["minusdi"] = numpy.nan_to_num(ta.MINUS_DI(dataframe))
     minusdiframe = DataFrame(
         dataframe["minusdi"]).rename(columns={"minusdi": "close"})
     dataframe["minusdiema"] = numpy.nan_to_num(
         ta.EMA(minusdiframe, timeperiod=25))
     dataframe["plusdi"] = numpy.nan_to_num(ta.PLUS_DI(dataframe))
     plusdiframe = DataFrame(
         dataframe["plusdi"]).rename(columns={"plusdi": "close"})
     dataframe["plusdiema"] = numpy.nan_to_num(
         ta.EMA(plusdiframe, timeperiod=5))
     dataframe["lowsma"] = numpy.nan_to_num(ta.EMA(dataframe,
                                                   timeperiod=60))
     dataframe["highsma"] = numpy.nan_to_num(
         ta.EMA(dataframe, timeperiod=120))
     dataframe["fastsma"] = numpy.nan_to_num(
         ta.SMA(dataframe, timeperiod=120))
     dataframe["slowsma"] = numpy.nan_to_num(
         ta.SMA(dataframe, timeperiod=240))
     dataframe["bigup"] = dataframe["fastsma"].gt(dataframe["slowsma"]) & (
         (dataframe["fastsma"] - dataframe["slowsma"]) >
         dataframe["close"] / 300)
     dataframe["bigdown"] = ~dataframe["bigup"]
     dataframe["trend"] = dataframe["fastsma"] - dataframe["slowsma"]
     dataframe["preparechangetrend"] = dataframe["trend"].gt(
         dataframe["trend"].shift())
     dataframe["preparechangetrendconfirm"] = dataframe[
         "preparechangetrend"] & dataframe["trend"].shift().gt(
             dataframe["trend"].shift(2))
     dataframe["continueup"] = dataframe["slowsma"].gt(
         dataframe["slowsma"].shift()) & dataframe["slowsma"].shift().gt(
             dataframe["slowsma"].shift(2))
     dataframe["delta"] = dataframe["fastsma"] - dataframe["fastsma"].shift(
     )
     dataframe["slowingdown"] = dataframe["delta"].lt(
         dataframe["delta"].shift())
     return dataframe
Пример #22
0
    def populate_indicators(self, dataframe: DataFrame,
                            metadata: dict) -> DataFrame:

        # Momentum Indicator
        # ------------------------------------

        # ADX
        dataframe['adx'] = ta.ADX(dataframe)

        # MACD
        macd = ta.MACD(dataframe)
        dataframe['macd'] = macd['macd']
        dataframe['macdsignal'] = macd['macdsignal']
        dataframe['macdhist'] = macd['macdhist']

        # Minus Directional Indicator / Movement
        dataframe['minus_di'] = ta.MINUS_DI(dataframe)

        # Plus Directional Indicator / Movement
        dataframe['plus_di'] = ta.PLUS_DI(dataframe)

        # RSI
        dataframe['rsi'] = ta.RSI(dataframe)

        # Stoch fast
        stoch_fast = ta.STOCHF(dataframe)
        dataframe['fastd'] = stoch_fast['fastd']
        dataframe['fastk'] = stoch_fast['fastk']

        # Bollinger bands
        bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe),
                                            window=20,
                                            stds=2)
        dataframe['bb_lowerband'] = bollinger['lower']
        dataframe['bb_middleband'] = bollinger['mid']
        dataframe['bb_upperband'] = bollinger['upper']

        # EMA - Exponential Moving Average
        dataframe['ema10'] = ta.EMA(dataframe, timeperiod=10)

        return dataframe
    def populate_buy_trend(self, dataframe: DataFrame,
                           metadata: dict) -> DataFrame:
        conditions = []

        # GUARDS
        if self.buy_plusdi_enabled.value:
            conditions.append(
                ta.PLUS_DI(dataframe, timeperiod=int(self.buy_plusdi.value)) >
                ta.MINUS_DI(dataframe, timeperiod=int(self.buy_minusdi.value)))

        # TRIGGERS
        try:
            conditions.append(
                ta.ADX(dataframe, timeperiod=int(self.buy_adx_timeframe.value))
                > self.buy_adx.value)
        except Exception:
            pass

        if conditions:
            dataframe.loc[reduce(lambda x, y: x & y, conditions), 'buy'] = 1

        return dataframe
Пример #24
0
 def ta_signal(self, symbol, time_frame):
     data = self.exchange.fetch_ohlcv(symbol, time_frame)
     df = DataFrame(
         data, columns=['time', 'open', 'high', 'low', 'close', 'volume'])
     df.set_index('time', inplace=True, drop=True)
     df['rsi'] = ta.RSI(df)
     df['adx'] = ta.ADX(df)
     df['plus_di'] = ta.PLUS_DI(df)
     df['minus_di'] = ta.MINUS_DI(df)
     df['fastd'] = ta.STOCHF(df)['fastd']
     df.loc[((df['rsi'] < 35) & (df['fastd'] < 35) & (df['adx'] > 30) &
             (df['plus_di'] > 0.5)) | ((df['adx'] > 65) &
                                       (df['plus_di'] > 0.5)), 'buy'] = 1
     df.loc[(((self.crossed_above(df['rsi'], 70)) |
              (self.crossed_above(df['fastd'], 70))) & (df['adx'] > 10) &
             (df['minus_di'] > 0)) | ((df['adx'] > 70) &
                                      (df['minus_di'] > 0.5)), 'sell'] = 1
     buy_signal, sell_signal = df.iloc[-1]['buy'], df.iloc[-1]['sell']
     if buy_signal == 1:
         return 'BUY'
     elif sell_signal == 1:
         return 'SELL'
     return 'neutral'
Пример #25
0
    def populate_indicators(dataframe: DataFrame, metadata: dict) -> DataFrame:

        # MACD
        # tadoc.org/indicator/MACD.htm
        macd = ta.MACD(dataframe)
        dataframe['macd'] = macd['macd']

        # MINUS DI
        # tadoc.org/indicator/MINUS_DI.htm
        dataframe['minus_di'] = ta.MINUS_DI(dataframe)

        # RSI
        # tadoc.org/indicator/RSI.htm
        # tradingview.com/scripts/fishertransform/
        # goo.gl/2JGGoy
        dataframe['rsi'] = ta.RSI(dataframe)
        rsi = 0.1 * (dataframe['rsi'] - 50)
        dataframe['fisher_rsi'] = (np.exp(2 * rsi) - 1) / (
            np.exp(2 * rsi) + 1
        )  # Inverse Fisher transform on RSI, values [-1.0, 1.0]
        dataframe['fisher_rsi_norma'] = 50 * (
            dataframe['fisher_rsi'] + 1
        )  # Inverse Fisher transform on RSI normalized, value [0.0, 100.0]

        # STOCH FAST
        # tadoc.org/indicator/STOCHF.htm
        stoch_fast = ta.STOCHF(dataframe)
        dataframe['fastd'] = stoch_fast['fastd']
        dataframe['fastk'] = stoch_fast['fastk']

        # SAR
        dataframe['sar'] = ta.SAR(dataframe)

        # SMA
        dataframe['sma'] = ta.SMA(dataframe, timeperiod=50)

        return dataframe
Пример #26
0
    def populate_indicators(self, dataframe: DataFrame,
                            metadata: dict) -> DataFrame:
        # Momentum Indicators
        # ------------------------------------

        # ADX
        dataframe['adx'] = ta.ADX(dataframe)

        # Plus Directional Indicator / Movement
        dataframe['plus_dm'] = ta.PLUS_DM(dataframe)
        dataframe['plus_di'] = ta.PLUS_DI(dataframe)

        # # Minus Directional Indicator / Movement
        dataframe['minus_dm'] = ta.MINUS_DM(dataframe)
        dataframe['minus_di'] = ta.MINUS_DI(dataframe)

        # Aroon, Aroon Oscillator
        aroon = ta.AROON(dataframe)
        dataframe['aroonup'] = aroon['aroonup']
        dataframe['aroondown'] = aroon['aroondown']
        dataframe['aroonosc'] = ta.AROONOSC(dataframe)

        # Awesome Oscillator
        dataframe['ao'] = qtpylib.awesome_oscillator(dataframe)

        # # Keltner Channel
        # keltner = qtpylib.keltner_channel(dataframe)
        # dataframe["kc_upperband"] = keltner["upper"]
        # dataframe["kc_lowerband"] = keltner["lower"]
        # dataframe["kc_middleband"] = keltner["mid"]
        # dataframe["kc_percent"] = (
        #     (dataframe["close"] - dataframe["kc_lowerband"]) /
        #     (dataframe["kc_upperband"] - dataframe["kc_lowerband"])
        # )
        # dataframe["kc_width"] = (
        #     (dataframe["kc_upperband"] - dataframe["kc_lowerband"]) / dataframe["kc_middleband"]
        # )

        # Ultimate Oscillator
        dataframe['uo'] = ta.ULTOSC(dataframe)

        # Commodity Channel Index: values [Oversold:-100, Overbought:100]
        dataframe['cci'] = ta.CCI(dataframe)

        # RSI
        dataframe['rsi'] = ta.RSI(dataframe)

        # Inverse Fisher transform on RSI: values [-1.0, 1.0] (https://goo.gl/2JGGoy)
        rsi = 0.1 * (dataframe['rsi'] - 50)
        dataframe['fisher_rsi'] = (np.exp(2 * rsi) - 1) / (np.exp(2 * rsi) + 1)

        # Inverse Fisher transform on RSI normalized: values [0.0, 100.0] (https://goo.gl/2JGGoy)
        dataframe['fisher_rsi_norma'] = 50 * (dataframe['fisher_rsi'] + 1)

        # Stochastic Slow
        stoch = ta.STOCH(dataframe)
        dataframe['slowd'] = stoch['slowd']
        dataframe['slowk'] = stoch['slowk']

        # Stochastic Fast
        stoch_fast = ta.STOCHF(dataframe)
        dataframe['fastd'] = stoch_fast['fastd']
        dataframe['fastk'] = stoch_fast['fastk']

        # Stochastic RSI
        stoch_rsi = ta.STOCHRSI(dataframe)
        dataframe['fastd_rsi'] = stoch_rsi['fastd']
        dataframe['fastk_rsi'] = stoch_rsi['fastk']

        # MACD
        macd = ta.MACD(dataframe)
        dataframe['macd'] = macd['macd']
        dataframe['macdsignal'] = macd['macdsignal']
        dataframe['macdhist'] = macd['macdhist']

        # MFI
        dataframe['mfi'] = ta.MFI(dataframe)

        # # ROC
        dataframe['roc'] = ta.ROC(dataframe)

        # Overlap Studies
        # ------------------------------------

        # # Bollinger Bands
        # bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=2)
        # dataframe['bb_lowerband'] = bollinger['lower']
        # dataframe['bb_middleband'] = bollinger['mid']
        # dataframe['bb_upperband'] = bollinger['upper']
        # dataframe["bb_percent"] = (
        #     (dataframe["close"] - dataframe["bb_lowerband"]) /
        #     (dataframe["bb_upperband"] - dataframe["bb_lowerband"])
        # )
        # dataframe["bb_width"] = (
        #     (dataframe["bb_upperband"] - dataframe["bb_lowerband"]) / dataframe["bb_middleband"]
        # )

        # # Bollinger Bands - Weighted (EMA based instead of SMA)
        # weighted_bollinger = qtpylib.weighted_bollinger_bands(
        #     qtpylib.typical_price(dataframe), window=20, stds=2
        # )
        # dataframe["wbb_upperband"] = weighted_bollinger["upper"]
        # dataframe["wbb_lowerband"] = weighted_bollinger["lower"]
        # dataframe["wbb_middleband"] = weighted_bollinger["mid"]
        # dataframe["wbb_percent"] = (
        #     (dataframe["close"] - dataframe["wbb_lowerband"]) /
        #     (dataframe["wbb_upperband"] - dataframe["wbb_lowerband"])
        # )
        # dataframe["wbb_width"] = (
        #     (dataframe["wbb_upperband"] - dataframe["wbb_lowerband"]) /
        #     dataframe["wbb_middleband"]
        # )

        # # EMA - Exponential Moving Average
        # dataframe['ema3'] = ta.EMA(dataframe, timeperiod=3)
        # dataframe['ema5'] = ta.EMA(dataframe, timeperiod=5)
        # dataframe['ema10'] = ta.EMA(dataframe, timeperiod=10)
        # dataframe['ema21'] = ta.EMA(dataframe, timeperiod=21)
        # dataframe['ema50'] = ta.EMA(dataframe, timeperiod=50)
        # dataframe['ema100'] = ta.EMA(dataframe, timeperiod=100)

        # # SMA - Simple Moving Average
        # dataframe['sma3'] = ta.SMA(dataframe, timeperiod=3)
        # dataframe['sma5'] = ta.SMA(dataframe, timeperiod=5)
        # dataframe['sma10'] = ta.SMA(dataframe, timeperiod=10)
        # dataframe['sma21'] = ta.SMA(dataframe, timeperiod=21)
        # dataframe['sma50'] = ta.SMA(dataframe, timeperiod=50)
        # dataframe['sma100'] = ta.SMA(dataframe, timeperiod=100)

        # Parabolic SAR
        # dataframe['sar'] = ta.SAR(dataframe)

        # TEMA - Triple Exponential Moving Average
        # dataframe['tema'] = ta.TEMA(dataframe, timeperiod=9)

        # # Cycle Indicator
        # # ------------------------------------
        # # Hilbert Transform Indicator - SineWave
        # hilbert = ta.HT_SINE(dataframe)
        # dataframe['htsine'] = hilbert['sine']
        # dataframe['htleadsine'] = hilbert['leadsine']

        # # Pattern Recognition - Bullish candlestick patterns
        # # ------------------------------------
        # # Hammer: values [0, 100]
        # dataframe['CDLHAMMER'] = ta.CDLHAMMER(dataframe)
        # # Inverted Hammer: values [0, 100]
        # dataframe['CDLINVERTEDHAMMER'] = ta.CDLINVERTEDHAMMER(dataframe)
        # # Dragonfly Doji: values [0, 100]
        # dataframe['CDLDRAGONFLYDOJI'] = ta.CDLDRAGONFLYDOJI(dataframe)
        # # Piercing Line: values [0, 100]
        # dataframe['CDLPIERCING'] = ta.CDLPIERCING(dataframe) # values [0, 100]
        # # Morningstar: values [0, 100]
        # dataframe['CDLMORNINGSTAR'] = ta.CDLMORNINGSTAR(dataframe) # values [0, 100]
        # # Three White Soldiers: values [0, 100]
        # dataframe['CDL3WHITESOLDIERS'] = ta.CDL3WHITESOLDIERS(dataframe) # values [0, 100]

        # # Pattern Recognition - Bearish candlestick patterns
        # # ------------------------------------
        # # Hanging Man: values [0, 100]
        # dataframe['CDLHANGINGMAN'] = ta.CDLHANGINGMAN(dataframe)
        # # Shooting Star: values [0, 100]
        # dataframe['CDLSHOOTINGSTAR'] = ta.CDLSHOOTINGSTAR(dataframe)
        # # Gravestone Doji: values [0, 100]
        # dataframe['CDLGRAVESTONEDOJI'] = ta.CDLGRAVESTONEDOJI(dataframe)
        # # Dark Cloud Cover: values [0, 100]
        # dataframe['CDLDARKCLOUDCOVER'] = ta.CDLDARKCLOUDCOVER(dataframe)
        # # Evening Doji Star: values [0, 100]
        # dataframe['CDLEVENINGDOJISTAR'] = ta.CDLEVENINGDOJISTAR(dataframe)
        # # Evening Star: values [0, 100]
        # dataframe['CDLEVENINGSTAR'] = ta.CDLEVENINGSTAR(dataframe)

        # # Pattern Recognition - Bullish/Bearish candlestick patterns
        # # ------------------------------------
        # # Three Line Strike: values [0, -100, 100]
        # dataframe['CDL3LINESTRIKE'] = ta.CDL3LINESTRIKE(dataframe)
        # # Spinning Top: values [0, -100, 100]
        # dataframe['CDLSPINNINGTOP'] = ta.CDLSPINNINGTOP(dataframe) # values [0, -100, 100]
        # # Engulfing: values [0, -100, 100]
        # dataframe['CDLENGULFING'] = ta.CDLENGULFING(dataframe) # values [0, -100, 100]
        # # Harami: values [0, -100, 100]
        # dataframe['CDLHARAMI'] = ta.CDLHARAMI(dataframe) # values [0, -100, 100]
        # # Three Outside Up/Down: values [0, -100, 100]
        # dataframe['CDL3OUTSIDE'] = ta.CDL3OUTSIDE(dataframe) # values [0, -100, 100]
        # # Three Inside Up/Down: values [0, -100, 100]
        # dataframe['CDL3INSIDE'] = ta.CDL3INSIDE(dataframe) # values [0, -100, 100]

        # # Chart type
        # # ------------------------------------
        # # Heikin Ashi Strategy
        # heikinashi = qtpylib.heikinashi(dataframe)
        # dataframe['ha_open'] = heikinashi['open']
        # dataframe['ha_close'] = heikinashi['close']
        # dataframe['ha_high'] = heikinashi['high']
        # dataframe['ha_low'] = heikinashi['low']

        # Retrieve best bid and best ask from the orderbook
        # ------------------------------------
        """
        # first check if dataprovider is available
        if self.dp:
            if self.dp.runmode in ('live', 'dry_run'):
                ob = self.dp.orderbook(metadata['pair'], 1)
                dataframe['best_bid'] = ob['bids'][0][0]
                dataframe['best_ask'] = ob['asks'][0][0]
        """

        return dataframe
Пример #27
0
    def DI(self):
        minus_di = abstract.MINUS_DI(self.company_stock, timeperiod=14)
        plus_di = abstract.PLUS_DI(self.company_stock, timeperiod=14)

        self.company_stock['MINUS_DI'] = minus_di
        self.company_stock['PLUS_DI'] = plus_di
Пример #28
0
    def populate_indicators(dataframe: DataFrame) -> DataFrame:
        """
        Adds several different TA indicators to the given DataFrame
        """
        dataframe['adx'] = ta.ADX(dataframe)
        dataframe['ao'] = qtpylib.awesome_oscillator(dataframe)
        dataframe['cci'] = ta.CCI(dataframe)
        macd = ta.MACD(dataframe)
        dataframe['macd'] = macd['macd']
        dataframe['macdsignal'] = macd['macdsignal']
        dataframe['macdhist'] = macd['macdhist']
        dataframe['mfi'] = ta.MFI(dataframe)
        dataframe['minus_dm'] = ta.MINUS_DM(dataframe)
        dataframe['minus_di'] = ta.MINUS_DI(dataframe)
        dataframe['plus_dm'] = ta.PLUS_DM(dataframe)
        dataframe['plus_di'] = ta.PLUS_DI(dataframe)
        dataframe['roc'] = ta.ROC(dataframe)
        dataframe['rsi'] = ta.RSI(dataframe)
        # Inverse Fisher transform on RSI, values [-1.0, 1.0] (https://goo.gl/2JGGoy)
        rsi = 0.1 * (dataframe['rsi'] - 50)
        dataframe['fisher_rsi'] = (numpy.exp(2 * rsi) - 1) / (numpy.exp(2 * rsi) + 1)
        # Inverse Fisher transform on RSI normalized, value [0.0, 100.0] (https://goo.gl/2JGGoy)
        dataframe['fisher_rsi_norma'] = 50 * (dataframe['fisher_rsi'] + 1)
        # Stoch
        stoch = ta.STOCH(dataframe)
        dataframe['slowd'] = stoch['slowd']
        dataframe['slowk'] = stoch['slowk']
        # Stoch fast
        stoch_fast = ta.STOCHF(dataframe)
        dataframe['fastd'] = stoch_fast['fastd']
        dataframe['fastk'] = stoch_fast['fastk']
        # Stoch RSI
        stoch_rsi = ta.STOCHRSI(dataframe)
        dataframe['fastd_rsi'] = stoch_rsi['fastd']
        dataframe['fastk_rsi'] = stoch_rsi['fastk']
        # Bollinger bands
        bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=2)
        dataframe['bb_lowerband'] = bollinger['lower']
        dataframe['bb_middleband'] = bollinger['mid']
        dataframe['bb_upperband'] = bollinger['upper']
        # EMA - Exponential Moving Average
        dataframe['ema3'] = ta.EMA(dataframe, timeperiod=3)
        dataframe['ema5'] = ta.EMA(dataframe, timeperiod=5)
        dataframe['ema10'] = ta.EMA(dataframe, timeperiod=10)
        dataframe['ema50'] = ta.EMA(dataframe, timeperiod=50)
        dataframe['ema100'] = ta.EMA(dataframe, timeperiod=100)
        # SAR Parabolic
        dataframe['sar'] = ta.SAR(dataframe)
        # SMA - Simple Moving Average
        dataframe['sma'] = ta.SMA(dataframe, timeperiod=40)
        # TEMA - Triple Exponential Moving Average
        dataframe['tema'] = ta.TEMA(dataframe, timeperiod=9)
        # Hilbert Transform Indicator - SineWave
        hilbert = ta.HT_SINE(dataframe)
        dataframe['htsine'] = hilbert['sine']
        dataframe['htleadsine'] = hilbert['leadsine']

        # Pattern Recognition - Bullish candlestick patterns
        # ------------------------------------
        """
        # Hammer: values [0, 100]
        dataframe['CDLHAMMER'] = ta.CDLHAMMER(dataframe)
        # Inverted Hammer: values [0, 100]
        dataframe['CDLINVERTEDHAMMER'] = ta.CDLINVERTEDHAMMER(dataframe)
        # Dragonfly Doji: values [0, 100]
        dataframe['CDLDRAGONFLYDOJI'] = ta.CDLDRAGONFLYDOJI(dataframe)
        # Piercing Line: values [0, 100]
        dataframe['CDLPIERCING'] = ta.CDLPIERCING(dataframe) # values [0, 100]
        # Morningstar: values [0, 100]
        dataframe['CDLMORNINGSTAR'] = ta.CDLMORNINGSTAR(dataframe) # values [0, 100]
        # Three White Soldiers: values [0, 100]
        dataframe['CDL3WHITESOLDIERS'] = ta.CDL3WHITESOLDIERS(dataframe) # values [0, 100]
        """

        # Pattern Recognition - Bearish candlestick patterns
        # ------------------------------------
        """
        # Hanging Man: values [0, 100]
        dataframe['CDLHANGINGMAN'] = ta.CDLHANGINGMAN(dataframe)
        # Shooting Star: values [0, 100]
        dataframe['CDLSHOOTINGSTAR'] = ta.CDLSHOOTINGSTAR(dataframe)
        # Gravestone Doji: values [0, 100]
        dataframe['CDLGRAVESTONEDOJI'] = ta.CDLGRAVESTONEDOJI(dataframe)
        # Dark Cloud Cover: values [0, 100]
        dataframe['CDLDARKCLOUDCOVER'] = ta.CDLDARKCLOUDCOVER(dataframe)
        # Evening Doji Star: values [0, 100]
        dataframe['CDLEVENINGDOJISTAR'] = ta.CDLEVENINGDOJISTAR(dataframe)
        # Evening Star: values [0, 100]
        dataframe['CDLEVENINGSTAR'] = ta.CDLEVENINGSTAR(dataframe)
        """

        # Pattern Recognition - Bullish/Bearish candlestick patterns
        # ------------------------------------
        """
        # Three Line Strike: values [0, -100, 100]
        dataframe['CDL3LINESTRIKE'] = ta.CDL3LINESTRIKE(dataframe)
        # Spinning Top: values [0, -100, 100]
        dataframe['CDLSPINNINGTOP'] = ta.CDLSPINNINGTOP(dataframe) # values [0, -100, 100]
        # Engulfing: values [0, -100, 100]
        dataframe['CDLENGULFING'] = ta.CDLENGULFING(dataframe) # values [0, -100, 100]
        # Harami: values [0, -100, 100]
        dataframe['CDLHARAMI'] = ta.CDLHARAMI(dataframe) # values [0, -100, 100]
        # Three Outside Up/Down: values [0, -100, 100]
        dataframe['CDL3OUTSIDE'] = ta.CDL3OUTSIDE(dataframe) # values [0, -100, 100]
        # Three Inside Up/Down: values [0, -100, 100]
        dataframe['CDL3INSIDE'] = ta.CDL3INSIDE(dataframe) # values [0, -100, 100]
        """

        # Chart type
        # ------------------------------------
        # Heikinashi stategy
        heikinashi = qtpylib.heikinashi(dataframe)
        dataframe['ha_open'] = heikinashi['open']
        dataframe['ha_close'] = heikinashi['close']
        dataframe['ha_high'] = heikinashi['high']
        dataframe['ha_low'] = heikinashi['low']

        return dataframe
    def populate_indicators(self, dataframe: DataFrame) -> DataFrame:
        """
        Adds several different TA indicators to the given DataFrame

        Performance Note: For the best performance be frugal on the number of indicators
        you are using. Let uncomment only the indicator you are using in your strategies
        or your hyperopt configuration, otherwise you will waste your memory and CPU usage.
        """

        # Momentum Indicator
        # ------------------------------------

        # ADX
        dataframe['adx'] = ta.ADX(dataframe)

        # Awesome oscillator
        dataframe['ao'] = qtpylib.awesome_oscillator(dataframe)
        """
        # Commodity Channel Index: values Oversold:<-100, Overbought:>100
        dataframe['cci'] = ta.CCI(dataframe)
        """
        # MACD
        macd = ta.MACD(dataframe)
        dataframe['macd'] = macd['macd']
        dataframe['macdsignal'] = macd['macdsignal']
        dataframe['macdhist'] = macd['macdhist']

        # MFI
        dataframe['mfi'] = ta.MFI(dataframe)

        # Minus Directional Indicator / Movement
        dataframe['minus_dm'] = ta.MINUS_DM(dataframe)
        dataframe['minus_di'] = ta.MINUS_DI(dataframe)

        # Plus Directional Indicator / Movement
        dataframe['plus_dm'] = ta.PLUS_DM(dataframe)
        dataframe['plus_di'] = ta.PLUS_DI(dataframe)
        dataframe['minus_di'] = ta.MINUS_DI(dataframe)
        """
        # ROC
        dataframe['roc'] = ta.ROC(dataframe)
        """
        # RSI
        dataframe['rsi'] = ta.RSI(dataframe)

        # Inverse Fisher transform on RSI, values [-1.0, 1.0] (https://goo.gl/2JGGoy)
        dataframe['fisher_rsi'] = fishers_inverse(dataframe['rsi'])

        # Inverse Fisher transform on RSI normalized, value [0.0, 100.0] (https://goo.gl/2JGGoy)
        dataframe['fisher_rsi_norma'] = 50 * (dataframe['fisher_rsi'] + 1)

        # Stoch
        stoch = ta.STOCH(dataframe)
        dataframe['slowd'] = stoch['slowd']
        dataframe['slowk'] = stoch['slowk']

        # Stoch fast
        stoch_fast = ta.STOCHF(dataframe)
        dataframe['fastd'] = stoch_fast['fastd']
        dataframe['fastk'] = stoch_fast['fastk']
        """
        # Stoch RSI
        stoch_rsi = ta.STOCHRSI(dataframe)
        dataframe['fastd_rsi'] = stoch_rsi['fastd']
        dataframe['fastk_rsi'] = stoch_rsi['fastk']
        """

        # Overlap Studies
        # ------------------------------------

        # Previous Bollinger bands
        # Because ta.BBANDS implementation is broken with small numbers, it actually
        # returns middle band for all the three bands. Switch to qtpylib.bollinger_bands
        # and use middle band instead.
        dataframe['blower'] = ta.BBANDS(dataframe, nbdevup=2,
                                        nbdevdn=2)['lowerband']

        # Bollinger bands
        bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe),
                                            window=20,
                                            stds=2)
        dataframe['bb_lowerband'] = bollinger['lower']
        dataframe['bb_middleband'] = bollinger['mid']
        dataframe['bb_upperband'] = bollinger['upper']

        # EMA - Exponential Moving Average
        dataframe['ema3'] = ta.EMA(dataframe, timeperiod=3)
        dataframe['ema5'] = ta.EMA(dataframe, timeperiod=5)
        dataframe['ema10'] = ta.EMA(dataframe, timeperiod=10)
        dataframe['ema50'] = ta.EMA(dataframe, timeperiod=50)
        dataframe['ema100'] = ta.EMA(dataframe, timeperiod=100)

        # SAR Parabol
        dataframe['sar'] = ta.SAR(dataframe)

        # SMA - Simple Moving Average
        dataframe['sma'] = ta.SMA(dataframe, timeperiod=40)

        # TEMA - Triple Exponential Moving Average
        dataframe['tema'] = ta.TEMA(dataframe, timeperiod=9)

        # Cycle Indicator
        # ------------------------------------
        # Hilbert Transform Indicator - SineWave
        hilbert = ta.HT_SINE(dataframe)
        dataframe['htsine'] = hilbert['sine']
        dataframe['htleadsine'] = hilbert['leadsine']

        # Pattern Recognition - Bullish candlestick patterns
        # ------------------------------------
        """
        # Hammer: values [0, 100]
        dataframe['CDLHAMMER'] = ta.CDLHAMMER(dataframe)
        # Inverted Hammer: values [0, 100]
        dataframe['CDLINVERTEDHAMMER'] = ta.CDLINVERTEDHAMMER(dataframe)
        # Dragonfly Doji: values [0, 100]
        dataframe['CDLDRAGONFLYDOJI'] = ta.CDLDRAGONFLYDOJI(dataframe)
        # Piercing Line: values [0, 100]
        dataframe['CDLPIERCING'] = ta.CDLPIERCING(dataframe) # values [0, 100]
        # Morningstar: values [0, 100]
        dataframe['CDLMORNINGSTAR'] = ta.CDLMORNINGSTAR(dataframe) # values [0, 100]
        # Three White Soldiers: values [0, 100]
        dataframe['CDL3WHITESOLDIERS'] = ta.CDL3WHITESOLDIERS(dataframe) # values [0, 100]
        """

        # Pattern Recognition - Bearish candlestick patterns
        # ------------------------------------
        """
        # Hanging Man: values [0, 100]
        dataframe['CDLHANGINGMAN'] = ta.CDLHANGINGMAN(dataframe)
        # Shooting Star: values [0, 100]
        dataframe['CDLSHOOTINGSTAR'] = ta.CDLSHOOTINGSTAR(dataframe)
        # Gravestone Doji: values [0, 100]
        dataframe['CDLGRAVESTONEDOJI'] = ta.CDLGRAVESTONEDOJI(dataframe)
        # Dark Cloud Cover: values [0, 100]
        dataframe['CDLDARKCLOUDCOVER'] = ta.CDLDARKCLOUDCOVER(dataframe)
        # Evening Doji Star: values [0, 100]
        dataframe['CDLEVENINGDOJISTAR'] = ta.CDLEVENINGDOJISTAR(dataframe)
        # Evening Star: values [0, 100]
        dataframe['CDLEVENINGSTAR'] = ta.CDLEVENINGSTAR(dataframe)
        """

        # Pattern Recognition - Bullish/Bearish candlestick patterns
        # ------------------------------------
        """
        # Three Line Strike: values [0, -100, 100]
        dataframe['CDL3LINESTRIKE'] = ta.CDL3LINESTRIKE(dataframe)
        # Spinning Top: values [0, -100, 100]
        dataframe['CDLSPINNINGTOP'] = ta.CDLSPINNINGTOP(dataframe) # values [0, -100, 100]
        # Engulfing: values [0, -100, 100]
        dataframe['CDLENGULFING'] = ta.CDLENGULFING(dataframe) # values [0, -100, 100]
        # Harami: values [0, -100, 100]
        dataframe['CDLHARAMI'] = ta.CDLHARAMI(dataframe) # values [0, -100, 100]
        # Three Outside Up/Down: values [0, -100, 100]
        dataframe['CDL3OUTSIDE'] = ta.CDL3OUTSIDE(dataframe) # values [0, -100, 100]
        # Three Inside Up/Down: values [0, -100, 100]
        dataframe['CDL3INSIDE'] = ta.CDL3INSIDE(dataframe) # values [0, -100, 100]
        """

        # Chart type
        # ------------------------------------
        # Heikinashi stategy
        heikinashi = qtpylib.heikinashi(dataframe)
        dataframe['ha_open'] = heikinashi['open']
        dataframe['ha_close'] = heikinashi['close']
        dataframe['ha_high'] = heikinashi['high']
        dataframe['ha_low'] = heikinashi['low']

        return dataframe
Пример #30
0
 def __countDMI(self):
   self.adx = ta.ADX(self.stock.inputs)
   self.plus_di = ta.PLUS_DI(self.stock.inputs)
   self.minus_di = ta.MINUS_DI(self.stock.inputs)