Skip to content

Simple Moving Average

SMA is a basic moving average widely used for trend analysis.

Method

tm.ta.sma(source, timeperiod)

Inputs

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

Outputs

OutputType
smanp.ndarray

Example usage

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