Skip to content

Moving average

Simple moving average is a basic tool to smooth out price fluctuations.

Method

tm.ta.ma(source, timeperiod, matype)

Inputs

ParameterArgument typeDescriptionDefault Value
sourcepd.SeriesInput data series-
timeperiodintNumber of periods for the indicator30
matypeintType of Moving Average0

Outputs

OutputType
manp.ndarray

Example usage

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