githubEdit

Simple Moving Average (SMA)

What It Is SMA calculates the arithmetic mean of closing prices over a specified number of periods. It smooths out price volatility to reveal underlying trends.

Formula

SMA = (P₁ + P₂ + ... + Pₙ) / n

Where:

  • n = number of periods (e.g., 9, 20, 50, 200)

  • P = closing price of each period

How It Works SMA gives equal weight to all prices in the calculation window. As new prices come in, the oldest price drops out of the calculation, creating a "rolling" average.

Example Calculation

Given this price data:

Period
Closing Price

1

20

2

22

3

21

4

23

5

24

6

26

5-Period SMA on Period 5:

SMA₅ = (20 + 22 + 21 + 23 + 24) / 5 = 110 / 5 = 22.0

Note: This can only be calculated after Period 5 closes, meaning the result is available on Period 6

5-Period SMA on Period 6:

Key Characteristics

  • Lag: SMA reacts slowly to sudden price changes because it averages all periods equally

  • Smoothness: Provides clean trend lines with minimal noise

  • Minimum Data: Requires n periods of data before calculation is possible

Reading Simple Moving Average (SMA) on Supra L1

Returns:

  • some(sma) if the indicator can be computed (scaled by DECIMAL_BUFFER)

  • none if insufficient history, invalid period, or tolerance exceeded

Parameters:

  • missing_candles_tolerance_percentage: Expressed with two-decimal precision (e.g., 5000 = 50.00%, 1000 = 10.00%)

Example:

Last updated