Type/to search
Built-in Functions
Global
Log
Market
Trade
Account
Futures
Exchange
IO
Network
Storage
Threads
TA
Talib
Overlap Studies
talib.ACCBANDS
talib.BBANDS
talib.DEMA
talib.EMA
talib.HT_TRENDLINE
talib.KAMA
talib.MA
talib.MAMA
talib.MAVP
talib.MIDPOINT
talib.MIDPRICE
talib.SAR
talib.SAREXT
talib.SMA
talib.T3
talib.TEMA
talib.TRIMA
talib.WMA
Momentum Indicators
Volume Indicators
Volatility Indicators
Cycle Indicators
Price Transform
Statistic Functions
Math Transform
Math Operators
Pattern Recognition
OS
Structures
Built-in Variables and Constants
Conventions
Exchanges

Calculates the Moving Average with Variable Period.

talib.MAVP(inReal, inPeriods)
talib.MAVP(inReal, inPeriods, optInMinPeriod)
talib.MAVP(inReal, inPeriods, optInMinPeriod, optInMaxPeriod)
talib.MAVP(inReal, inPeriods, optInMinPeriod, optInMaxPeriod, optInMAType)

Examples

Compute a variable-period average using 10 for up bars and 20 for down bars.

javascript
function main() { var records = exchange.GetRecords() if (!records) return var closes = records.map(function(r) { return r.Close }) // period per bar: 10 for up bars, 20 for down bars (for illustration only) var periods = records.map(function(r) { return r.Close > r.Open ? 10 : 20 }) var ret = talib.MAVP(closes, periods, 10, 20) Log(ret) }
python
import talib import numpy as np def main(): records = exchange.GetRecords() if not records: return # period per bar: 10 for up bars, 20 for down bars (for illustration only) periods = np.array([10.0 if r["Close"] > r["Open"] else 20.0 for r in records]) ret = talib.MAVP(records.Close, periods, 10, 20) Log(ret)

Returns

TypeDescription

numeric array

Indicator values, the same length as the input; the leading values without enough data are NaN.

Arguments

NameTypeRequiredDescription

inReal

numeric array

Yes

Series to average.

inPeriods

numeric array

Yes

Period used for each bar; it must have the same length as inReal. Values outside [optInMinPeriod, optInMaxPeriod] are clamped to the bounds.

optInMinPeriod

number

No

Minimum period. Default 2.

optInMaxPeriod

number

No

Maximum period. Default 30.

optInMAType

number

No

Moving average type; see the MAType table on the Talib page. Default 0 (SMA).

See Also

Remarks

TA-Lib equivalent: MAVP(Array(inReal),Array(inPeriods),Min Period = 2,Max Period = 30,MA Type = 0) = Array(outReal).

The i-th value is the moving average of inReal up to element i with period inPeriods[i]; the first optInMaxPeriod - 1 values are NaN (regardless of the actual values in inPeriods).

Both inputs must be numeric arrays: in JavaScript, extract a field from the K-line data with map first; if a K-line array is passed, both inputs take the close price of the same K-line data and the result is meaningless; arrays of different lengths raise an error. In Python, both inputs must be numpy arrays of type float64.