Simple Moving Average (SMA)

Calculates the average of a selected range of prices, usually closing prices, by the number of periods in that range. (credit to Investopia)

import { Ticker, TechnicalAnalysisLibrary } from 'traders';

const ticker = new Ticker('V');

const data = await ticker.historical('1d', '2021-03-01', '2021-03-17');

const ta = new TechnicalAnalysisLibrary();

try {
  const result = ta.SMA(5, data);
} catch (error) {
  console.log(error);
}
# Example of SMA result
# Visa daily closing price from 2021-03-01 to 2021-03-17
[
  214.83, 215.56,
  216.48, 218.14,
  221.07, 222.86,
  223.46, 224.33
]

Last updated