ta.sma() - Pine Script Function
ta.sma()
Section titled “ta.sma()”Overview
Section titled “Overview”The sma function returns the moving average, that is the sum of last y values of x, divided by y.
Syntax
Section titled “Syntax”ta.sma(source, length) → series floatParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| source | series int/float | Series of values to process. |
Returns
Section titled “Returns”Simple moving average of source for length bars back.
Remarks
Section titled “Remarks”- na values in the source series are ignored.
Examples
Section titled “Examples”Example 1
Section titled “Example 1”//@version=6indicator("ta.sma")plot(ta.sma(close, 15))// same on pine, but much less efficientpine_sma(x, y) => sum = 0.0for i = 0 to y - 1 sum := sum + x[i] / y sumplot(pine_sma(close, 15))