Simple Moving Average


A Simple Moving Average (SMA) is the unweighted mean of the previous n data points. In technical analysis there are various popular values for n, like 10 days, 40 days, or 200 days. The period selected depends on the kind of movement one is concentrating on, such as short, intermediate, or long term. In any case moving average levels are interpreted as support in a rising market, or resistance in a falling market.

AnyChart Stock allows you to add SMA with desired period to any of your charts.

Mathematical description of the indicator: Simple moving average (SMA) Mathematical Description.

Adding Indicator

SMA indicator is added using sma() method, it requires a mapping with the "value" field in it:

// create data table on loaded data
var dataTable =;

// add data to a table

// map loaded data
var mapping = dataTable.mapAs({'value': 4});

// create stock chart
chart = anychart.stock();

// create plot on the chart
var plot = chart.plot(0);

// create SMA indicators with period 20
var sma20 = plot.sma(mapping, 20).series();

Here is a live sample:


Indicator Parameters

SMA indicator needs three parameters: mapping with the "value" field in it, period and a type of series to be displayed as:

var sma10 = plot.sma(mapping, 10, "column");


Vizualization of an indicator depends on the type of a series you display it with. Here is a sample where SMA with different parameters and settings is added to different plots:

// create SMA indicator with period 20 and show as line on the first plot
var sma20 = plot_0.sma(mapping, 20).series();

// create SMA indicator with period 50 and show as column on the second plot
var sma50 = plot_1.sma(mapping, 50, "column").series();

Live sample: