Tool
Moving Average
market.moving_average
Inputs
No typed inputs.
Outputs
A single smoothed price line, one value per bar, plotted on the same scale as price.
A moving average smooths price into a single trend line by averaging the last N bars. Traders use it to see the underlying direction without the bar-to-bar noise, and to spot when price pulls back to or crosses the line.
How it works
Over a rolling window (the period, default 14 bars) it averages the chosen price (close by default) into one value per bar. The mode picks how those bars are weighted: a simple average treats them equally, while exponential and Hull variants weight recent bars more so the line turns faster.
Modes
Mode options
Averages the last N bars with equal weight. The smoothest, slowest-turning line.
When to use: Use when you want a stable view of the trend and don't mind extra lag.
Weights recent bars more heavily, so the line tracks price with less lag than SMA.
When to use: Use when you want a responsive trend line that reacts faster to turns.
Weights bars linearly, newest gets the most weight. Sits between SMA and EMA in responsiveness.
When to use: Use when you want recent bars to count more, but a smoother shape than EMA.
A double-exponential construction that subtracts lag, hugging price closer than EMA.
When to use: Use when EMA still lags too much and you want the line nearer to price.
A triple-exponential construction that removes even more lag than DEMA, tracking price very closely.
When to use: Use when you want the least-lagging average and can tolerate more wiggle.
The Hull moving average is built to be both smooth and very responsive, turning quickly with little lag.
When to use: Use when you want fast turns and a smooth line, accepting occasional overshoot.
Source options
Average each bar's open price.
When to use: Use open when that price best reflects the move you trade.
Average each bar's high price.
When to use: Use high when that price best reflects the move you trade.
Average each bar's low price.
When to use: Use low when that price best reflects the move you trade.
Average each bar's close price. The usual choice.
When to use: Use close when that price best reflects the move you trade (the default).
Average the median price, the midpoint of each bar's high and low.
When to use: Use the median when you want to ignore where price opened and closed.
Average the typical price, the mean of each bar's high, low, and close.
When to use: Use the typical price when you want close to count alongside the bar's range.
Average the OHLC4 price, the mean of each bar's open, high, low, and close.
When to use: Use the average price for the smoothest, most balanced input across the whole bar.
Configuration
Which averaging method to use: sma (simple, equal weight), ema (exponential, recent-weighted), wma (linear-weighted), dema / tema (double / triple EMA, less lag), or hma (Hull, very responsive).
How many bars to average over. Larger = smoother and slower; smaller = faster and noisier. 14 is a common default.
Which price each bar contributes: open, high, low, close, hl2 (median), hlc3 (typical), or ohlc4 (average). Close is the usual choice.
Connects to
Examples
- Wire close and a 50-period EMA into calc.cross to fire when price crosses the average.
- Filter: only take longs when a fast MA sits above a slow MA (stack the trend).
Common mistakes
- Using too short a period, which makes the line whippy and produces constant false crosses.
- Treating every cross of the line as a signal in a sideways market, where price chops back and forth across it.