Example #1
0
    def populate_exit_trend(self, dataframe: DataFrame,
                            metadata: dict) -> DataFrame:
        """
        Based on TA indicators, populates the exit signal for the given dataframe
        :param dataframe: DataFrame
        :param metadata: Additional information, like the currently traded pair
        :return: DataFrame with exit columns populated
        """
        dataframe.loc[(
            # Signal: RSI crosses above 70
            (qtpylib.crossed_above(dataframe['rsi'], self.sell_rsi.value)) &
            (dataframe['tema'] > dataframe['bb_middleband'])
            &  # Guard: tema above BB middle
            (dataframe['tema'] < dataframe['tema'].shift(1))
            &  # Guard: tema is falling
            (dataframe['volume'] > 0)  # Make sure Volume is not 0
        ), 'exit_long'] = 1

        dataframe.loc[(
            # Signal: RSI crosses above 30
            (qtpylib.crossed_above(dataframe['rsi'], self.exit_short_rsi.value
                                   )) &
            # Guard: tema below BB middle
            (dataframe['tema'] <= dataframe['bb_middleband']) &
            (dataframe['tema'] > dataframe['tema'].shift(1))
            &  # Guard: tema is raising
            (dataframe['volume'] > 0)  # Make sure Volume is not 0
        ), 'exit_short'] = 1

        return dataframe
 def populate_sell_trend(self, dataframe: DataFrame,
                         metadata: dict) -> DataFrame:
     dataframe.loc[((((dataframe['open'] >= dataframe['ema_high'])) |
                     ((qtpylib.crossed_above(dataframe['fastk'], 70)) |
                      (qtpylib.crossed_above(dataframe['fastd'], 70)))) &
                    (dataframe['cci'] > 100)), 'sell'] = 1
     return dataframe
        def populate_buy_trend(dataframe: DataFrame,
                               metadata: dict) -> DataFrame:
            """
            Buy strategy Hyperopt will build and use
            """
            conditions = []
            # GUARDS AND TRENDS
            if 'mfi-enabled' in params and params['mfi-enabled']:
                conditions.append(dataframe['mfi'] < params['mfi-value'])
            if 'fastd-enabled' in params and params['fastd-enabled']:
                conditions.append(dataframe['fastd'] < params['fastd-value'])
            if 'adx-enabled' in params and params['adx-enabled']:
                conditions.append(dataframe['adx'] > params['adx-value'])
            if 'rsi-enabled' in params and params['rsi-enabled']:
                conditions.append(dataframe['rsi'] < params['rsi-value'])

            # TRIGGERS
            if 'trigger' in params:
                if params['trigger'] == 'bb_lower':
                    conditions.append(
                        dataframe['close'] < dataframe['bb_lowerband'])
                if params['trigger'] == 'macd_cross_signal':
                    conditions.append(
                        qtpylib.crossed_above(dataframe['macd'],
                                              dataframe['macdsignal']))
                if params['trigger'] == 'sar_reversal':
                    conditions.append(
                        qtpylib.crossed_above(dataframe['close'],
                                              dataframe['sar']))

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

            return dataframe
