Calculating Moving Averages: A Simple Explanation
Quick answer
- Moving averages smooth out price data to identify trends.
- The simplest type is the Simple Moving Average (SMA).
- Calculate SMA by summing prices over a period and dividing by the number of periods.
- Shorter periods react faster to price changes; longer periods are smoother.
- Moving averages are used in finance, but also in other data analysis fields.
- They help visualize trends without the noise of daily fluctuations.
Who this is for
- Investors looking to understand trend analysis in financial markets.
- Data analysts who need to smooth out time-series data.
- Anyone curious about technical indicators used in charting.
What to check first (before you act)
Your Data
Before calculating any moving average, ensure you have a consistent set of data points. This could be daily stock prices, weekly sales figures, or monthly temperature readings. The data needs to be ordered chronologically.
Your Goal
What are you trying to achieve by calculating a moving average? Are you trying to identify the general direction of a stock price over the last month, or smooth out yearly sales to see a long-term growth trend? Your goal will dictate the type of moving average and the period you choose.
The Period (Lookback Window)
This is the number of data points you will include in each calculation. Common periods include 10, 20, 50, 100, or 200 days for financial data. A shorter period will make the moving average more sensitive to recent price changes, while a longer period will create a smoother line that reflects longer-term trends.
Step-by-step: Calculating a Simple Moving Average (SMA)
1. Gather your data: Collect a series of chronological data points. For example, let’s say you’re looking at the closing price of a stock for the last 5 days: \$10, \$12, \$11, \$13, \$14.
- What “good” looks like: You have a list of numbers in the correct order.
- Common mistake: Using data from different timeframes (e.g., mixing daily and weekly prices) or having data out of order.
- How to avoid it: Double-check your data source and ensure it’s all from the same frequency and time period, and sort it chronologically.
2. Choose your period (n): Decide how many data points you want to average over. Let’s choose a 3-day moving average. So, n = 3.
- What “good” looks like: You have a clear number representing your lookback window.
- Common mistake: Not defining the period clearly, leading to inconsistent calculations.
- How to avoid it: Write down your chosen period before you start calculating.
3. Calculate the first moving average: Sum the first ‘n’ data points and divide by ‘n’.
- For our example: (\$10 + \$12 + \$11) / 3 = \$11.
- What “good” looks like: You have the first calculated average value.
- Common mistake: Forgetting to divide by ‘n’ or including too few or too many data points in the sum.
- How to avoid it: Carefully count the number of data points you’re adding and ensure you divide by that exact number.
4. Calculate the second moving average: Drop the oldest data point and add the next newest data point to your sum, then divide by ‘n’.
- The oldest data point was \$10. The next newest is \$13.
- New sum: (\$12 + \$11 + \$13) / 3 = \$12.
- What “good” looks like: You have your second calculated average value.
- Common mistake: Re-using the old sum without dropping the oldest and adding the newest point, leading to an incorrect average.
- How to avoid it: Mentally or physically cross out the oldest data point and add the new one to your sum before dividing.
5. Continue for all data points: Repeat step 4 for every subsequent data point.
- For the next point: (\$11 + \$13 + \$14) / 3 = \$12.67.
- What “good” looks like: You have a series of moving average values corresponding to your data.
- Common mistake: Stopping calculations too early or trying to calculate an average for the very first data points where you don’t have enough preceding data.
- How to avoid it: Understand that you won’t have a moving average for the first (n-1) data points.
6. Plot your results (optional but recommended): Graph your original data and your calculated moving average line on the same chart.
- What “good” looks like: A visual representation showing how the moving average smooths the price action.
- Common mistake: Plotting the moving average data incorrectly, making it hard to interpret.
- How to avoid it: Ensure your moving average values are plotted against the corresponding time periods they represent.
Common mistakes (and what happens if you ignore them)
| Mistake | What it causes | Fix |
|---|---|---|
| <strong>Using inconsistent data frequency</strong> | Inaccurate and misleading trend identification. | Ensure all data points are from the same timeframe (e.g., all daily closing prices). |
| <strong>Incorrectly defining the period (n)</strong> | Moving average will not reflect the desired trend sensitivity (too fast or too slow). | Clearly state and stick to your chosen lookback window (e.g., 50-day, 200-day). |
| <strong>Skipping calculation steps</strong> | The moving average line will be inaccurate and not a true average of the chosen period. | Follow the step-by-step process precisely for each new data point. |
| <strong>Forgetting to divide by ‘n'</strong> | The resulting numbers will be sums, not averages, leading to dramatically different and incorrect values. | Always divide the sum of your data points by the number of data points (‘n’). |
| <strong>Including data outside the period</strong> | The average will be skewed by irrelevant data, misrepresenting the trend. | Only sum the ‘n’ most recent data points for each calculation. |
| <strong>Trying to calculate for insufficient data</strong> | You cannot calculate a moving average for the first (n-1) data points as there aren’t enough prior points. | Understand that the moving average line starts later than your original data. |
| <strong>Misinterpreting the moving average</strong> | Making trading or business decisions based on false signals or trends. | Remember that a moving average is a lagging indicator and represents past performance. |
| <strong>Not considering other indicators</strong> | Over-reliance on a single moving average can lead to missed opportunities or false signals. | Use moving averages in conjunction with other technical analysis tools or fundamental data. |
| <strong>Using wrong type of moving average</strong> | Different moving averages (e.g., Exponential Moving Average – EMA) give different weightings. | Understand the difference between SMA and other types like EMA and choose the one that fits your analysis needs. |
| <strong>Not updating the calculation</strong> | The moving average will become stale and less relevant to current conditions. | Regularly update your moving average calculations as new data becomes available. |
Decision rules
- If you are looking for short-term trend signals, then use a shorter moving average period (e.g., 10-day or 20-day) because it reacts more quickly to price changes.
- If you are looking for long-term trend signals, then use a longer moving average period (e.g., 100-day or 200-day) because it filters out short-term noise.
- If the price is consistently above a long-term moving average, then this suggests an uptrend because the average price over the longer period is lower than the current price.
- If the price is consistently below a long-term moving average, then this suggests a downtrend because the average price over the longer period is higher than the current price.
- If a shorter moving average crosses above a longer moving average, then this can be interpreted as a bullish signal because momentum is increasing.
- If a shorter moving average crosses below a longer moving average, then this can be interpreted as a bearish signal because momentum is decreasing.
- If your data has significant volatility, then a longer moving average period will provide a smoother and more reliable trend line because it averages out more data points.
- If you need to react quickly to market changes, then a shorter moving average is more appropriate because it incorporates recent data more heavily.
- If you are analyzing business sales data, then a moving average can help identify seasonal trends or overall growth patterns by smoothing out daily or weekly fluctuations.
- If you are new to moving averages, then start with the Simple Moving Average (SMA) because it is the easiest to understand and calculate.
- If the moving average line is flat, then this indicates a period of consolidation or sideways movement in the data because the average price is not changing significantly.
- If you observe frequent crossovers between short and long-term moving averages, then the market is likely in a choppy or non-trending phase because signals are being generated and quickly reversed.
FAQ
What is a moving average?
A moving average is a technical analysis tool that smooths out price data by creating a constantly updated average price. It helps to identify the direction of a trend and reduce the impact of random price fluctuations.
What’s the difference between a Simple Moving Average (SMA) and an Exponential Moving Average (EMA)?
An SMA gives equal weight to all data points in the period. An EMA, on the other hand, gives more weight to recent data points, making it more responsive to current price changes.
How do I choose the right period for my moving average?
The choice of period depends on your objective. Shorter periods (e.g., 10, 20) are used for short-term analysis and react quickly, while longer periods (e.g., 50, 200) are for long-term trends and are smoother.
Can moving averages predict future prices?
No, moving averages are lagging indicators. They are based on past data and can help identify current trends and potential future directions, but they cannot guarantee future price movements.
What does it mean when a stock’s price crosses its moving average?
When a price crosses above its moving average, it can be seen as a bullish signal. When it crosses below, it can be seen as a bearish signal, suggesting a potential change in trend.
Are moving averages only used for stock prices?
No, moving averages are versatile and can be used to analyze any time-series data, such as sales figures, economic indicators, weather patterns, or website traffic.
How many data points do I need to calculate a moving average?
You need at least as many data points as your chosen period (n). For example, to calculate a 10-day moving average, you need at least 10 days of data.
What is a “golden cross” or “death cross”?
These are specific moving average crossovers. A golden cross occurs when a shorter-term moving average (like the 50-day) crosses above a longer-term moving average (like the 200-day), often seen as bullish. A death cross is the opposite (50-day crossing below 200-day) and is considered bearish.
What this page does NOT cover (and where to go next)
- Exponential Moving Averages (EMA) and other advanced types: While this guide focused on the Simple Moving Average (SMA), other types like EMA, Weighted Moving Average (WMA), and Smoothed Moving Average (SMMA) exist, each with its own calculation and application.
- Using moving averages in trading strategies: This article explains how to calculate them. Developing specific trading strategies that incorporate moving averages requires further study into how they are used with other indicators and market conditions.
- Advanced technical analysis indicators: Moving averages are just one tool. Exploring other indicators like MACD, RSI, Bollinger Bands, and chart patterns will provide a more comprehensive understanding of market analysis.
- Fundamental analysis: Understanding the underlying business or economic factors that influence prices is crucial and complements technical analysis tools like moving averages.
- Risk management: Regardless of the analysis tools used, effective strategies for managing investment risk are essential for long-term success.