Skip to main content

Simple Moving Average (SMA)

The SMA calculates the arithmetic mean of the last N periods of a specified price field.

Registration Name: "SMA"

Parameters:

  • period (required): Number of bars to average
  • field (required): Price field to use ("open", "high", "low", "close")

Returns: The average value over the specified period

registerIndicator("SMA", "BUILTIN", {
period: 20,
field: "close"
}, "SMA_20_CLOSE"); // Custom ID for this instance