sma

Simple Moving Average

sma(source, periods)

Parameters

Name Type Description
source field Data series
periods int Number of bars

Formula

SMA = Σ(values) / periods

Examples

// price above 20-day SMA (uptrend)
close > sma(close, 20);
// volume above 50-day average
volume > sma(volume, 50);
// price crossed above 200-day SMA (bullish)
crossover(close, sma(close, 200));
// short SMA above long SMA (golden cross)
sma(close, 50) > sma(close, 200);

Returns

float — may be NULL

Range

periods must be 2-400

Notes

No value for the first periods-1 bars: NULL until the window holds periods non-NULL values, matching ema()'s lookback for the same period