Esempio n. 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
Esempio n. 2
0
def populate_indicators(dataframe: DataFrame) -> DataFrame:
    """
    Adds several different TA indicators to the given DataFrame
    """
    dataframe['sar'] = ta.SAR(dataframe)
    dataframe['adx'] = ta.ADX(dataframe)
    stoch = ta.STOCHF(dataframe)
    dataframe['fastd'] = stoch['fastd']
    dataframe['fastk'] = stoch['fastk']
    dataframe['blower'] = ta.BBANDS(dataframe, nbdevup=2,
                                    nbdevdn=2)['lowerband']
    dataframe['sma'] = ta.SMA(dataframe, timeperiod=40)
    dataframe['tema'] = ta.TEMA(dataframe, timeperiod=9)
    dataframe['mfi'] = ta.MFI(dataframe)
    dataframe['cci'] = ta.CCI(dataframe)
    dataframe['rsi'] = ta.RSI(dataframe)
    dataframe['mom'] = ta.MOM(dataframe)
    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)
    dataframe['ao'] = awesome_oscillator(dataframe)
    macd = ta.MACD(dataframe)
    dataframe['macd'] = macd['macd']
    dataframe['macdsignal'] = macd['macdsignal']
    dataframe['macdhist'] = macd['macdhist']
    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
    def do_populate_indicators(self, dataframe: DataFrame,
                               metadata: dict) -> DataFrame:
        """
        Adds multiple TA indicators to MoniGoMani's DataFrame per pair.
        Should be called with 'informative_pair' (1h candles) during backtesting/hyperopting with TimeFrame-Zoom!

        Performance Note: For the best performance be frugal on the number of indicators you are using.
        Only add in indicators that you are using in your weighted signal configuration for MoniGoMani,
        otherwise you will waste your memory and CPU usage.

        :param dataframe: (DataFrame) DataFrame with data from the exchange
        :param metadata: (dict) Additional information, like the currently traded pair
        :return DataFrame: DataFrame for MoniGoMani with all mandatory indicator data populated
        """

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

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

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

        # 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)

        # MFI - Money Flow Index (Under bought / Over sold & Over bought / Under sold / volume Indicator)
        dataframe['mfi'] = ta.MFI(dataframe)

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

        # Bollinger Bands
        bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe),
                                            window=20,
                                            stds=2)
        dataframe['bb_middleband'] = bollinger['mid']

        # SMA's & EMA's are trend following tools (Should not be used when line goes sideways)
        # SMA - Simple Moving Average (Moves slower compared to EMA, price trend over X periods)
        dataframe['sma9'] = ta.SMA(dataframe, timeperiod=9)
        dataframe['sma50'] = ta.SMA(dataframe, timeperiod=50)
        dataframe['sma200'] = ta.SMA(dataframe, timeperiod=200)

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

        # Volume Indicators
        # -----------------

        # Rolling VWAP - Volume Weighted Average Price
        dataframe['rolling_vwap'] = qtpylib.rolling_vwap(dataframe)

        return dataframe
