Skip to content

MACD with controllable MA type

MACDEXT is an extended version of MACD allowing for different MA types.

Method

tm.ta.macdext(source, fastperiod, fastmatype, slowperiod, slowmatype, signalperiod, signalmatype)

Inputs

ParameterArgument typeDescriptionDefault Value
sourcepd.SeriesInput data series-
fastperiodintFast period for the indicator12
fastmatypeintFast Moving Average type0
slowperiodintSlow period for the indicator26
slowmatypeintSlow Moving Average type0
signalperiodintSignal period for the indicator9
signalmatypeintSignal Moving Average type0

Outputs

OutputType
macdnp.ndarray
macdsignalnp.ndarray
macdhistnp.ndarray

Example usage

strategy.py
import tradomate as tm
@tm.strategy()
def my_strategy(config: tm.TradomateConfig, data: tm.TradomateData):
# Trying out MACD with controllable MA type
macd, macdsignal, macdhist = tm.ta.macdext(data.close, fastperiod=12, fastmatype=0, slowperiod=26, slowmatype=0, signalperiod=9, signalmatype=0)
# Get the last value and print
last_value = macd.iloc[-1]
tm.log(f"Last value of MACD with controllable MA type is {last_value}")
# Plot the values of macd
tm.plot(macd, title="MACD with controllable MA type", overlay=False)