Example #4
0
    def mac(self,
            dataframe: DataFrame,
            fast: int = 20,
            slow: int = 50) -> Series:

        dataframe = dataframe.copy()

        # Fast MAs
        upper_fast = ta.EMA(dataframe['high'], timeperiod=fast)
        lower_fast = ta.EMA(dataframe['low'], timeperiod=fast)

        # Slow MAs
        upper_slow = ta.EMA(dataframe['high'], timeperiod=slow)
        lower_slow = ta.EMA(dataframe['low'], timeperiod=slow)

        # Crosses
        crosses_lf_us = qtpylib.crossed_above(
            lower_fast, upper_slow) | qtpylib.crossed_below(
                lower_fast, upper_slow)
        crosses_uf_ls = qtpylib.crossed_above(
            upper_fast, lower_slow) | qtpylib.crossed_below(
                upper_fast, lower_slow)

        dir_1 = np.where(crosses_lf_us, 1, np.nan)
        dir_2 = np.where(crosses_uf_ls, -1, np.nan)

        dir = np.where(dir_1 == 1, dir_1, np.nan)
        dir = np.where(dir_2 == -1, dir_2, dir_1)

        res = Series(dir).fillna(method='ffill').to_numpy()

        return res
        def populate_sell_trend(dataframe: DataFrame,
                                metadata: dict) -> DataFrame:
            """
            Sell strategy Hyperopt will build and use
            """
            # print(params)
            conditions = []
            # GUARDS AND TRENDS
            if 'sell-mfi-enabled' in params and params['sell-mfi-enabled']:
                conditions.append(dataframe['mfi'] > params['sell-mfi-value'])
            if 'sell-fastd-enabled' in params and params['sell-fastd-enabled']:
                conditions.append(
                    dataframe['fastd'] > params['sell-fastd-value'])
            if 'sell-adx-enabled' in params and params['sell-adx-enabled']:
                conditions.append(dataframe['adx'] < params['sell-adx-value'])
            if 'sell-rsi-enabled' in params and params['sell-rsi-enabled']:
                conditions.append(dataframe['rsi'] > params['sell-rsi-value'])

            # TRIGGERS
            if 'sell-trigger' in params:
                if params['sell-trigger'] == 'sell-bb_upper':
                    conditions.append(
                        dataframe['close'] > dataframe['bb_upperband'])
                if params['sell-trigger'] == 'sell-macd_cross_signal':
                    conditions.append(
                        qtpylib.crossed_above(dataframe['macdsignal'],
                                              dataframe['macd']))
                if params['sell-trigger'] == 'sell-sar_reversal':
                    conditions.append(
                        qtpylib.crossed_above(dataframe['sar'],
                                              dataframe['close']))

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

            return dataframe
        def populate_buy_trend(dataframe: DataFrame,
                               metadata: dict) -> DataFrame:
            """
            Buy strategy Hyperopt will build and use.
            """
            conditions = []

            conditions.append(dataframe[f"rsi({params['rsi-period']})"] >
                              params['rsi-lower-band'])
            conditions.append(
                qtpylib.crossed_above(dataframe['stoch-slowd'],
                                      params['stoch-lower-band']))
            conditions.append(
                qtpylib.crossed_above(dataframe['stoch-slowk'],
                                      params['stoch-lower-band']))
            conditions.append(
                qtpylib.crossed_above(dataframe['stoch-slowk'],
                                      dataframe['stoch-slowd']))

            # Check that the candle had volume
            conditions.append(dataframe['volume'] > 0)

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

            return dataframe
Example #7
0
    def populate_buy_trend(self, dataframe: DataFrame,
                           metadata: dict) -> DataFrame:
        dataframe.loc[(
            (qtpylib.crossed_above(dataframe['rsi'], 50)) &
            (qtpylib.crossed_above(dataframe['ema5'], dataframe['ema10'])) &
            (dataframe['adx'] > 25) &
            (dataframe['volume'] > 0)  # Make sure Volume is not 0
        ), 'buy'] = 1

        return dataframe
Example #8
0
 def populate_sell_trend(self, dataframe: DataFrame) -> DataFrame:
     """
     Based on TA indicators, populates the sell signal for the given dataframe
     :param dataframe: DataFrame
     :return: DataFrame with buy column
     """
     dataframe.loc[(((qtpylib.crossed_above(dataframe['rsi'], 70)) |
                     (qtpylib.crossed_above(dataframe['fastd'], 70))) &
                    (dataframe['adx'] > 10) & (dataframe['minus_di'] > 0)) |
                   ((dataframe['adx'] > 70) &
                    (dataframe['minus_di'] > 0.5)), 'sell'] = 1
     return dataframe
Example #9
0
    def populate_sell_trend(self, dataframe: DataFrame) -> DataFrame:
        """
        Based on TA indicators, populates the sell signal for the given dataframe
        :param dataframe: DataFrame
        :return: DataFrame with buy column
        """
        dataframe.loc[((dataframe['open'] >= dataframe['ema_high'])) | (
            # (dataframe['fastk'] > 70) &
            # (dataframe['fastd'] > 70)
            (qtpylib.crossed_above(dataframe['fastk'], 70)) |
            (qtpylib.crossed_above(dataframe['fastd'], 70))), 'sell'] = 1

        return dataframe
Example #10
0
 def populate_sell_trend(self, dataframe: DataFrame,
                         metadata: dict) -> DataFrame:
     """
     Based on TA indicators, populates the sell signal for the given dataframe
     :param dataframe: DataFrame
     :param metadata: Additional information, like the currently traded pair
     :return: DataFrame with buy column
     """
     dataframe.loc[(((qtpylib.crossed_above(dataframe['rsi'], 70)) |
                     (qtpylib.crossed_above(dataframe['fastd'], 70))) &
                    (dataframe['adx'] > 10) & (dataframe['minus_di'] > 0)) |
                   ((dataframe['adx'] > 70) &
                    (dataframe['minus_di'] > 0.5)), 'sell'] = 1
     return dataframe
