MACD Crossovers Filtered by CCI for Five-Minute Long Trades
Summary
This five-minute strategy combines MACD crossovers with the Commodity Channel Index (CCI) to time long entries and exits. It opens a long position when MACD crosses above its signal line while CCI is at or below -50. It signals an exit when MACD crosses below its signal line while CCI is at or above 100. The code calculates MACD and CCI from market data and uses those paired conditions for its signals.
The strategy also specifies a tiered minimal return-on-investment schedule and a stop-loss of -30%, though these settings can be overridden by configuration. The document provides no market, backtest period, or performance results, so it does not establish whether the combined signals work reliably. It describes long-side entries and exits only; it gives no short-entry rule or explanation of position sizing. The thresholds and risk settings are presented as implementation choices rather than supported findings.
Key ideas
- A long entry requires MACD to cross above its signal line while CCI is at or below -50.
- A long exit requires MACD to cross below its signal line while CCI is at or above 100.
- The strategy uses a five-minute timeframe and includes configurable return targets and a -30% stop-loss.
- No backtest evidence or performance results are provided.
Tags
Full text
# MACDStrategy_crossed
# MACDStrategy_crossed
buy:
MACD crosses MACD signal above
and CCI < -50
sell:
MACD crosses MACD signal below
and CCI > 100
## Source (GPL-3.0)
```python
# --- 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.