Swing trading settings

Which Moving Average Is Best for Trends?

Short answer

No moving average is best for every trend. A 20-bar average is a shorter-horizon candidate, a 50-bar SMA is a common intermediate trend reference, and a 200-bar SMA tracks a broader regime. EMA weights recent prices more heavily than SMA, so it responds faster but can change direction more often. Match the length to the trend you want to follow, define price position and slope separately, then compare the complete strategy after costs on data kept out of tuning.

Parameters and what they change

Treat each value as a starting point. A setting only becomes useful after you test it on the same market, timeframe, costs, and date range you plan to study.

Swing trading parameter comparison
ParameterStarting pointWhat it changesCaution
SMA or EMACompare both at the same lengthSMA weights each price in its window equally. EMA gives recent values more weight and generally reacts sooner.Faster reaction can help after a turn but also creates more short-term changes. It is not evidence of a better trading result.
Shorter trend reference20 bars, an illustrative baselineTracks a shorter segment of price history for swing timing or a fast trend filter.It can flip repeatedly during a range. Twenty bars means twenty days only on a daily chart, not on a four-hour chart.
Intermediate trend reference50-bar SMAProvides a slower direction filter that can be paired with a separate swing entry trigger.A rebound can put price above the average before the average turns upward. Specify whether your rule needs one condition or both.
Longer trend reference200-bar SMAProvides a broad regime reference rather than a fast entry signal.More smoothing delays recognition of turns. Use the same evaluation dates after all tested averages have enough prior history.
Slope windowCompare with five bars ago, for illustrationTurns a rising average into a rule: current average greater than the average five completed bars earlier. Equality fails this positive-slope condition.A longer comparison window can keep the slope positive after a recent turn. Test the window separately from the average length.
Price positionCompleted close above the averageDefines a long-side permission condition. The short-side mirror requires the close below the average and, if used, negative slope.Price above the average does not establish that the average is rising. Requiring both checks may exclude trades and delay entries.
Source and confirmationClose source, zero plot offset, completed barsKeeps the input series and decision time consistent across comparisons.The current close and its average can change intrabar. A plot offset only shifts the displayed line; it does not remove calculation lag.

Presets to test, not copy blindly

Illustrative short-swing study

Daily chart; holds of several days

Compare 20 SMA and 20 EMA as the trend reference

Use when responsiveness is the hypothesis. Track how often each filter changes state during a range and whether earlier exits offset the added turnover.

Illustrative intermediate-trend study

Daily chart; holds of several weeks

50 SMA with price-position and five-bar slope checks

Use when the entry rule should ignore some short swings. Compare price-only permission with price plus slope while keeping the entry and exit rules identical.

Illustrative longer-regime study

Daily chart; trends lasting months

200 SMA as a filter for a separate swing entry

Use when broad direction matters more than early reversal entries. Review missed recoveries as well as drawdown; a slower filter can stay bearish after price has turned.

Test templates you can audit

These templates define a research process. They are not trade calls or evidence that a setup will make money.

One chosen liquid symbol; hypothetical test

1D, standard candles

Rule to test

When flat, enter long after a completed close crosses above a 20-bar average. Exit after a completed close crosses below it. Compare SMA and EMA with the same fixed position size, no pyramiding, and next-bar market orders.

This isolates average type. Record fees and slippage explicitly. Keep an untouched later date range, then compare net average trade, drawdown, and turnover there without changing the selected settings.

Same symbol and dates; hypothetical test

1D, standard candles

Rule to test

Use a close above the highest high of the previous ten completed bars as the long entry trigger, and a close below the lowest low of the previous five completed bars as the exit. Compare no filter, close above 50 SMA, and close above 50 SMA with its value above five bars ago. Keep sizing fixed and allow one position.

This isolates the filter contribution. Predeclare the trend and range periods to inspect, include all of them, and compare exposure and missed trades as well as drawdown. The breakout windows are illustrative choices.

Several preselected symbols; hypothetical test

1D, identical evaluation dates

Rule to test

Keep the ten-bar breakout entry, five-bar exit, and price-plus-slope filter from the previous test. Compare SMA lengths 20, 50, and 200 with the same five-bar slope window, sizing, and execution settings.

This isolates trend horizon. Start only after the longest average and slope window are available. Select on the training period, freeze the choice, and evaluate later data. Inspect nearby lengths for sensitivity instead of declaring the highest historical profit universally best.

Checks to run before trusting the result

Define slope numerically before testing. An illustrative rising filter requires the average today to exceed its value five completed bars ago. A line that looks steep on a zoomed chart is not a reproducible condition.

Price above a rising average satisfies both direction checks. Price above a falling average may be a rebound within a decline; price below a rising average may be a pullback. A flat average with repeated price crossings is a warning that the filter may generate frequent reversals.

Illustrative example: a 50-bar SMA rises from 100 to 101 over five bars, but price closes at 100.5. Slope is positive and price position is negative. A rule requiring both conditions rejects the long setup. These numbers describe a hypothetical case, not a historical trade.

A trend filter grants permission to look for an entry; it does not define an entry, stop, or position size. For a swing strategy, keep those rules fixed while comparing filters so a better-looking equity curve has an identifiable cause.

Measure whipsaw costs: record trade count, average net trade, exposure, and drawdown in preselected sideways periods. A faster filter can leave a losing position sooner and still perform worse if repeated exits and re-entries consume the gain through fees and slippage.

Turn the idea into an inspectable rule

Use the Pine Script AI Coding Agent to draft an editable strategy with inputs for average type, length, slope window, and a filter on/off switch. Review its rules and load it into TradingView. Pineify Strategy Optimizer can then compare exposed input combinations through the Chrome extension. Keep the test dates, costs, and order settings consistent; reserve a separate period for a later test without retuning. The generated script and optimization results still need review.

Build a moving-average test

Frequently asked questions

Sources and limits

Sources checked 2026-10-16

  • Moving Averages (TradingView, checked 2026-10-16). Average weighting, lag, trend direction, and the distinction between calculation and plot offset.
  • Simple Moving Average (Fidelity, checked 2026-10-16). Identifies 50-bar and 200-bar averages as common intermediate and long-term references and explains the smoothing-versus-lag tradeoff.
  • Exponential Moving Average (Fidelity, checked 2026-10-16). Explains recent-price weighting and the extra short-term changes that can accompany greater sensitivity.
  • Repainting (TradingView Pine Script documentation, checked 2026-10-16). Explains changing realtime prices, close-confirmed signals, and other causes of historical versus realtime differences.
  • Strategies (TradingView Pine Script documentation, checked 2026-10-16). Documents order timing, simulated costs, selection bias, and testing outside the sample used for optimization.

This page is educational, not investment advice. Parameters and test templates are illustrative research choices with no performance results claimed. Backtests depend on data and execution assumptions and do not predict future returns. Trend filters can delay entries, miss recoveries, and produce repeated losses. Trading can result in loss.