Skip to content
All library documents

MACD and CCI Cross Signals for Long Entries and Exits

Code Freqtrade

Summary

This Freqtrade strategy combines MACD crossovers with Commodity Channel Index thresholds to time long trades on a five-minute chart. It enters when MACD moves above its signal line while CCI is at or below a negative threshold, and exits when MACD crosses below its signal while CCI is at or above a positive threshold.

The strategy also sets a tiered minimal return-on-investment schedule and a stop-loss, though configuration may override those values. The document provides implementation rules but no backtest, market selection, performance evidence, or rationale for the indicator periods and thresholds. The stated settings therefore describe a strategy template rather than evidence of profitability; the relatively wide configured stop and short timeframe also warrant careful testing and risk controls.

Key ideas

  • Long entry requires MACD to cross above its signal line while CCI is low.
  • Long exit requires MACD to cross below its signal line while CCI is high.
  • The strategy is configured for a five-minute timeframe.
  • ROI targets and stop-loss settings are provided but can be overridden by configuration.
  • No performance testing or asset universe is documented.

Tags

Full text
# MACDStrategy_crossed.py


```py

# --- Do not remove these libs ---
from freqtrade.strategy import IStrategy
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 MACDStrategy_crossed(IStrategy):
    """
        buy:
            MACD crosses MACD signal above
            and CCI < -50
        sell:
            MACD crosses MACD signal below
            and CCI > 100
    """

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

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

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

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

        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[
            (
                qtpylib.crossed_above(dataframe['macd'], dataframe['macdsignal']) &
                (dataframe['cci'] <= -50.0)
            ),
            '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[
            (
                qtpylib.crossed_below(dataframe['macd'], dataframe['macdsignal']) &
                (dataframe['cci'] >= 100.0)
            ),
            '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.