Example #11
0
    def populate_exit_trend(self, dataframe: DataFrame,
                            metadata: dict) -> DataFrame:
        dataframe.loc[(
            ((qtpylib.crossed_above(dataframe['rsi'], self.sell_rsi.value)) |
             (qtpylib.crossed_above(dataframe['fastd'], 70))) &
            (dataframe['adx'] > 10) & (dataframe['minus_di'] > 0)) |
                      ((dataframe['adx'] > 70) &
                       (dataframe['minus_di'] > self.sell_minusdi.value)),
                      'exit_long'] = 1

        dataframe.loc[(
            qtpylib.crossed_above(dataframe['rsi'], self.buy_rsi.value)),
                      'exit_short'] = 1

        return dataframe
Example #12
0
def test_crossed_numpy_types():
    """
    This test is only present since this method currently diverges from the qtpylib implementation.
    And we must ensure to not break this again once we update from the original source.
    """
    series = pd.Series([56, 97, 19, 76, 65, 25, 87, 91, 79, 79])
    expected_result = pd.Series(
        [False, True, False, True, False, False, True, False, False, False])

    assert qtpylib.crossed_above(series, 60).equals(expected_result)
    assert qtpylib.crossed_above(series, 60.0).equals(expected_result)
    assert qtpylib.crossed_above(series, np.int32(60)).equals(expected_result)
    assert qtpylib.crossed_above(series, np.int64(60)).equals(expected_result)
    assert qtpylib.crossed_above(series,
                                 np.float64(60.0)).equals(expected_result)
Example #13
0
    def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        """
        Only used when --spaces does not include buy
        """
        dataframe.loc[
            (
                (qtpylib.crossed_above(dataframe['rsi'], 30)) &  # Signal: RSI crosses above lower band
                (qtpylib.crossed_above(dataframe['stoch-slowd'], 20)) &  # Signal: Stoch slowd crosses above lower band
                (qtpylib.crossed_above(dataframe['stoch-slowk'], 20)) &  # Signal: Stoch slowk crosses above lower band
                (qtpylib.crossed_above(dataframe['stoch-slowk'], dataframe['stoch-slowd'])) &  # Signal: Stoch slowk crosses slowd
                (dataframe['volume'] > 0)  # Make sure Volume is not 0
            ),
            'buy'] = 1

        return dataframe
 def populate_sell_trend(self, dataframe: DataFrame,
                         metadata: dict) -> DataFrame:
     dataframe.loc[(
         (dataframe['adx'] < 25) &
         (qtpylib.crossed_above(dataframe['long'], dataframe['short']))),
                   'sell'] = 1
     return dataframe
    def populate_sell_trend(self, dataframe: DataFrame,
                            metadata: dict) -> DataFrame:
        dataframe.loc[(qtpylib.crossed_above(
            dataframe['close'], dataframe[f"30d-high_{self.inf_timeframe}"])),
                      'sell'] = 1

        return dataframe
Example #16
0
        def populate_buy_trend(dataframe: DataFrame,
                               metadata: dict) -> DataFrame:
            conditions = []

            # GUARDS AND TRENDS
            if params.get("ema-low-enabled"):
                conditions.append(dataframe["open"] < dataframe["ema-low"])
            if params.get("fastk-enabled"):
                conditions.append(dataframe["fastk"] < params["fastk-value"])
            if params.get("fastd-enabled"):
                conditions.append(dataframe["fastd"] < params["fastd-value"])
            if params.get("adx-enabled"):
                conditions.append(dataframe["adx"] > params["adx-value"])

            # TRIGGERS
            if "trigger" in params:
                if params["trigger"] == "fastk_cross_fastd":
                    conditions.append(
                        qtpylib.crossed_above(dataframe["fastk"],
                                              dataframe["fastd"]))

            conditions.append(dataframe["volume"] > 0)

            if conditions:
                dataframe.loc[reduce(lambda x, y: x & y, conditions),
                              "buy"] = 1
            return dataframe
