Calculating A Simple Moving Average
Quick answer
- A Simple Moving Average (SMA) smooths out price data to show the average price over a specified period.
- To calculate it, sum the closing prices for a set number of periods and divide by that number.
- For example, a 5-day SMA uses the last 5 days’ closing prices.
- SMAs are widely used in financial analysis to identify trends and potential support/resistance levels.
- Shorter SMAs react more quickly to price changes, while longer SMAs are smoother and show longer-term trends.
- The “period” for the average can be anything: days, weeks, months, or even minutes.
Who this is for
- Investors looking to understand basic technical analysis tools.
- Traders who want to identify trends and potential entry/exit points in financial markets.
- Anyone interested in smoothing out volatile data series to see underlying patterns.
What to check first (before you act)
Your Goal and Timeline
What are you trying to achieve by calculating an SMA? Are you looking for short-term trading signals, or are you trying to understand the long-term trend of an asset? Your goal will influence the length of the moving average period you choose. A shorter period (e.g., 10-day SMA) is more sensitive to recent price changes and useful for short-term analysis, while a longer period (e.g., 50-day or 200-day SMA) reflects longer-term trends and is less prone to noise.
Your Data Source
Where will you get the price data from? You’ll need historical closing prices for the asset you’re analyzing. This could be stock prices, cryptocurrency prices, or data from any other financial instrument. Ensure your data is accurate and covers the period you intend to analyze. Many financial websites and charting platforms provide historical data, and some offer tools to automatically calculate SMAs.
Understanding the Timeframe
What timeframe are you interested in? Are you looking at daily price movements, weekly trends, or even intraday fluctuations? The timeframe you choose will determine the “periods” you use in your calculation. For example, if you’re analyzing daily stock charts, your periods will likely be in days. If you’re looking at weekly charts, your periods will be in weeks.
Step-by-step: Calculating a Simple Moving Average
1. Choose your asset and data: Select the financial asset (e.g., a stock, ETF, or cryptocurrency) you want to analyze. Obtain its historical closing prices for the desired timeframe (e.g., daily closing prices).
- What “good” looks like: You have a clear list or table of daily closing prices for your chosen asset.
- Common mistake and how to avoid it: Using opening prices or adjusted closing prices instead of the standard closing price. Always confirm which price point your data source is providing.
2. Determine the lookback period: Decide how many periods you want to include in your average. Common periods are 10, 20, 50, 100, or 200. A shorter period makes the SMA more sensitive to recent price changes.
- What “good” looks like: You have a specific number (e.g., 20) that represents your chosen lookback period.
- Common mistake and how to avoid it: Picking a period arbitrarily without considering your trading strategy or the asset’s volatility. Research common SMA periods used for similar assets or consult trading resources.
3. Gather the required data points: Collect the closing prices for the chosen asset for the number of periods you selected in step 2. For example, if you chose a 20-day SMA and are looking at daily data, you’ll need the closing prices for the last 20 days.
- What “good” looks like: You have a set of 20 (or your chosen period) consecutive closing prices.
- Common mistake and how to avoid it: Including incorrect or non-consecutive days. Ensure your data is sequential and covers the exact period needed for the calculation.
4. Sum the closing prices: Add up all the closing prices you gathered in the previous step.
- What “good” looks like: You have a single number representing the total sum of those prices.
- Common mistake and how to avoid it: Simple arithmetic errors. Double-check your addition, especially if using a manual spreadsheet.
5. Divide by the number of periods: Take the sum from step 4 and divide it by the number of periods you chose in step 2. This result is your Simple Moving Average for that specific point in time.
- What “good” looks like: You have a single number, which is the calculated SMA value.
- Common mistake and how to avoid it: Dividing by the wrong number (e.g., the total number of data points available instead of your lookback period). Ensure you divide by your chosen lookback period.
6. Calculate for subsequent periods: To create a moving average line on a chart, you repeat steps 3-5 for each subsequent period. For example, to calculate the next day’s 20-day SMA, you would drop the oldest day’s price from your sum and add the newest day’s closing price, then divide by 20 again.
- What “good” looks like: You have a series of SMA values, each calculated for a different point in time, forming a line when plotted.
- Common mistake and how to avoid it: Not “moving” the window. Forgetting to drop the oldest data point and add the newest one will result in a static average, not a moving one.
7. Plot the SMA: If you’re using charting software, you can typically input the asset, the timeframe, and the desired SMA period, and it will calculate and plot it for you. If doing it manually, plot each calculated SMA value against its corresponding date.
- What “good” looks like: A smooth line on your price chart representing the SMA.
- Common mistake and how to avoid it: Misinterpreting the plotted line as price itself. The SMA is an indicator derived from price, not the price action itself.
Common Mistakes (and what happens if you ignore them)
| Mistake | What it causes | Fix |
|---|---|---|
| Using the wrong type of price data | Inaccurate calculations and misleading trend signals. For example, using opening price for a closing price calculation. | Always use the consistent price type (usually closing price) for your calculation. Verify your data source. |
| Incorrect lookback period selection | SMAs that are too sensitive (short periods) or too slow to react (long periods), leading to missed opportunities or false signals. | Research common periods for your asset and timeframe. Experiment with different periods to see how they reflect price action. |
| Arithmetic errors in summation or division | The calculated SMA value will be wrong, leading to incorrect analysis and trading decisions. | Double-check your calculations. Use spreadsheet functions or charting software for accuracy. |
| Not “moving” the average | The calculation becomes static, failing to reflect current price trends and providing outdated signals. | Ensure you drop the oldest data point and add the newest one for each subsequent calculation. |
| Confusing SMA with actual price | Misinterpreting signals, believing the SMA is the current price, and making decisions based on flawed understanding. | Remember the SMA is an <em>average</em> of past prices, designed to smooth out noise and show trend direction. |
| Ignoring the timeframe of the data | Applying a short-term SMA to long-term data or vice-versa, resulting in mismatched analysis and inappropriate signals. | Ensure your SMA period aligns with the timeframe of your price data (e.g., 20-day SMA on daily charts, 50-week SMA on weekly charts). |
| Using SMAs in highly volatile, choppy markets | SMAs can generate frequent “whipsaws” (false signals) in sideways or very volatile markets, leading to losses. | Understand market conditions. SMAs work best in trending markets. Consider using other indicators or different SMA types in choppy markets. |
| Over-reliance on a single SMA | Missing crucial information from other price action or indicators, leading to incomplete analysis and poor decisions. | Use SMAs in conjunction with other technical indicators and fundamental analysis for a more robust trading strategy. |
| Calculating SMAs on non-time-series data | The concept of “moving” average is lost, rendering the calculation meaningless. | Ensure the data you are using is a time series (e.g., prices over consecutive days, weeks, or months). |
Decision rules (simple if/then)
- If the price is consistently above a rising SMA, then the trend is likely upward because the SMA is acting as support.
- If the price is consistently below a falling SMA, then the trend is likely downward because the SMA is acting as resistance.
- If a shorter-term SMA crosses above a longer-term SMA (e.g., 50-day SMA crosses above 200-day SMA), then this is often interpreted as a bullish signal (a “golden cross”) because momentum is increasing.
- If a shorter-term SMA crosses below a longer-term SMA (e.g., 50-day SMA crosses below 200-day SMA), then this is often interpreted as a bearish signal (a “death cross”) because momentum is decreasing.
- If the price crosses above an SMA, then it may signal a potential shift from a downtrend to an uptrend or a continuation of an uptrend.
- If the price crosses below an SMA, then it may signal a potential shift from an uptrend to a downtrend or a continuation of a downtrend.
- If an SMA is flat or moving sideways, then the market is likely in a consolidation or sideways trend, and the SMA may not provide strong directional signals.
- If you are a short-term trader, then using shorter SMAs (e.g., 10-day or 20-day) might be more appropriate because they react faster to price changes.
- If you are a long-term investor, then using longer SMAs (e.g., 50-day, 100-day, or 200-day) might be more appropriate because they smooth out short-term fluctuations and highlight longer-term trends.
- If the price is frequently crossing back and forth over an SMA, then the market is likely choppy or in a range, and the SMA might be generating too many false signals.
- If you are analyzing a highly volatile asset, then using a longer SMA period might be necessary to filter out excessive noise and identify the true underlying trend.
FAQ
What is the most common Simple Moving Average period?
While there’s no single “most common” period, the 50-day and 200-day SMAs are very widely watched in stock market analysis. Shorter periods like 10-day or 20-day are often used for shorter-term trading.
Can I use SMAs for cryptocurrencies?
Yes, SMAs can be used for cryptocurrencies just like stocks. However, cryptocurrencies are often more volatile, so you might need to adjust your chosen period or use them in conjunction with other indicators.
What is the difference between a Simple Moving Average (SMA) and an Exponential Moving Average (EMA)?
An SMA gives equal weight to all prices in the lookback period. An EMA gives more weight to recent prices, making it more responsive to current price changes than an SMA.
How do I interpret a crossover of two SMAs?
When a shorter-term SMA crosses above a longer-term SMA, it’s often seen as a bullish signal. When a shorter-term SMA crosses below a longer-term SMA, it’s often seen as a bearish signal.
Can SMAs predict future prices?
No, SMAs are lagging indicators, meaning they are based on past price data. They help identify trends and potential support/resistance levels but do not predict future prices with certainty.
What if the price is moving sideways?
In sideways or choppy markets, SMAs can be less effective and may generate frequent false signals (whipsaws). It’s often best to use SMAs in trending markets or combine them with other tools to confirm signals.
How many SMAs should I use at once?
It’s generally recommended not to overload your chart with too many SMAs. Many traders find success using one or two SMAs, such as a short-term and a long-term one, to identify trends and potential crossovers.
Are SMAs the only technical indicator I need?
No, SMAs are just one tool among many in technical analysis. For more robust trading decisions, it’s advisable to use SMAs in combination with other indicators (like RSI, MACD) and fundamental analysis.
What this page does NOT cover (and where to go next)
- Exponential Moving Averages (EMAs) and other advanced moving average types: While SMAs are foundational, EMAs and Weighted Moving Averages (WMAs) offer different ways to smooth data.
- Complex trading strategies involving SMAs: This guide focuses on calculation; actual trading strategies involve combining SMAs with other indicators and risk management.
- Backtesting and optimizing SMA periods: Determining the “best” SMA period for a specific asset often involves historical testing.
- Using SMAs in algorithmic trading: Automated trading systems require a deeper dive into programming and strategy implementation.
- Fundamental analysis of assets: Understanding a company’s financials or economic factors is crucial for long-term investment decisions, beyond technical indicators like SMAs.