Skip to content

Moving average with variable period

MAVP adjusts the moving average period dynamically.

Method

tm.ta.mavp(source_close, source_timeperiod, minperiod, maxperiod, matype)

Inputs

ParameterArgument typeDescriptionDefault Value
source_closepd.SeriesClose prices series-
source_timeperiodpd.SeriesTime period for source series-
minperiodintMinimum period for the indicator2
maxperiodintMaximum period for the indicator30
matypeintType of Moving Average0

Outputs

OutputType
mavpnp.ndarray

Example usage

strategy.py
import tradomate as tm
@tm.strategy()
def my_strategy(config: tm.TradomateConfig, data: tm.TradomateData):
# Trying out Moving average with variable period
mavp = tm.ta.mavp(data.close, data.timeperiod, minperiod=2, maxperiod=30, matype=0)
# Get the last value and print
last_value = mavp.iloc[-1]
tm.log(f"Last value of Moving average with variable period is {last_value}")
# Plot the values of mavp
tm.plot(mavp, title="Moving average with variable period", overlay=False)