Esempio n. 5
0
    def analyze(self,
                historical_data,
                signal=['sar'],
                hot_thresh=None,
                cold_thresh=None):
        """Performs a macd analysis on the historical data

        Args:
            historical_data (list): A matrix of historical OHCLV data.
            signal (list, optional): Defaults to macd. The indicator line to check hot/cold
                against.
            hot_thresh (float, optional): Defaults to None. The threshold at which this might be
                good to purchase.
            cold_thresh (float, optional): Defaults to None. The threshold at which this might be
                good to sell.

        Returns:
            pandas.DataFrame: A dataframe containing the indicators and hot/cold values.
        """

        dataframe = self.convert_to_dataframe(historical_data)
        sar_values = abstract.SAR(dataframe).iloc[:]
        sar_values.dropna(how='all', inplace=True)

        if sar_values[signal[0]].shape[0]:
            sar_values['is_hot'] = sar_values[signal[0]] > hot_thresh
            sar_values['is_cold'] = sar_values[signal[0]] < cold_thresh

        return sar_values
    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.
        """

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

        # 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)

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

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

        # Hammer: values [0, 100]
        dataframe['CDLHAMMER'] = ta.CDLHAMMER(dataframe)

        return dataframe
Esempio n. 7
0
def populate_indicators_and_buy_signal(dataframe):
    dataframe['ema'] = ta.EMA(dataframe, timeperiod=33)
    dataframe['sar'] = ta.SAR(dataframe, 0.02, 0.22)
    dataframe['adx'] = ta.ADX(dataframe)

    prev_sar = dataframe['sar'].shift(1)
    prev_close = dataframe['close'].shift(1)
    prev_sar2 = dataframe['sar'].shift(2)
    prev_close2 = dataframe['close'].shift(2)

    # wait for stable turn from bearish to bullish market
    dataframe.loc[(dataframe['close'] > dataframe['sar']) &
                  (prev_close > prev_sar) & (prev_close2 < prev_sar2),
                  'swap'] = 1

    # consider prices above ema to be in upswing
    dataframe.loc[dataframe['ema'] <= dataframe['close'], 'upswing'] = 1

    dataframe.loc[(dataframe['upswing'] == 1) & (dataframe['swap'] == 1) & (
        dataframe['adx'] > 25),  # adx over 25 tells there's enough momentum
                  'buy'] = 1

    dataframe.loc[dataframe['buy'] == 1, 'buy_price'] = dataframe['close']

    return dataframe, info_msg % (dataframe.iloc[-1]['ema'],
                                  dataframe.iloc[-1]['sar'],
                                  dataframe.iloc[-1]['adx'])
 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
Esempio n. 9
0
def SAR(ohlcv, kw):
    """ :return Parabolic SAR (sar) """
    params = {'acceleration': 0, 'maximum': 0}
    acceleration, maximum = _get_params(kw, params, ['acceleration', 'maximum'])
    result = talib.SAR(ohlcv, acceleration, maximum)
    return {
        'sar': result,
    }
Esempio n. 10
0
    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:

        # Misc. calculations regarding existing open positions (reset on every loop iteration)
        self.custom_trade_info[metadata['pair']] = trade_data = {}
        trade_data['active_trade'] = trade_data['other_trades'] = False

        if self.config['runmode'].value in ('live', 'dry_run'):
            
            active_trade = Trade.get_trades([Trade.pair == metadata['pair'], Trade.is_open.is_(True),]).all()
            other_trades = Trade.get_trades([Trade.pair != metadata['pair'], Trade.is_open.is_(True),]).all()

            if active_trade:
                current_rate = self.get_current_price(metadata['pair'])
                active_trade[0].adjust_min_max_rates(current_rate)
                trade_data['active_trade']   = True
                trade_data['current_profit'] = active_trade[0].calc_profit_ratio(current_rate)
                trade_data['peak_profit']    = active_trade[0].calc_profit_ratio(active_trade[0].max_rate)

            if other_trades:
                trade_data['other_trades'] = True
                total_other_profit = tuple(trade.calc_profit_ratio(self.get_current_price(trade.pair)) for trade in other_trades)
                trade_data['avg_other_profit'] = mean(total_other_profit) 

        self.custom_trade_info[metadata['pair']] = trade_data

        # Set up other indicators
        dataframe['volume_mean_slow'] = dataframe['volume'].rolling(window=24).mean()
        dataframe['rmi-slow'] = RMI(dataframe, length=20, mom=5)
        dataframe['rmi-fast'] = RMI(dataframe, length=9, mom=3)
        dataframe['sar'] = ta.SAR(dataframe)

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

        # Trend calculations
        dataframe['max'] = dataframe['high'].rolling(12).max()      
        dataframe['min'] = dataframe['low'].rolling(12).min()       
        dataframe['upper'] = np.where(dataframe['max'] > dataframe['max'].shift(),1,0)      
        dataframe['lower'] = np.where(dataframe['min'] < dataframe['min'].shift(),1,0)      
        dataframe['up_trend'] = np.where(dataframe['upper'].rolling(3, min_periods=1).sum() != 0,1,0)      
        dataframe['dn_trend'] = np.where(dataframe['lower'].rolling(3, min_periods=1).sum() != 0,1,0)

        # Informative Pair Indicators
        informative = self.dp.get_pair_dataframe(pair=metadata['pair'], timeframe=self.inf_timeframe)

        informative['ema3']   = ta.EMA(informative, timeperiod=3)
        informative['ema12']  = ta.EMA(informative, timeperiod=12)

        inf_macd = ta.MACD(informative)
        informative['macd'] = inf_macd['macd']
        informative['macdsignal'] = inf_macd['macdsignal']
        informative['macdhist'] = inf_macd['macdhist']

        dataframe = merge_informative_pair(dataframe, informative, self.timeframe, self.inf_timeframe, ffill=True)

        return dataframe
Esempio n. 11
0
    def populate_indicators(self, dataframe: DataFrame,
                            metadata: dict) -> DataFrame:

        # Set Up Bollinger Bands
        upper_bb1, mid_bb1, lower_bb1 = ta.BBANDS(dataframe['close'],
                                                  timeperiod=36)
        upper_bb2, mid_bb2, lower_bb2 = ta.BBANDS(
            qtpylib.typical_price(dataframe), timeperiod=12)

        # Only putting some bands into dataframe as the others are not used elsewhere in the strategy
        dataframe['lower-bb1'] = lower_bb1
        dataframe['lower-bb2'] = lower_bb2
        dataframe['mid-bb2'] = mid_bb2

        dataframe['bb1-delta'] = (mid_bb1 - dataframe['lower-bb1']).abs()
        dataframe['closedelta'] = (dataframe['close'] -
                                   dataframe['close'].shift()).abs()
        dataframe['tail'] = (dataframe['close'] - dataframe['low']).abs()

        # Additional indicators
        dataframe['ema_fast'] = ta.EMA(dataframe['close'], timeperiod=6)
        dataframe['ema_slow'] = ta.EMA(dataframe['close'], timeperiod=48)
        dataframe['volume_mean_slow'] = dataframe['volume'].rolling(
            window=24).mean()

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

        # 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)

        # Informative Pair Indicators
        coin, stake = metadata['pair'].split('/')
        fiat = self.fiat
        stake_fiat = f"{stake}/{self.fiat}"
        coin_fiat = f"{coin}/{self.fiat}"

        coin_fiat_inf = self.dp.get_pair_dataframe(pair=f"{coin}/{fiat}",
                                                   timeframe=self.timeframe)
        dataframe['coin-fiat-adx'] = ta.ADX(coin_fiat_inf, timeperiod=21)
        coin_aroon = ta.AROON(coin_fiat_inf, timeperiod=25)
        dataframe['coin-fiat-aroon-down'] = coin_aroon['aroondown']
        dataframe['coin-fiat-aroon-up'] = coin_aroon['aroonup']

        stake_fiat_inf = self.dp.get_pair_dataframe(pair=f"{stake}/{fiat}",
                                                    timeframe=self.timeframe)
        dataframe['stake-fiat-adx'] = ta.ADX(stake_fiat_inf, timeperiod=21)
        stake_aroon = ta.AROON(stake_fiat_inf, timeperiod=25)
        dataframe['stake-fiat-aroon-down'] = stake_aroon['aroondown']
        dataframe['stake-fiat-aroon-up'] = stake_aroon['aroonup']

        # These indicators are used to persist a buy signal in live trading only
        # They dramatically slow backtesting down
        if self.config['runmode'].value in ('live', 'dry_run'):
            dataframe['sar'] = ta.SAR(dataframe)

        return dataframe
Esempio n. 12
0
def populate_indicators(dataframe: DataFrame) -> DataFrame:
    """
    Adds several different TA indicators to the given DataFrame
    """

    # Log the dataframe
    dataframe.to_csv("dataframe.csv", sep='\t')

    #Determine Trend
    dataframe = indicators.TREND(dataframe)

    #Exponential Moving Average
    dataframe['ema'] = ta.EMA(dataframe, timeperiod=33)

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

    #Average Directional Movement Index
    dataframe['adx'] = ta.ADX(dataframe)

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

    #Relative Strength Index
    dataframe['rsi'] = ta.RSI(dataframe, 14)
    dataframe = indicators.RSI(dataframe)

    #Absolute Price Oscillator
    dataframe['apo'] = ta.APO(dataframe,
                              fastperiod=12,
                              slowperiod=26,
                              matype=0)

    #Momentum
    dataframe['mom'] = ta.MOM(dataframe, 10)

    #Bollinger Bands
    dataframe = indicators.BBANDS(20, dataframe, 2)

    # Stochcastic
    dataframe['K'] = indicators.STOK(dataframe, 14)
    dataframe['D'] = indicators.STOD(dataframe, 14)
    dataframe = indicators.STOCH(dataframe)

    # if Counter.counter < 30:
    #     print(dataframe)
    #     print (macd)
    #     print (dataframe ['adx'])
    #     Counter.counter = Counter.counter + 1

    # else:
    #     exit()

    return dataframe
Esempio n. 13
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
Esempio n. 14
0
def populate_indicators(dataframe: DataFrame) -> DataFrame:
    """
    Adds several different TA indicators to the given DataFrame
    """
    dataframe['ema'] = ta.EMA(dataframe, timeperiod=33)
    dataframe['sar'] = ta.SAR(dataframe, 0.02, 0.22)
    dataframe['adx'] = ta.ADX(dataframe)

    return dataframe
Esempio n. 15
0
 def sar(self):
     sar = tb.SAR(self.dataframe, acceleration=0, maximum=0)
     if self.dataframe['open'][len(self.dataframe) - 1] > sar[len(sar) - 1]:
         return "buy"
     elif self.dataframe['open'][len(self.dataframe) - 1] < sar[len(sar) -
                                                                1]:
         return "sell"
     else:
         return "neutral"
Esempio n. 16
0
    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:

        # Misc calculations regarding existing open positions
        self.custom_trade_info[metadata['pair']] = trade_data = {}
        trade_data['active_trade'] = trade_data['other_trades'] = False

        if self.config['runmode'].value in ('live', 'dry_run'):
            
            active_trade = Trade.get_trades([Trade.pair == metadata['pair'], Trade.is_open.is_(True),]).all()
            other_trades = Trade.get_trades([Trade.pair != metadata['pair'], Trade.is_open.is_(True),]).all()

            if active_trade:
                trade_data['active_trade'] = True
                trade_data['current_profit'] = active_trade[0].calc_profit_ratio(rate=self.get_current_price(metadata['pair']))
                trade_data['peak_profit']    = active_trade[0].calc_profit_ratio(rate=active_trade[0].max_rate)
                trade_data['current_peak_ratio'] = (trade_data['current_profit'] / trade_data['peak_profit'])

            if other_trades:
                trade_data['other_trades'] = True
                total_other_profit = sum(trade.calc_profit_ratio(rate=self.get_current_price(trade.pair)) for trade in other_trades)
                trade_data['avg_other_profit'] = total_other_profit / len(other_trades)

        self.custom_trade_info[metadata['pair']] = trade_data

        # Set up other indicators
        dataframe['volume_mean_slow'] = dataframe['volume'].rolling(window=24).mean()
        dataframe['rmi-slow'] = RMI(dataframe, length=20, mom=5)
        dataframe['rmi-fast'] = RMI(dataframe, length=9, mom=3)
        dataframe['sar'] = ta.SAR(dataframe)

        # Trend calculations
        dataframe['max'] = dataframe['high'].rolling(12).max()      
        dataframe['min'] = dataframe['low'].rolling(12).min()       
        dataframe['upper'] = np.where(dataframe['max'] > dataframe['max'].shift(),1,0)      
        dataframe['lower'] = np.where(dataframe['min'] < dataframe['min'].shift(),1,0)      
        dataframe['up_trend'] = np.where(dataframe['upper'].rolling(3, min_periods=1).sum() != 0,1,0)      
        dataframe['dn_trend'] = np.where(dataframe['lower'].rolling(3, min_periods=1).sum() != 0,1,0)

        # Consensus dashboard based on default timeframe and informative pair
        # Example: https://www.tradingview.com/symbols/BTCUSD/technicals/
        # Code: https://github.com/freqtrade/technical/blob/master/technical/tradingview/__init__.py

        consensus = tv.SummaryConsensus(dataframe).score()
        dataframe['tv-consensus-sell'] = consensus['sell_agreement']
        dataframe['tv-consensus-buy']  = consensus['buy_agreement']

        informative = self.dp.get_pair_dataframe(pair=metadata['pair'], timeframe=self.inf_timeframe)
        consensus_inf = tv.SummaryConsensus(informative).score()
        informative['tv-consensus-sell'] = consensus_inf['sell_agreement']
        informative['tv-consensus-buy']  = consensus_inf['buy_agreement']

        dataframe = merge_informative_pair(dataframe, informative, self.timeframe, self.inf_timeframe, ffill=True)

        # dataframe.to_csv('user_data/foo.csv')

        return dataframe
    def populate_indicators(self, dataframe: DataFrame,
                            metadata: dict) -> DataFrame:
        dataframe['sar'] = ta.SAR(dataframe)
        if self.dp.runmode.value in ('backtest', 'hyperopt'):
            self.custom_info[metadata['pair']] = dataframe[[
                'date', 'sar'
            ]].copy().set_index('date')

        # all "normal" indicators:
        # e.g.
        # dataframe['rsi'] = ta.RSI(dataframe)
        return dataframe
Esempio n. 18
0
 def SAR(self):
     SAR = tb.SAR(self.dataframe, acceleration=0, maximum=0)
     if (self.dataframe['open'][len(self.dataframe) - 1] >
             SAR[len(SAR) - 1]):
         #print("SAR: buy")
         return "buy"
     elif (self.dataframe['open'][len(self.dataframe) - 1] <
           SAR[len(SAR) - 1]):
         #print("SAR: sell")
         return "sell"
     else:
         #print("SAR: neutral")
         return "neutral"
Esempio n. 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.
     :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
     # ------------------------------------
     dataframe['rsi'] = ta.RSI(dataframe)
     # # Stochastic RSI
     stoch_rsi = ta.STOCHRSI(dataframe)
     # dataframe['fastd_rsi'] = stoch_rsi['fastd']
     dataframe['fastk_rsi'] = stoch_rsi['fastk']
     # # 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)
     # MACD
     macd = ta.MACD(dataframe)
     dataframe['macd'] = macd['macd']
     # dataframe['macdsignal'] = macd['macdsignal']
     # dataframe['macdhist'] = macd['macdhist']
      # Parabolic SAR
     dataframe['sar'] = ta.SAR(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']
     # 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"]
     # )
     return dataframe
    def populate_indicators(self, dataframe: DataFrame,
                            metadata: dict) -> DataFrame:

        dataframe['ohlc4'] = ta.AVGPRICE(dataframe)
        dataframe['hlc3'] = (dataframe['high'] + dataframe['low'] +
                             dataframe['close']) / 3
        dataframe['hl2'] = (dataframe['high'] + dataframe['low']) / 2

        dataframe['atr'] = ta.ATR(dataframe, timeperiod=10)
        dataframe['sar'] = ta.SAR(dataframe)

        dataframe = supertrend(dataframe, multiplier=1)

        return dataframe
Esempio n. 21
0
def populate_indicators(dataframe: DataFrame) -> DataFrame:
    """
    Adds several different TA indicators to the given DataFrame
    """
    dataframe['sar'] = ta.SAR(dataframe)
    dataframe['adx'] = ta.ADX(dataframe)
    stoch = ta.STOCHF(dataframe)
    dataframe['fastd'] = stoch['fastd']
    dataframe['fastk'] = stoch['fastk']
    dataframe['blower'] = ta.BBANDS(dataframe, nbdevup=2, nbdevdn=2)['lowerband']
    dataframe['sma'] = ta.SMA(dataframe, timeperiod=40)
    dataframe['tema'] = ta.TEMA(dataframe, timeperiod=9)
    dataframe['mfi'] = ta.MFI(dataframe)
    dataframe['cci'] = ta.CCI(dataframe)
    return dataframe
Esempio n. 22
0
    def populate_indicators(self, dataframe, metadata):
        stoch = ta.STOCH(dataframe)
        rsi = ta.RSI(dataframe)
        bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe))

        dataframe["slowk"] = stoch["slowk"]
        dataframe["rsi"] = rsi

        rsi = 0.1 * (rsi - 50)
        dataframe["fisher"] = (np.exp(2 * rsi) - 1) / (np.exp(2 * rsi) + 1)
        dataframe["bb_lowerband"] = bollinger["lower"]
        dataframe["sar"] = ta.SAR(dataframe)
        dataframe["CDLHAMMER"] = ta.CDLHAMMER(dataframe)

        return dataframe
Esempio n. 23
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
Esempio n. 24
0
    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:        

        dataframe['sar'] = ta.SAR(dataframe)
        dataframe['rmi'] = RMI(dataframe)
        dataframe['kama-3'] = ta.KAMA(dataframe, timeperiod=3)
        dataframe['kama-21'] = ta.KAMA(dataframe, timeperiod=21)

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

        dataframe['volume_ma'] = dataframe['volume'].rolling(window=24).mean()

        
        return dataframe
Esempio n. 25
0
def get_ticker_dataframe(pair: str) -> DataFrame:
    """
    Analyses the trend for the given pair
    :param pair: pair as str in format BTC_ETH or BTC-ETH
    :return: DataFrame
    """
    minimum_date = arrow.now() - timedelta(hours=6)
    url = 'https://bittrex.com/Api/v2.0/pub/market/GetTicks'
    headers = {
        'User-Agent':
        'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36',
    }
    params = {
        'marketName': pair.replace('_', '-'),
        'tickInterval': 'OneMin',
        '_': minimum_date.timestamp * 1000
    }
    data = requests.get(url, params=params, headers=headers).json()
    if not data['success']:
        raise RuntimeError('BITTREX: {}'.format(data['message']))

    data = [{
        'close': t['C'],
        'volume': t['V'],
        'open': t['O'],
        'high': t['H'],
        'low': t['L'],
        'date': t['T'],
    } for t in sorted(data['result'], key=lambda k: k['T'])
            if arrow.get(t['T']) > minimum_date]
    dataframe = DataFrame(json_normalize(data))

    dataframe['close_30_ema'] = ta.EMA(dataframe, timeperiod=30)
    dataframe['close_90_ema'] = ta.EMA(dataframe, timeperiod=90)

    dataframe['sar'] = ta.SAR(dataframe, 0.02, 0.2)

    # calculate StochRSI
    stochrsi = ta.STOCHRSI(dataframe)
    dataframe['stochrsi'] = stochrsi['fastd']  # values between 0-100, not 0-1

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

    return dataframe
Esempio n. 26
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 Indicators
     # ------------------------------------
     dataframe['adx'] = ta.ADX(dataframe)
     dataframe['sar'] = ta.SAR(dataframe)
     # RSI
     dataframe['rsi'] = ta.RSI(dataframe)
     dataframe['mfi'] = ta.MFI(dataframe)
     stoch_fast = ta.STOCHF(dataframe)
     dataframe['fastd'] = stoch_fast['fastd']
     # Bollinger Bands 1 STD
     bollinger1 = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe),
                                          window=20,
                                          stds=1)
     dataframe['bb_lowerband1'] = bollinger1['lower']
     # dataframe['bb_middleband1'] = bollinger1['mid']
     # dataframe['bb_upperband1'] = bollinger1['upper']
     # bollinger2 = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=2)
     # dataframe['bb_lowerband2'] = bollinger2['lower']
     # dataframe['bb_middleband2'] = bollinger2['mid']
     # dataframe['bb_upperband2'] = bollinger2['upper']
     # bollinger3 = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=3)
     # dataframe['bb_lowerband3'] = bollinger3['lower']
     # dataframe['bb_middleband3'] = bollinger3['mid']
     # dataframe['bb_upperband3'] = bollinger3['upper']
     # Bollinger Bands 4 STD
     bollinger4 = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe),
                                          window=20,
                                          stds=4)
     dataframe['bb_lowerband4'] = bollinger4['lower']
     # dataframe['bb_middleband4'] = bollinger4['mid']
     # dataframe['bb_upperband4'] = bollinger4['upper']
     macd = ta.MACD(dataframe)
     dataframe['macd'] = macd['macd']
     dataframe['macdsignal'] = macd['macdsignal']
     return dataframe
Esempio n. 27
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.
        """

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

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

        # 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)

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

        # EMA - Exponential Moving Average
        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)

        return dataframe
    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        dataframe['volume_mean_slow'] = dataframe['volume'].rolling(window=24).mean()

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

        dataframe['max'] = dataframe['high'].rolling(60).max()      

        dataframe['min'] = dataframe['low'].rolling(60).min()       

        dataframe['upper'] = np.where(dataframe['max'] > dataframe['max'].shift(),1,0)      

        dataframe['lower'] = np.where(dataframe['min'] < dataframe['min'].shift(),1,0)      

        dataframe['up_trend'] = np.where(dataframe['upper'].rolling(10, min_periods=1).sum() != 0,1,0)      

        dataframe['dn_trend'] = np.where(dataframe['lower'].rolling(10, min_periods=1).sum() != 0,1,0)

        return dataframe
Esempio n. 29
0
def populate_indicators(dataframe: DataFrame) -> DataFrame:
    """
    Adds several different TA indicators to the given DataFrame
    """
    dataframe['close_30_ema'] = ta.EMA(dataframe, timeperiod=30)
    dataframe['close_90_ema'] = ta.EMA(dataframe, timeperiod=90)

    dataframe['sar'] = ta.SAR(dataframe, 0.02, 0.2)

    # calculate StochRSI
    stochrsi = ta.STOCHRSI(dataframe)
    dataframe['stochrsi'] = stochrsi['fastd']  # values between 0-100, not 0-1

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

    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