Example #17
0
        def populate_buy_trend(dataframe: DataFrame,
                               metadata: dict) -> DataFrame:
            conditions = []

            # GUARDS AND TRENDS
            if params.get("tema-enabled"):
                conditions.append(
                    dataframe["tema"] > dataframe["tema"].shift(1))
            if params.get("bb-lowerband-enabled"):
                conditions.append(
                    dataframe["open"] <= dataframe["bb_lowerband"])

            # TRIGGERS
            if "trigger" in params:
                if params["trigger"] == "rsi_cross_signal":
                    conditions.append(
                        qtpylib.crossed_above(dataframe["rsi"],
                                              params["rsi-value"]))

            conditions.append(dataframe["volume"] > 0)

            if conditions:
                dataframe.loc[reduce(lambda x, y: x & y, conditions),
                              "buy"] = 1
            return dataframe
Example #18
0
    def populate_sell_trend(self, dataframe: DataFrame,
                            metadata: dict) -> DataFrame:
        conditions = list()
        for i in range(self.Sell_DNA_Size):
            OPR = self.sell_params[f'sell-oper-{i}']
            IND = self.sell_params[f'sell-indicator-{i}']
            CRS = self.sell_params[f'sell-cross-{i}']
            REAL = self.sell_params[f'sell-real-{i}']
            DFIND = dataframe[IND]
            DFCRS = dataframe[CRS]

            if OPR == ">":
                conditions.append(DFIND > DFCRS)
            elif OPR == "=":
                conditions.append(np.isclose(DFIND, DFCRS))
            elif OPR == "<":
                conditions.append(DFIND < DFCRS)
            elif OPR == "CA":
                conditions.append(qtpylib.crossed_above(DFIND, DFCRS))
            elif OPR == "CB":
                conditions.append(qtpylib.crossed_below(DFIND, DFCRS))
            elif OPR == ">R":
                conditions.append(DFIND > REAL)
            elif OPR == "=R":
                conditions.append(np.isclose(DFIND, REAL))
            elif OPR == "<R":
                conditions.append(DFIND < REAL)

        if self.Sell_DNA_Size > 0:
            dataframe.loc[reduce(lambda x, y: x & y, conditions), 'sell'] = 1

        return dataframe
Example #19
0
        def populate_sell_trend(dataframe: DataFrame,
                                metadata: dict) -> DataFrame:
            conditions = []

            conditions.append(
                (dataframe["open"] >= dataframe["ema-high"])
                | qtpylib.crossed_above(dataframe["fastk"],
                                        params["sell-fastk-value"])
                | qtpylib.crossed_above(dataframe["fastd"],
                                        params["sell-fastd-value"]))

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

            return dataframe
Example #20
0
        def populate_buy_trend(dataframe: DataFrame,
                               metadata: dict) -> DataFrame:
            """
            Buy strategy Hyperopt will build and use.
            """
            conditions = []

            # GUARDS AND TRENDS
            if params.get('adx-enabled'):
                conditions.append(dataframe['adx'] > params['adx-value'])

            if params.get('minus-enabled'):
                conditions.append(
                    dataframe['minus_di'] > params['minus_di-value'])

            if params.get('plus-enabled'):
                conditions.append(
                    dataframe['plus_di'] > params['plus_di-value'])

            # TRIGGERS
            if 'trigger' in params:
                if params['trigger'] == 'buy_signal':
                    conditions.append(
                        qtpylib.crossed_above(dataframe['plus_di'],
                                              dataframe['minus_di']))

            # Check that the candle had volume
            conditions.append(dataframe['volume'] > 0)

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

            return dataframe
Example #21
0
    def populate_buy_trend(self, dataframe: DataFrame,
                           metadata: dict) -> DataFrame:
        dataframe.loc[((
            qtpylib.crossed_above(dataframe['ZLEMA'], dataframe['pm_40_3_40_9']
                                  ))), 'buy'] = 1

        return dataframe
