Moving Averages
Smooths price data to reveal the underlying trend direction by averaging closing prices over a defined period.
Overview
Moving averages are the foundation of technical analysis. By smoothing out daily price noise, they reveal whether an asset is in an uptrend, downtrend, or moving sideways. Two main variants exist: the Simple Moving Average (SMA), which weights all periods equally, and the Exponential Moving Average (EMA), which gives more weight to recent prices and reacts faster to new information.
How it looks on a chart
Illustration only — synthetic data generated for visual reference.
A moving average draws a smooth line on your chart by averaging the closing price over a set number of days. If the 50-day line is sloping upward and prices are above it, the market is generally in an uptrend. When prices fall below the moving average, it may signal a shift to a downtrend. Traders often use two moving averages at once — a faster one (like 20 days) and a slower one (like 50 days). When the fast line crosses above the slow line, it is called a "golden cross" and suggests rising momentum. When the fast line crosses below the slow line, it is called a "death cross" and suggests weakening momentum. Moving averages also act as dynamic support and resistance levels. During an uptrend, prices often bounce off the moving average. This makes them useful entry points for traders who want to buy the dip within a larger trend.
The SMA is calculated by summing the last N closing prices and dividing by N. The EMA uses a multiplier k = 2/(N+1) so that recent prices receive proportionally more weight. At a 20-period EMA, the most recent bar carries about 9.5% of the total weight, while the oldest bar contributes less than 0.1%. Parameter selection matters significantly. Short periods (5–20) generate frequent signals with more false positives. Long periods (50–200) filter noise but lag considerably on trend reversals. Crossover systems using the 9/21 EMA pair are popular on intraday charts, while the 50/200 SMA cross is the standard reference on daily charts. In backtesting, moving average crossover systems work best in trending markets and fail badly during sideways chop. Adding a volatility filter — such as only trading crossovers when ATR is above its 20-period average — can substantially improve the Sharpe ratio by sitting out low-conviction environments.
Hull Moving Average (HMA) and DEMA/TEMA variants attempt to reduce the inherent lag of SMA and EMA by applying double or triple smoothing with weighted corrections. The HMA formula, HMA = WMA(2×WMA(n/2) − WMA(n), √n), nearly eliminates lag while preserving smoothness. From an academic standpoint, Lo, Mamaysky and Wang (2000) documented statistically significant predictive power for simple moving average crossovers on U.S. equities, though subsequent studies using transaction costs and risk-adjusted returns show more modest benefits. The profitability of MA strategies has declined post-2000 as markets absorbed this information. When used in systematic strategies, look-ahead bias is a critical concern: a 200-day SMA on day T requires prices from days T-199 through T — any strategy that "knows" the final average before the close of day T introduces bias. Gilito's engine enforces strict point-in-time data handling to prevent this.
Formula
SMA(n) = (P₁ + P₂ + ... + Pₙ) / n EMA(t) = Price(t) × k + EMA(t-1) × (1 - k), where k = 2 / (n + 1)
- 1.Choose period n (e.g., 20 days) and the price series to smooth (typically close).
- 2.For SMA: sum the last n closing prices and divide by n.
- 3.For EMA: compute the smoothing multiplier k = 2 / (n + 1).
- 4.Apply the EMA recursion: EMA(t) = Close(t) × k + EMA(t−1) × (1 − k), seeding with the first SMA value.
- 5.Plot the resulting series as an overlay on the price chart.
Parameters
| Parameter | Default | Range | Description |
|---|---|---|---|
| Fast Period | 20 | 5–50 | Number of bars for the faster moving average. |
| Slow Period | 50 | 20–200 | Number of bars for the slower moving average. |
| MA Type | 1 | 0–1 | 0 = SMA, 1 = EMA. |
Trading signals
bullish: Fast MA crosses above Slow MA
Golden cross — momentum shifting upward, potential long entry.
bearish: Fast MA crosses below Slow MA
Death cross — momentum shifting downward, potential short or exit signal.
bullish: Price bounces off rising MA
Dynamic support hold — trend continuation entry in pullback.
bearish: Price breaks below flat or falling MA
Trend breakdown — possible exit or short entry.
Limitations
- •Lagging indicator — signals arrive after the move has already started.
- •Generates many false signals during sideways, choppy markets.
- •Period selection is arbitrary and often optimized in-sample, leading to overfitting.
- •Does not convey information about volume or volatility, so signal strength varies greatly.
Gilito tests thousands of MA period combinations (fast/slow pairs from 5 to 200) across every asset in its universe, scoring each crossover system by Sharpe, max drawdown, and win rate on out-of-sample data. It also uses EMAs as regime filters — only activating other sub-strategies when price is above a configurable long-term EMA.