Simple moving average vs exponential: compare the weights
For complete, equally spaced closing-price data, SMA is the sum of the latest N closes divided by N. EMA updates as alpha × current close + (1 − alpha) × previous EMA, with alpha = 2 / (N + 1). The EMA needs an initial value, so record the seed and warm-up history when reproducing numbers. These formulas describe the calculations, not a forecast.
| Same length: 5 bars | SMA | EMA |
|---|
| Newest close | 20% weight | 33.333% weight |
| Previous close | 20% weight | 22.222% weight |
| Two bars ago | 20% weight | 14.815% weight |
| Older observations | 20% each for three and four bars ago; zero outside the five-bar window. | Weights continue to decay. The previous EMA carries the remaining history and seed contribution. |
| What moves the line | The difference between the new price entering and the old price leaving the window. | The difference between the new price and the previous EMA. |
Trend example: faster response does not mean an earlier entry
Illustrative prices, not market history: begin with five closes of 100 and an EMA seed of 100. Then prices rise by 2 each bar. Both averages have length 5 and use the same close. Values are rounded to three decimals for display; calculations retain full precision. If the signal is a close crossing above its average from at or below it, both signal on bar 1. The EMA line reacts more, but that rule does not enter earlier.
- A second hypothetical path exposes a different limit: after the same initialization, let price jump to 110 and stay there. On the first bar, SMA is 102 and EMA is 103.333. On the fifth bar, SMA is 110 and EMA is 108.683. The fixed SMA window has fully replaced the old prices, while EMA still retains some older weight.
- If the rising path reverses after entry, either signal can lose. These examples contain no fills, trading costs, or profitability result. They show why initial response, time to settle, and entry timing are different measurements.
| Bar after initialization | Close | SMA (5) | EMA (5) |
|---|
| 1 | 102 | 100.400 | 100.667 |
| 2 | 104 | 101.200 | 101.778 |
| 3 | 106 | 102.400 | 103.185 |
| 4 | 108 | 104.000 | 104.790 |
| 5 | 110 | 106.000 | 106.527 |
| 6 | 112 | 108.000 | 108.351 |
Range example: a smoother line can still whipsaw
Reset to the same five closes of 100 and EMA seed of 100. Now alternate between 102 and 98. The table labels the close relative to each average, not a recommendation to buy or sell. A rule that enters on a cross above and exits on a cross below would alternate signals on every displayed bar with either average. All prices here are hypothetical closed-bar values.
- Switching from EMA to SMA does not automatically remove false entries. In this sequence the averages have different values but identical signal directions.
- A distance threshold, longer length, or trend filter changes the strategy. Test each change separately; reducing activity can also delay or exclude a sustained move.
- Count entries and exits as well as returns. Repeated trades incur costs even when the plotted averages look smooth.
| Bar | Close | SMA (5) | EMA (5) | Close vs both |
|---|
| 1 | 102 | 100.400 | 100.667 | Above |
| 2 | 98 | 100.000 | 99.778 | Below |
| 3 | 102 | 100.400 | 100.519 | Above |
| 4 | 98 | 100.000 | 99.679 | Below |
| 5 | 102 | 100.400 | 100.453 | Above |
| 6 | 98 | 99.600 | 99.635 | Below |
Set up a fair SMA vs EMA comparison in TradingView
Add the built-in simple and exponential moving averages to one standard candlestick chart. Match length and source, set the display offset to zero, and use the chart timeframe for both. A 20-bar average on a five-minute chart and a 20-bar average on a daily chart summarize different observations. Extra smoothing or a different indicator timeframe introduces another variable.
- Use the same exchange symbol, session, adjusted-price setting, and loaded history. A comparison across different feeds is also a data comparison.
- Read both averages from the same completed candle. The current close changes while a realtime candle is open, so both the average and a crossing condition can change before that candle closes.
- Choose whether a signal must wait for the chart bar to close. That reduces signals that vanish within that bar, but delays the decision and does not remove closed-bar whipsaws.
- Check higher-timeframe requests separately if the script uses them. Confirmation of the chart candle alone does not confirm a still-open higher-timeframe candle.
Test the average type before tuning the strategy
Use one explicit experimental rule for both versions: while flat, enter long when a completed close is above its selected average and the previous close was at or below the previous average. Exit when a completed close is below its average and the previous close was at or above it. Hold on equality; do not pyramid or short. This is a proposed comparison procedure, not a tested trading strategy.
- Start with the same length, source, warm-up period, symbol, timeframe, dates, position size, and capital. Change only SMA versus EMA.
- Use the same order timing and fill settings. Under the usual bar-close calculation and next-tick market-order setup, a signal at one close is typically filled at the following open, not at the signal price.
- Apply identical commission and slippage assumptions. Review signal timestamps, trade count, drawdown, exposure, and net results after costs. Diagnose the first differing signal before ranking returns.
- Choose trend and range evaluation periods before looking at which version wins. Reserve later data for a separate check rather than selecting the average on every period and reporting those selected results together.
- Only then compare parameter ranges. Pineify Strategy Optimizer can help run input-parameter trials, but keep the average type fixed within each matched run and use the same parameter grid for the other version. Compare the same configurations before choosing a best result.
Build a comparison you can inspect
Ask the Pine Script AI Coding Agent to draft one script with an SMA/EMA selector, a shared length and price source, both plotted averages, and the explicit closed-bar rules above. Review the generated code and check it in TradingView before evaluating results. If you prefer visual configuration, the Visual Pine Script Editor includes separate SMA and EMA indicators with source and length settings; add both with matching inputs.
- Keep the visual comparison and the strategy report distinct. A line that tracks price closely does not establish a profitable order rule.
- Check the strategy version, selected average, and input settings before each optimizer run. Preserve those settings with the results so the comparison can be reproduced.