Example #22
0
    def market_cipher(self, dataframe) -> DataFrame:
        #dataframe['volume_rolling'] = dataframe['volume'].shift(14).rolling(14).mean()
        #
        osLevel = -60
        obLevel = 30
        dataframe['ap'] = (dataframe['high'] + dataframe['low'] +
                           dataframe['close']) / 3
        dataframe['esa'] = ta.EMA(dataframe['ap'], self.n1)
        dataframe['d'] = ta.EMA((dataframe['ap'] - dataframe['esa']).abs(),
                                self.n1)
        dataframe['ci'] = (dataframe['ap'] -
                           dataframe['esa']) / (0.015 * dataframe['d'])
        dataframe['tci'] = ta.EMA(dataframe['ci'], self.n2)

        dataframe['wt1'] = dataframe['tci']
        dataframe['wt2'] = ta.SMA(dataframe['wt1'], 4)

        dataframe['wtVwap'] = dataframe['wt1'] - dataframe['wt2']
        dataframe['wtOversold'] = dataframe['wt2'] <= osLevel
        dataframe['wtOverbought'] = dataframe['wt2'] >= obLevel

        dataframe['wtCrossUp'] = dataframe['wt2'] - dataframe['wt1'] <= 0
        dataframe['wtCrossDown'] = dataframe['wt2'] - dataframe['wt1'] >= 0
        dataframe['crossed_above'] = qtpylib.crossed_above(
            dataframe['wt2'], dataframe['wt1'])
        dataframe['crossed_below'] = qtpylib.crossed_below(
            dataframe['wt2'], dataframe['wt1'])

        return dataframe
Example #23
0
        def populate_sell_trend(dataframe: DataFrame,
                                metadata: dict) -> DataFrame:

            # TRIGGERS and GUARDS
            # Solving a mistery: Which sell trigger is better?
            # The winner of both will be displayed in the output of the hyperopt.

            conditions = []

            if 'sell-trigger' in params:
                if params['sell-trigger'] == 'rsi-macd-minusdi':
                    conditions.append(
                        qtpylib.crossed_above(dataframe['rsi'],
                                              params['rsi-sell-value']))
                    conditions.append(dataframe['macd'] < 0)
                    conditions.append(
                        dataframe['minus_di'] > params['minusdi-sell-value'])

            if 'sell-trigger' in params:
                if params['sell-trigger'] == 'sar-fisherRsi':
                    conditions.append(dataframe['sar'] > dataframe['close'])
                    conditions.append(dataframe['fisher_rsi'] >
                                      params['fishRsiNorma-sell-value'])

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

            return dataframe
Example #24
0
        def populate_buy_trend(dataframe: DataFrame,
                               metadata: dict) -> DataFrame:

            conditions = []

            # TRIGGERS & GUARDS
            if 'trigger' in params:

                for cciTime in cciTimeRange:

                    cciName = "cci-" + str(cciTime)

                    if params['trigger'] == cciName:
                        conditions.append(
                            dataframe[cciName] < params["buy-cci-value"])
                        conditions.append(
                            dataframe['macd'] > dataframe['macdsignal'])
                        conditions.append(dataframe['volume'] > 0)
                        conditions.append(
                            qtpylib.crossed_above(dataframe['macd'],
                                                  dataframe['macdsignal']))

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

            return dataframe
Example #25
0
        def populate_sell_trend(dataframe: DataFrame,
                                metadata: dict) -> DataFrame:
            conditions = []

            # GUARDS AND TRENDS
            if params.get('sell-adx-enabled'):
                conditions.append(
                    dataframe['sell-adx'] > params['sell-adx-value'])
            if params.get('sell-plus-enabled'):
                conditions.append(
                    dataframe['sell-plus_di'] > params['sell-plus_di-value'])
            if params.get('sell-minus-enabled'):
                conditions.append(
                    dataframe['sell-minus_di'] > params['sell-minus_di-value'])

            # TRIGGERS
            if 'sell-trigger' in params:
                if params['sell-trigger'] == 'sell_signal':
                    conditions.append(
                        qtpylib.crossed_above(dataframe['sell-plus_di'],
                                              dataframe['sell-minus_di']))

            conditions.append(dataframe['volume'] > 0)

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

            return dataframe
