Moving average
Simple moving average is a basic tool to smooth out price fluctuations.
Method
tm.ta.ma(source, timeperiod, matype)
Inputs
Parameter | Argument type | Description | Default Value |
---|---|---|---|
source | pd.Series | Input data series | - |
timeperiod | int | Number of periods for the indicator | 30 |
matype | int | Type of Moving Average | 0 |
Outputs
Output | Type |
---|---|
ma | np.ndarray |
Example usage
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)