Overview
The Simple Moving Average (SMA) is one of the most commonly used technical indicators in financial markets. It calculates the average value of a given data series (such as price) over a specific period, smoothing out short-term fluctuations to identify trends.
Syntax
const period = 9;
const src = "open"
const sma = new I.SMA([period], src)
Parameters
- period (Integer):
- Defines the number of data points to consider when calculating the average.
- Example: A period of 9 will calculate the average of the last 9 data points.
- src (String):
- Specifies the data source for the SMA calculation.
- Options include: "open", "close", "high", "low", or any other applicable field.
- Default: "open"
Returns
The SMA object provides the calculated moving average for each data point in the series. The first few values of the SMA array may be undefined if insufficient data points exist to complete the specified period.
Use Cases
- Trend Identification:
- A rising SMA suggests an uptrend, while a falling SMA indicates a downtrend.
- Support and Resistance:
- Prices often respect SMA lines as dynamic support or resistance levels.