Example #26
0
    def populate_buy_trend(self, dataframe: DataFrame,
                           metadata: dict) -> DataFrame:

        dataframe.loc[qtpylib.crossed_above(dataframe['go_long'], 0),
                      'buy'] = 1

        return dataframe
    def market_cipher(self, dataframe) -> DataFrame:
        self.n1 = 10  #WT Channel Length
        self.n2 = 21  #WT Average Length

        dataframe['ap'] = (dataframe['high'] + dataframe['low'] +
                           dataframe['close']) / 3
        dataframe['esa'] = ta.EMA(dataframe['ap'], self.n1)
        dataframe['d'] = ta.EMA((dataframe['ap'] - dataframe['esa']).abs(),
                                self.n1)
        dataframe['ci'] = (dataframe['ap'] -
                           dataframe['esa']) / (0.015 * dataframe['d'])
        dataframe['tci'] = ta.EMA(dataframe['ci'], self.n2)

        dataframe['wt1'] = dataframe['tci']
        dataframe['wt2'] = ta.SMA(dataframe['wt1'], 4)

        dataframe['wtVwap'] = dataframe['wt1'] - dataframe['wt2']

        dataframe['wtCrossUp'] = dataframe['wt2'] - dataframe['wt1'] <= 0
        dataframe['wtCrossDown'] = dataframe['wt2'] - dataframe['wt1'] >= 0
        dataframe['crossed_above'] = qtpylib.crossed_above(
            dataframe['wt2'], dataframe['wt1'])
        dataframe['crossed_below'] = qtpylib.crossed_below(
            dataframe['wt2'], dataframe['wt1'])

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

        dataframe['ema8'] = ta.EMA(dataframe, timeperiod=8)
        dataframe['ema14'] = ta.EMA(dataframe, timeperiod=14)
        dataframe['ema50'] = ta.EMA(dataframe, timeperiod=50)

        dataframe['atr'] = ta.ATR(dataframe, timeperiod=14)

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

        #StochRSI
        period = 14
        smoothD = 3
        SmoothK = 3
        stochrsi = (dataframe['rsi'] - dataframe['rsi'].rolling(period).min()
                    ) / (dataframe['rsi'].rolling(period).max() -
                         dataframe['rsi'].rolling(period).min())
        dataframe['srsi_k'] = stochrsi.rolling(SmoothK).mean() * 100
        dataframe['srsi_d'] = dataframe['srsi_k'].rolling(smoothD).mean()

        dataframe.loc[
            (dataframe['ema8'] > dataframe['ema14']) &
            (dataframe['ema14'] > dataframe['ema50'])
            & qtpylib.crossed_above(dataframe['srsi_k'], dataframe['srsi_d']),
            'go_long'] = 1
        dataframe['go_long'].fillna(0, inplace=True)

        dataframe.loc[
            qtpylib.crossed_above(dataframe['go_long'], 0),
            'take_profit'] = dataframe['close'] + dataframe['atr'] * 2
        dataframe['take_profit'].fillna(method='ffill', inplace=True)

        dataframe.loc[qtpylib.crossed_above(dataframe['go_long'], 0),
                      'stop_loss'] = dataframe['close'] - dataframe['atr'] * 3
        dataframe['stop_loss'].fillna(method='ffill', inplace=True)

        dataframe.loc[qtpylib.crossed_above(dataframe['go_long'], 0),
                      'stop_pct'] = (dataframe['atr'] * 3) / dataframe['close']
        dataframe['stop_pct'].fillna(method='ffill', inplace=True)

        # add indicator mapped to correct DatetimeIndex to custom_info
        self.custom_info[metadata['pair']] = dataframe[[
            'date', 'stop_pct', 'take_profit'
        ]].copy().set_index('date')

        return dataframe
Example #29
0
    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:

        dataframe['ema3'] = ta.EMA(dataframe, timeperiod=3)
        dataframe['ema5'] = ta.EMA(dataframe, timeperiod=5)
        dataframe['ema10'] = ta.EMA(dataframe, timeperiod=10)


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

        ichimoku = ftt.ichimoku(dataframe, 
            conversion_line_period=20, 
            base_line_periods=60,
            laggin_span=120, 
            displacement=30
            )

        # cross indicators
        dataframe['tenkan_sen'] = ichimoku['tenkan_sen']
        dataframe['kijun_sen'] = ichimoku['kijun_sen']

        # cloud, green a > b, red a < b
        dataframe['senkou_a'] = ichimoku['senkou_span_a']
        dataframe['senkou_b'] = ichimoku['senkou_span_b']
        # dataframe['leading_senkou_span_a'] = ichimoku['leading_senkou_span_a']
        # dataframe['leading_senkou_span_b'] = ichimoku['leading_senkou_span_b']
        dataframe['cloud_green'] = ichimoku['cloud_green'] * 1
        dataframe['cloud_red'] = ichimoku['cloud_red'] * -1

        dataframe['cloud_green_strong'] = (
                dataframe['cloud_green'] & 
                (dataframe['tenkan_sen'] > dataframe['kijun_sen']) &
                (dataframe['kijun_sen'] > dataframe['senkou_a'])
            ).astype('int') * 2

        dataframe['cloud_red_strong'] = (
                dataframe['cloud_red'] & 
                (dataframe['tenkan_sen'] < dataframe['kijun_sen']) &
                (dataframe['kijun_sen'] < dataframe['senkou_b'])
            ).astype('int') * -2

        dataframe.loc[
            qtpylib.crossed_above(dataframe['tenkan_sen'], dataframe['kijun_sen']),
            'tk_cross_up'] = 3
        dataframe['tk_cross_up'].fillna(method='ffill', inplace=True, limit=2)
        dataframe['tk_cross_up'].fillna(value=0, inplace=True)

        # dataframe['rsi_ok'] = (dataframe['rsi'] < 75).astype('int')
        dataframe['ema35_ok'] = (
            (dataframe['ema3'] > dataframe['ema5']) &
            (dataframe['ema5'] > dataframe['ema10'])
            ).astype('int')

        dataframe['spike'] = (
            (dataframe['close'] > (dataframe['close'].shift(3) * (1 - self.stoploss * 0.9)))
            ).astype('int')

        dataframe['recent_high'] = dataframe['high'].rolling(12).max()

        return dataframe
