Skip to content

MACD #

MACD #

MACD(
    fast_period: int,
    slow_period: int,
    signal_period: int,
    input_values: List[float] = None,
    input_indicator: Indicator = None,
    input_modifier: InputModifierType = None,
    ma_type: MAType = MAType.EMA,
    input_sampling: SamplingPeriodType = None,
)

Bases: Indicator

Moving Average Convergence Divergence.

Input type: float

Output type: MACDVal

Parameters:

Name Type Description Default
fast_period int

Fast moving average period.

required
slow_period int

Slow moving average period.

required
signal_period int

Signal line moving average period.

required
input_values List[float]

List of input values.

None
input_indicator Indicator

Input indicator.

None
input_modifier InputModifierType

Input modifier.

None
ma_type MAType

Moving average type.

EMA
input_sampling SamplingPeriodType

Input sampling type.

None
Source code in talipp/indicators/MACD.py
def __init__(self, fast_period: int,
             slow_period: int,
             signal_period: int,
             input_values: List[float] = None,
             input_indicator: Indicator = None,
             input_modifier: InputModifierType = None,
             ma_type: MAType = MAType.EMA,
             input_sampling: SamplingPeriodType = None):
    super().__init__(input_modifier=input_modifier,
                     output_value_type=MACDVal,
                     input_sampling=input_sampling)

    self.ma_fast = MAFactory.get_ma(ma_type, fast_period)
    self.ma_slow = MAFactory.get_ma(ma_type, slow_period)
    self.signal_line = MAFactory.get_ma(ma_type, signal_period)

    self.add_sub_indicator(self.ma_fast)
    self.add_sub_indicator(self.ma_slow)
    self.add_managed_sequence(self.signal_line)

    self.initialize(input_values, input_indicator)

MACDVal dataclass #

MACDVal(
    macd: float = None,
    signal: float = None,
    histogram: float = None,
)

MACD output type.

Parameters:

Name Type Description Default
macd float

MACD value.

None
signal float

Signal line.

None
histogram float

Histogram.

None