In technical analysis (TA), a Smoothed Moving Average (SMA) is a popular trend-following indicator used to smooth out price data and identify the direction of a trend more effectively. Unlike the Simple Moving Average (SMA), which gives equal weight to all data points in the calculation period, the Smoothed Moving Average assigns a higher weight to more recent data points. This makes the Smoothed Moving Average less responsive to short-term price fluctuations and more reflective of the overall trend.
The formula for calculating a Smoothed Moving Average is:
SMA=(Previous SMA × (n−1))+Current ClosenSMA = \frac{(Previous \: SMA \: \times \: (n - 1)) + Current \: Close}{n}
Where:
- SMASMA is the smoothed moving average
- Previous SMAPrevious \: SMA is the smoothed moving average of the previous period
- Current CloseCurrent \: Close is the closing price of the current period
- nn is the smoothing period (the number of periods over which the smoothing is applied)
To calculate the initial smoothed moving average, you would typically use a simple moving average over the first nn periods, and then apply the smoothing formula for subsequent periods.
Here's a simple Python function to calculate the Smoothed Moving Average:
def smoothed_moving_average(data, n):
sma = sum(data[:n]) / n
smoothed_values = [sma]
for i in range(n, len(data)):
sma = (sma * (n - 1) + data[i]) / n
smoothed_values.append(sma)
return smoothed_values
In this function:
data
is a list of historical prices.n
is the smoothing period.
You can then use the smoothed_moving_average
function to calculate the smoothed moving average for a given dataset and smoothing period.