Example #30
0
 def populate_buy_trend(self, dataframe: DataFrame) -> DataFrame:
     dataframe.loc[(
         ((dataframe['open'] < dataframe['ema_low']) &
          (dataframe['adx'] > 30) & (dataframe['mfi'] < 30) &
          ((dataframe['fastk'] < 30) & (dataframe['fastd'] < 30) &
           (qtpylib.crossed_above(dataframe['fastk'], dataframe['fastd'])))
          & (dataframe['cci'] < -150))), 'buy'] = 1
     return dataframe
Example #31
0
def populate_sell_trend(dataframe: DataFrame) -> DataFrame:
    """
    Based on TA indicators, populates the sell signal for the given dataframe
    :param dataframe: DataFrame
    :return: DataFrame with buy column
    """
    dataframe.loc[
        (
            (
                (qtpylib.crossed_above(dataframe['rsi'], 70)) |
                (qtpylib.crossed_above(dataframe['fastd'], 70))
            ) &
            (dataframe['adx'] > 10) &
            (dataframe['minus_di'] > 0)
        ) |
        (
            (dataframe['adx'] > 70) &
            (dataframe['minus_di'] > 0.5)
        ),
        'sell'] = 1
    return dataframe
Example #32
0
    def populate_buy_trend(dataframe: DataFrame) -> DataFrame:
        conditions = []
        # GUARDS AND TRENDS
        if params['uptrend_long_ema']['enabled']:
            conditions.append(dataframe['ema50'] > dataframe['ema100'])
        if params['uptrend_short_ema']['enabled']:
            conditions.append(dataframe['ema5'] > dataframe['ema10'])
        if params['mfi']['enabled']:
            conditions.append(dataframe['mfi'] < params['mfi']['value'])
        if params['fastd']['enabled']:
            conditions.append(dataframe['fastd'] < params['fastd']['value'])
        if params['adx']['enabled']:
            conditions.append(dataframe['adx'] > params['adx']['value'])
        if params['rsi']['enabled']:
            conditions.append(dataframe['rsi'] < params['rsi']['value'])
        if params['over_sar']['enabled']:
            conditions.append(dataframe['close'] > dataframe['sar'])
        if params['green_candle']['enabled']:
            conditions.append(dataframe['close'] > dataframe['open'])
        if params['uptrend_sma']['enabled']:
            prevsma = dataframe['sma'].shift(1)
            conditions.append(dataframe['sma'] > prevsma)

        # TRIGGERS
        triggers = {
            'lower_bb': dataframe['tema'] <= dataframe['blower'],
            'faststoch10': (crossed_above(dataframe['fastd'], 10.0)),
            'ao_cross_zero': (crossed_above(dataframe['ao'], 0.0)),
            'ema5_cross_ema10': (crossed_above(dataframe['ema5'], dataframe['ema10'])),
            'macd_cross_signal': (crossed_above(dataframe['macd'], dataframe['macdsignal'])),
            'sar_reversal': (crossed_above(dataframe['close'], dataframe['sar'])),
            'stochf_cross': (crossed_above(dataframe['fastk'], dataframe['fastd'])),
            'ht_sine': (crossed_above(dataframe['htleadsine'], dataframe['htsine'])),
        }
        conditions.append(triggers.get(params['trigger']['type']))

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

        return dataframe