Skip to content
Algo Trade Analytics Docs

ta.sma() - Pine Script Function

The sma function returns the moving average, that is the sum of last y values of x, divided by y.

ta.sma(source, length) → series float
NameTypeDescription
sourceseries int/floatSeries of values to process.

Simple moving average of source for length bars back.

  • na values in the source series are ignored.
//@version=6
indicator("ta.sma")
plot(ta.sma(close, 15))// same on pine, but much less efficientpine_sma(x, y) => sum = 0.0
for i = 0 to y - 1 sum := sum + x[i] / y sum
plot(pine_sma(close, 15))