Files
2024-01-25 04:03:36 +03:30

36 lines
1.1 KiB
Markdown

# SMA
Simple Moving Average
[Resource 1](https://www.investopedia.com/terms/s/sma.asp)
A simple moving average (SMA) calculates the average of a selected range of prices, usually closing prices, by the number of periods in that range.
Simple moving averages calculate the average of a range of prices by the number of periods within that range.
A simple moving average is a technical indicator that can aid in determining if an asset price will continue or if it will reverse a bull or bear trend.
A simple moving average can be enhanced as an exponential moving average (EMA) that is more heavily weighted on recent price action.
## Formula
SMA = (A1 + A2 + ... + An) / n
An = price of an asset at period n
n = the number of total periods
[Tutorial](https://mql4tutorial.com/mql4-tutorial-english/mql4-tutorial-basics-11-how-to-calculate-a-simple-moving-average)
```mq4
double sma = iMA(_Symbol, _Period, numOfCandles, 0, MODE_SMA, PRICE_CLOSE, 0)
```
## Calculation process
```pine
pine_sma(source, length) =>
sum = 0.0
for i = 0 to length - 1
sum += source[i] / length
sum
plot(pine_sma(close, 15))
```