Simple Moving Averange
Syntax
Description
The sma
function calculates the Simple Moving Average (SMA) for a given symbol over a specified period. The function can also be applied directly to an array of numerical data to calculate the SMA. The SMA is a widely used technical indicator that smooths out price data by creating a constantly updated average price.
Returns
The sma function returns a single SMA value by default. If the rolling option is specified, it returns an array of SMA values for the specified rolling period.
Parameters
len
: The length of the period over which to calculate the SMA.symbol
: The symbol for which to calculate the SMA.options
? (optional): An object with the following optional properties:rolling
: The number of days for which to return the SMA values. If specified, an array of SMA values is returned.offset
: The number of days ago to start the calculation. Default is 0 (current day).prop
: The property of the data to use for calculation. Default is'close'
. This option is only applicable when using with symbol.
Examples
Using symbol and length
Using Data:
Notes
- The sma function is a fundamental tool in technical analysis, providing insight into market trends by smoothing out price fluctuations.
- When using the rolling option, the returned array of SMA values can help in analyzing recent price movements and detecting short-term trends.
- The offset option is useful for backtesting strategies and analyzing historical data by calculating the SMA from a specific point in time.