# Moving Average(MA)

In [statistics](https://en.wikipedia.org/wiki/Statistics), a **moving average** (**rolling average** or **running average**) is a calculation to analyze data points by creating a series of [averages](https://en.wikipedia.org/wiki/Average) of different subsets of the full data set. It is also called a **moving mean** (**MM**)[\[1\]](https://en.wikipedia.org/wiki/Moving_average#cite_note-1) or **rolling mean** and is a type of [finite impulse response](https://en.wikipedia.org/wiki/Finite_impulse_response) filter. Variations include: [simple](#simple-moving-average-sma), and [cumulative](https://en.wikipedia.org/wiki/Moving_average#Cumulative_moving_average), or [weighted](https://en.wikipedia.org/wiki/Moving_average#Weighted_moving_average) forms (described below).

Given a series of numbers and a fixed subset size, the first element of the moving average is obtained by taking the average of the initial fixed subset of the number series. Then the subset is modified by "shifting forward"; that is, excluding the first number of the series and including the next value in the subset.

#### Simple Moving Average(SMA)

In financial applications, a **simple moving average** (**SMA**) is the unweighted [mean](https://en.wikipedia.org/wiki/Arithmetic_mean) of the previous **n** data-points. However, in science and engineering, the mean is normally taken from an equal number of data on either side of a central value. This ensures that variations in the mean are aligned with the variations in the data rather than being shifted in time. An example of a simple equally weighted running mean for a **n**-day sample of the closing price is the mean of the previous **n** days' closing prices. Let those prices be ![{\displaystyle p\_{1},p\_{2},\dots ,p\_{n}}](https://wikimedia.org/api/rest_v1/media/math/render/svg/69d4afc30479593f8b2dd046bf3cb3038181e32a). Let the mean over the first **k** data-points be ![{\displaystyle {\overline {p}}\_{k}}](https://wikimedia.org/api/rest_v1/media/math/render/svg/fb60b6d8fede6beb341116cfce96b7eccd7b76f2). Thus, the mean over all the data-points is calculated as: ![{\displaystyle {\begin{aligned}{\overline {p}}\_{n}&={\frac {p\_{1}+p\_{2}+\cdots +p\_{n}}{n}}\\\\&={\frac {1}{n}}\sum \_{i=1}^{n}p\_{i}\end{aligned}}}](https://wikimedia.org/api/rest_v1/media/math/render/svg/82c3716786efc117a93ff164d1e1fcfee0437c33)

This means that the moving average filter can be computed quite cheaply on real time data with a FIFO / circular buffer.

When calculating successive values, a new value comes into the sum, and the oldest value drops out. This means that a full summation each time is unnecessary. Thus, the new mean can be calculated as:![{\displaystyle {\overline {p}}\_{n}={\overline {p}}\_{n-1}+{\frac {1}{n}}(p\_{n}-{\overline {p}}\_{n-1})}](https://wikimedia.org/api/rest_v1/media/math/render/svg/2739ed87e4a668340e0ea18add452ef7d4d1b3d4)

The period selected depends on the type of movement of interest, such as short, intermediate, or long-term. In financial terms, moving-average levels can be interpreted as [support](https://en.wikipedia.org/wiki/Support_\(technical_analysis\)) in a falling market or [resistance](https://en.wikipedia.org/wiki/Resistance_\(technical_analysis\)) in a rising market.
