Is there a best moving average setting?
No. A length is a trade-off between speed and noise, and the right point on that trade-off depends on how long you hold, how volatile the market is and what you use the line for. Popular lengths work partly because many traders watch them: TradingView’s built-in EMA loads with a length of 9 and its MA Cross indicator with 9 and 21, so those numbers end up on a great many charts. That makes them reasonable defaults, not proven edges.
What does matter: matching the length to your holding time, keeping the same settings long enough to learn how they behave, and judging any setting on many trades after costs. A setting that “works” on last month’s chart is usually just fitted to it.
- Lookback length
- The number of bars a moving average uses, such as 20. It counts bars, not days, so a 20 on a 5-minute chart covers 100 minutes.
Best moving average settings by trading style
These are the conventions you will see most often, matched to holding time, as in the drawing at the top:
- Scalping and day trading, 1- to 5-minute charts: the 9 EMA for momentum and the 20 or 21 EMA as the pullback line, with VWAP as the day’s reference. A 21 EMA on a 5-minute chart spans about 105 minutes of trading; best timeframe for day trading covers the chart side.
- Swing trading, daily charts and sometimes the 4-hour: the 10 and 20 or 21 EMA for the short trend and the 50-day SMA as the deeper pullback line. A 21-day EMA spans about a month of sessions.
- Position trading and investing, daily and weekly charts: the 50-day and the 200-day moving average, or their weekly cousins, the 10- and 40-week averages.
21 EMA vs 20 EMA: does the difference matter?
Barely. The newest close carries 9.5% of a 20 EMA and 9.1% of a 21 EMA, so the two lines nearly overlap. On the hypothetical daily XYZ chart below, over 65 sessions, the largest gap between them was $0.21, or 0.19% of price, and only one close out of 65 landed between the two lines.
That one close shows where any difference comes from. XYZ was pulling back to the averages: it closed at $106.20, just below both, then at $106.24, 2 cents above the 21 EMA ($106.22) and 10 cents below the 20 EMA ($106.34), then fell to a low of $105.12. A rule that buys the first close back above the line would have bought that day with the 21 EMA and not with the 20, and over the whole chart closes crossed the 21 EMA six times and the 20 EMA four. On another chart the coin lands the other way: that is noise, not an edge.
- 21 EMA
- An exponential moving average of the last 21 bars, weighting the newest close at 2 ÷ 22, about 9.1%. On a daily chart it spans about a month of sessions.
20 EMA strategy: a worked pullback trade (hypothetical)
The same chart gives a worked example of the common 20 EMA pullback. XYZ is in an uptrend above a rising 20 EMA, with a swing high of $109.43. It pulls back, closes below the line three sessions in a row and reaches a low of $105.12. The next session closes at $106.76, back above both the 20 EMA ($106.31) and the 21 EMA ($106.21): buy at $106.76 with a stop $0.10 under the pullback low, at $105.02, a risk of $1.74 a share. The first target is the swing high, $2.67 away, about 1.5R.
With the 21 EMA instead of the 20, this entry, stop and target are identical: the setting changed nothing that mattered. What mattered was the plan: an entry on a closed candle, a stop at the pullback low, a target with room and a size set from the stop, as in the EMA trading strategy.
How to choose a moving average length for your timeframe
A practical rule of thumb: use the length the market has respected on your timeframe, and that fits your holding time. A simple average trails a steady trend by about half its length, (N − 1) ÷ 2 bars, so a line much slower than your holding period describes a trend you will not be in, and a much faster one mostly shows noise.
To check “respected”, go back over the last 20 or so clear pullbacks in trends you would have traded and note where they paused: near the 20, near the 50, or nowhere in particular. Count the misses too, because the eye remembers the touches. If no line fits clearly better, use the convention for your style and stop searching.
9/21 vs 10/20: does the crossover setting change the result?
Less than most people expect. The drawing below counts the crosses of three pairs on the same 260 hypothetical daily bars. The 9/21 EMA crossed 13 times and the 10/20 EMA 13 times, on the same bars except one, where they were a bar apart. The 10-day SMA crossing the 20-day SMA, the version behind the search “10 day moving average crosses 20 day”, fired 8 times, at different moments: switching from EMA to SMA changed more than switching lengths, as types of moving averages would predict.
Nine of the 13 EMA crosses came in one sideways stretch of about 50 bars, where both pairs whipsawed in step. The setting did not decide whether the crosses were useful; the market did, which is why the filters in moving average crossover matter more than the numbers.
How to test a moving average setting without overfitting
Testing every length from 5 to 50 and keeping the best one is the classic way to fool yourself. When Sullivan, Timmermann and White (Journal of Finance, 1999) widened a set of 26 simple trading rules to thousands and corrected for data snooping, the best rule over the first 90 years of their Dow data did not hold up in the decade that followed. A cleaner process:
- Write the rule before testing: entry, stop, exit and size, with the length set to the convention for your style.
- Test a few nearby lengths, such as 18, 20, 21 and 23, not dozens. A sound setting sits on a plateau where its neighbours do about as well; a lone peak is usually luck.
- Include realistic costs, then check the result on data the test never saw and on paper trading.
- Judge 100 or more trades, not a handful, as how to backtest a trading strategy explains, and read backtest overfitting before trusting a perfect curve.
- Parameter plateau
- A range of nearby settings, such as lengths 18 to 23, that give similar test results: a sign the rule is not just fitted to one lucky number.