Skip to main content
On this page

Smoothed Moving Average: Correct Pine Script Formula and Settings

· 4 min read
Pineify Team
Pine Script and AI trading workflow research team

A Smoothed Moving Average (SMMA) is a recursive average with a smoothing weight of 1 / length. It reduces the contribution of each new observation relative to a conventional EMA of the same length. That changes responsiveness and lag; it does not establish a superior trading strategy.

Smoothed Moving Average Indicator on TradingView chart showing trend direction

Formula and initialization​

For a positive length n, the recurrence is:

SMMA current = [SMMA previous × (n - 1) + source current] / n

The first available value is seeded from an n-observation simple average. Older observations then retain declining influence through the previous average. The starting history and handling of unavailable values matter when comparing two implementations.

Pineify's core implementation explicitly seeds with ta.sma and applies this recurrence. Its configuration defaults to Close and Length 7, with a line over the price chart. A default is not an optimized recommendation for a trading style.

Adding the Smoothed Moving Average indicator in the Pineify editor

Use ta.rma in Pine Script​

Pine's built-in ta.rma provides Wilder-style smoothing with alpha 1 / length. There is no built-in ta.smma function to call. The following example uses a positive-length input and plots the result:

//@version=6
indicator("SMMA", overlay=true)
len = input.int(14, "Period", minval=1)
src = input.source(close, "Source")
smma = ta.rma(src, len)
plot(smma, "SMMA", color=color.blue, linewidth=2)

The example uses 14 as an editable demonstration value; it does not change Pineify's default of 7. The Pine reference for ta.rma documents its smoothing and missing-value behavior. When comparing it with a custom recurrence, align the history and investigate any missing-source observations instead of assuming every edge case is identical.

This is an indicator, not a strategy. It creates no orders and reports no backtest returns. Syntax validation does not establish a profitable use of the line.

Pineify's visual editor interface for creating Pine Script indicators

Compare SMMA, EMA, and SMA carefully​

An SMA gives equal weight to the observations in its finite window. A conventional EMA uses alpha 2 / (n + 1), while this SMMA uses 1 / n. For the same length greater than one, SMMA assigns less weight to the newest observation than that EMA. Comparisons with a different-length EMA require examining the actual weights rather than the names alone.

A rising average records a change in the smoothed source. Calling it an uptrend is an interpretation under a chosen definition. A price crossing the average can reverse again. Neither a smooth-looking line nor a selected bounce proves that it provides reliable support or resistance.

Multiple lengths on the same chart are multiple lookback settings, not automatically multiple timeframes. A higher-timeframe series requires a separate request and careful handling of when its bars are confirmed.

Evaluate a crossover rule​

Specify whether entry requires a confirmed close crossing the line, how an existing position exits, and whether the rule is long-only or reverses. Set position sizing and costs before comparing settings. Inspect individual fills and retain the exact symbol, timeframe, dates, source, and length.

If you add a volume or RSI filter, evaluate the change against the same baseline and report trade count and exposure. An SMMA does not make the ATR calculation cleaner: ATR is calculated from true ranges independently of this moving average unless a custom formula explicitly changes its inputs.

Pineify's Visual Editor can configure the SMMA and generate a script for review. Testing strategy behavior takes place in the relevant testing environment, such as TradingView's Strategy Tester. There is no verified annual-return or win-rate result presented here.

What function should I use instead of ta.smma?

Use ta.rma for Wilder-style smoothing with alpha 1 / length, or write and inspect an explicit recurrence when you need different initialization or missing-value behavior.

Does SMMA guarantee fewer losing trades than EMA?

No. Their different weights change signals. Performance depends on the entire rule, data, and costs.

Are several SMMA lengths a multi-timeframe strategy?

Not by themselves. They use the same chart series unless the script explicitly requests other timeframes.

The Best Pine Script Generator