Files
xMQL4/Docs/Samples/SMA.md
T
2024-01-25 04:03:36 +03:30

1.1 KiB

SMA

Simple Moving Average

Resource 1

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

double sma = iMA(_Symbol, _Period, numOfCandles, 0, MODE_SMA, PRICE_CLOSE, 0)

Calculation process

pine_sma(source, length) =>
    sum = 0.0
    for i = 0 to length - 1
        sum += source[i] / length
    sum

plot(pine_sma(close, 15))