Skip to content
All library documents

Using a 15-Minute Bitcoin Pair to Filter Crypto Entries

Code Freqtrade

Summary

This Freqtrade example shows how to combine a traded pair’s short-term trend with a higher-timeframe Bitcoin reference. It requests BTC/USDT candles at 15-minute intervals, calculates a 20-period simple moving average on that data, and merges the informative columns into the strategy’s 5-minute dataframe. Entry signals require the traded pair’s 20-period EMA to exceed its 50-period EMA and the informative close to be above its moving average; exit signals use the opposite comparisons.

The code also specifies ROI thresholds, a fixed stop loss, limit entry and exit orders, and disables trailing stops. It is presented as an implementation example, and its own description cautions that the strategy performs poorly. No backtest results or evidence of profitability are provided. The example’s comments describe the reference as stake currency versus USDT, but the actual informative pair is BTC/USDT, so its filter reflects Bitcoin conditions rather than each traded asset’s quote conversion. Traders should validate the signal and data alignment for their own markets and configuration.

Key ideas

  • The strategy combines 5-minute signals with 15-minute BTC/USDT data.
  • It merges Bitcoin’s 20-period simple moving average and close into the traded pair’s dataframe.
  • Long entries require the traded pair’s 20-period EMA above its 50-period EMA and Bitcoin above its informative moving average.
  • Exit signals require both comparisons to reverse.
  • The example reports no performance evidence and cautions that it performs poorly.

Tags

Full text
# InformativeSample.py


```py

# --- Do not remove these libs ---
from freqtrade.strategy import IStrategy, merge_informative_pair
from typing import Dict, List
from functools import reduce
from pandas import DataFrame
# --------------------------------

import talib.abstract as ta
import freqtrade.vendor.qtpylib.indicators as qtpylib


class InformativeSample(IStrategy):
    """
    Sample strategy implementing Informative Pairs - compares stake_currency with USDT.
    Not performing very well - but should serve as an example how to use a referential pair against USDT.
    author@: xmatthias
    github@: https://github.com/freqtrade/freqtrade-strategies

    How to use it?
    > python3 freqtrade -s InformativeSample
    """

    INTERFACE_VERSION: int = 3
    # Minimal ROI designed for the strategy.
    # This attribute will be overridden if the config file contains "minimal_roi"
    minimal_roi = {
        "60":  0.01,
        "30":  0.03,
        "20":  0.04,
        "0":  0.05
    }

    # Optimal stoploss designed for the strategy
    # This attribute will be overridden if the config file contains "stoploss"
    stoploss = -0.10

    # Optimal timeframe for the strategy
    timeframe = '5m'

    # trailing stoploss
    trailing_stop = False
    trailing_stop_positive = 0.02
    trailing_stop_positive_offset = 0.04

    # run "populate_indicators" only for new candle
    process_only_new_candles = True

    # Experimental settings (configuration will overide these if set)
    use_exit_signal = True
    exit_profit_only = True
    ignore_roi_if_entry_signal = False

    # Optional order type mapping
    order_types = {
        'entry': 'limit',
        'exit': 'limit',
        'stoploss': 'market',
        'stoploss_on_exchange': False
    }

    def informative_pairs(self):
        """
        Define additional, informative pair/interval combinations to be cached from the exchange.
        These pair/interval combinations are non-tradeable, unless they are part
        of the whitelist as well.
        For more information, please consult the documentation
        :return: List of tuples in the format (pair, interval)
            Sample: return [("ETH/USDT", "5m"),
                            ("BTC/USDT", "15m"),
                            ]
        """
        return [(f"BTC/USDT", '15m')]

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

        dataframe['ema20'] = ta.EMA(dataframe, timeperiod=20)
        dataframe['ema50'] = ta.EMA(dataframe, timeperiod=50)
        dataframe['ema100'] = ta.EMA(dataframe, timeperiod=100)
        if self.dp:
            # Get ohlcv data for informative pair at 15m interval.
            inf_tf = '15m'
            informative = self.dp.get_pair_dataframe(pair=f"BTC/USDT",
                                                     timeframe=inf_tf)

            # calculate SMA20 on informative pair
            informative['sma20'] = informative['close'].rolling(20).mean()

            # Combine the 2 dataframe
            # This will result in a column named 'closeETH' or 'closeBTC' - depending on stake_currency.
            dataframe = merge_informative_pair(dataframe, informative,
                                               self.timeframe, inf_tf, ffill=True)

        return dataframe

    def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        """
        Based on TA indicators, populates the buy signal for the given dataframe
        :param dataframe: DataFrame
        :return: DataFrame with buy column
        """
        dataframe.loc[
            (
                (dataframe['ema20'] > dataframe['ema50']) &
                # stake/USDT above sma(stake/USDT, 20)
                (dataframe['close_15m'] > dataframe['sma20_15m'])
            ),
            'enter_long'] = 1

        return dataframe

    def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        """
        Based on TA indicators, populates the sell signal for the given dataframe
        :param dataframe: DataFrame
        :return: DataFrame with buy column
        """
        dataframe.loc[
            (
                (dataframe['ema20'] < dataframe['ema50']) &
                # stake/USDT below sma(stake/USDT, 20)
                (dataframe['close_15m'] < dataframe['sma20_15m'])
            ),
            'exit_long'] = 1
        return dataframe

```

Shown in full with attribution under the source's licence. Licence: GPL-3.0

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.