Moving average with variable period
MAVP adjusts the moving average period dynamically.
Method
tm.ta.mavp(source_close, source_timeperiod, minperiod, maxperiod, matype)
Inputs
Parameter | Argument type | Description | Default Value |
---|---|---|---|
source_close | pd.Series | Close prices series | - |
source_timeperiod | pd.Series | Time period for source series | - |
minperiod | int | Minimum period for the indicator | 2 |
maxperiod | int | Maximum period for the indicator | 30 |
matype | int | Type of Moving Average | 0 |
Outputs
Output | Type |
---|---|
mavp | np.ndarray |
Example usage
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)