---
title: Moving Averages
description: Trend-following indicators that smooth price data — SMA, EMA, and RMA help identify direction, support/resistance, and crossover signals.
---

## Overview

Trend-following indicators smooth price data over time. Moving averages help identify trend direction, support/resistance levels, and trading signals through crossovers and price interactions.

| Type | Description |
| --- | --- |
| **Simple Moving Average (SMA)** | Arithmetic mean of prices over a specified period. Equal weight is given to every data point. |
| **Exponential Moving Average (EMA)** | Weighted average that gives more importance to recent prices, making it more responsive to price changes. |
| **Running Moving Average (RMA)** | Modified exponential moving average using `alpha = 1 / period`, also known as Wilder's smoothing method. |

| Function | Description |
| --- | --- |
| [`sma`](#sma) | Simple Moving Average helper function |
| [`ema`](#ema) | Exponential Moving Average helper function |
| [`rma`](#rma) | Running Moving Average helper function |

<a id="sma"></a>

## sma - Simple Moving Average

`sma(source: TimeSeries, period?: number = 12, priceIndex?: number = 1): number` — Simple Moving Average.

| Parameter | Type | Description |
| --- | --- | --- |
| `source` | TimeSeries | Source data series |
| `period` | number | Number of periods for calculation (default: `12`) |
| `priceIndex` | number | Index of price data (default: `1`) |

**Returns:** `number` — moving average value at the current bar.

```javascript
//@version=2

timeseries trade = ohlcv(symbol=currentSymbol, exchange=currentExchange);
var data = sma(source=trade.close, period=20);
plotLine(value=data, width=2, colors=["green"], label=["SMA 20"], desc=["20-period Simple Moving Average"]);
```

<a id="ema"></a>

## ema - Exponential Moving Average

`ema(source: TimeSeries, period?: number = 12, priceIndex?: number = 1): number` — Exponential Moving Average.

| Parameter | Type | Description |
| --- | --- | --- |
| `source` | TimeSeries | Source data series |
| `period` | number | Number of periods for calculation (default: `12`) |
| `priceIndex` | number | Index of price data (default: `1`) |

**Returns:** `number` — exponential moving average value at the current bar.

```javascript
//@version=2

timeseries trade = ohlcv(symbol=currentSymbol, exchange=currentExchange);
var data = ema(source=trade.close, period=20);
plotLine(value=data, width=2, colors=["orange"], label=["EMA 20"], desc=["20-period Exponential Moving Average"]);
```

<a id="rma"></a>

## rma - Running Moving Average

`rma(source: TimeSeries, period?: number = 12, priceIndex?: number = 1): number` — Running Moving Average using Wilder's smoothing method.

| Parameter | Type | Description |
| --- | --- | --- |
| `source` | TimeSeries | Source data series |
| `period` | number | Number of periods for calculation (default: `12`) |
| `priceIndex` | number | Index of price data (default: `1`) |

**Returns:** `number` — running moving average value at the current bar.

```javascript
//@version=2

timeseries trade = ohlcv(symbol=currentSymbol, exchange=currentExchange);
var data = rma(source=trade.close, period=20);
plotLine(value=data, width=2, colors=["blue"], label=["RMA 20"], desc=["20-period Running Moving Average"]);
```

## Best Practices

<table data-view="cards"><tbody>
<tr><td>Period Selection</td><td>Common periods: <strong>20</strong> for short-term, <strong>50</strong> for medium-term, and <strong>200</strong> for long-term. Adjust based on trading timeframe and market volatility.</td><td></td></tr>
<tr><td>EMA vs SMA</td><td>Use EMA for faster signals in trending markets and SMA for smoother signals in ranging markets. EMA reacts quicker to price changes.</td><td></td></tr>
<tr><td>Confirmation</td><td>Combine moving averages with volume, RSI, or other indicators for stronger confirmation. Do not rely on a moving average alone.</td><td></td></tr>
<tr><td>False Signals</td><td>Moving averages lag price action. In choppy markets, use additional filters to reduce whipsaws and false breakouts.</td><td></td></tr>
</tbody></table>
