Skip to content

Weighted Moving Average

WMA assigns different weights to different prices, giving more importance to recent data.

Method

tm.ta.wma(source, timeperiod)

Inputs

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

Outputs

OutputType
wmanp.ndarray

Example usage

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