Skip to content
All library documents

MACD Zero-Line and Signal-Line Rules for Trend Entries

Article Strategy library · Author: berlinguyinca

Summary

This simple MACD strategy defines a bullish condition as MACD above both zero and its signal line. It enters long when both conditions hold and signals an exit when MACD falls below the signal line. Although the accompanying description names a bearish condition below zero and below the signal, the implemented entry rule is long-only; it does not open a short position. The strategy uses MACD and its signal and histogram series, with five-minute candles.

The source also sets return targets at different holding times and a stop-loss, though those controls may be overridden by configuration. No backtest settings, performance figures, or evidence of profitability are supplied. The rules are therefore a compact indicator example rather than a validated trading system. MACD crossovers can lag price moves, and the document does not explain how the thresholds, risk settings, or market selection were evaluated. Traders would need to assess costs, signal behavior, and risk independently before drawing conclusions.

Key ideas

  • A bullish MACD condition requires MACD to be positive and above its signal line.
  • The coded entry is long-only, despite a textual definition of a bearish trend.
  • A fall of MACD below its signal line triggers the stated exit condition.
  • The source sets holding-time return targets and a stop-loss, which configuration may override.
  • No backtest outcomes or profitability evidence are provided.

Tags

Full text
# ASDTSRockwellTrading


# ASDTSRockwellTrading









trading strategy based on the concept explained at https://www.youtube.com/watch?v=mmAWVmKN4J0
    author@: Gert Wohlgemuth

    idea:

        uptrend definition:
            MACD above 0 line AND above MACD signal


        downtrend definition:
            MACD below 0 line and below MACD signal

        sell definition:
            MACD below MACD signal

    it's basically a very simple MACD based strategy and we ignore the definition of the entry and exit points in this case, since the trading bot, will take of this already

## 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 ASDTSRockwellTrading(IStrategy):
    """
    trading strategy based on the concept explained at https://www.youtube.com/watch?v=mmAWVmKN4J0
    author@: Gert Wohlgemuth

    idea:

        uptrend definition:
            MACD above 0 line AND above MACD signal


        downtrend definition:
            MACD below 0 line and below MACD signal

        sell definition:
            MACD below MACD signal

    it's basically a very simple MACD based strategy and we ignore the definition of the entry and exit points in this case, since the trading bot, will take of this already

    """

    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']

        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['macd'] > 0) &
                (dataframe['macd'] > dataframe['macdsignal'])
            ),
            '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['macd'] < dataframe['macdsignal'])
            ),
            '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.