TAlib v0.3.6 TAlib.Indicators.MA

Moving Average indicator Wikipedia Calculate SMA, WMA, and EMA

Link to this section Summary

Functions

Calculate Cumulative Moving Average

Calculate Exponential Moving Average

Calculate a list of EMA

Calculate Simple Moving Average

Calculate a list of SMA

Update Cumulative Moving Average when new price comes

Update Exponential Moving Average when new price comes

Update Simple Moving Average when new price comes

Calculate Weighted Moving Average

Link to this section Functions

Link to this function

cma(prices, period \\ 50)

Calculate Cumulative Moving Average

Parameters

  • prices: List of prices, lates price is the first one in the list.
  • period: MA period to be calculated. It must be less than size of prices

Example

  iex> TAlib.Indicators.MA.cma([0,1,2,3],3)
  2.0
Link to this function

ema(prices, period \\ 50)

Calculate Exponential Moving Average

Parameters

  • prices: List of prices, lates price is the first one in the list.
  • period: MA period to be calculated. It must be equal or less than size of prices

Example

  iex> TAlib.Indicators.MA.ema([0,1,2,3],3)
  1.0
Link to this function

ema_list(prices, period \\ 50)
ema_list([float()], integer()) :: [float()]

Calculate a list of EMA

Parameters

  • prices: List of prices, lates price is the last one in the list.
  • period: MA period to be calculated. It must be equal or less than size of prices

Example

  iex> TAlib.Indicators.MA.ema_list(1330.95, 1334.65, ...] , 3)
  [nil, nil,  44.3289, 44.2096, 44.1796 ...]
Link to this function

sma(prices, period \\ 50)

Calculate Simple Moving Average

Parameters

  • prices: List of prices, lates price is the first one in the list.
  • period: MA period to be calculated. It must be equal or less than size of prices

Example

  iex> TAlib.Indicators.MA.sma([1,2,3,4],3)
  3.0
Link to this function

sma_list(prices, period \\ 50)
sma_list([float()], integer()) :: [float()]

Calculate a list of SMA

Parameters

  • prices: List of prices, lates price is the last one in the list.
  • period: MA period to be calculated. It must be equal or less than size of prices

Example

  iex> TAlib.Indicators.MA.sma_list(1330.95, 1334.65, ...] , 3)
  [nil, nil, 44.3289 ...]
Link to this function

update_cma(current_cma, new_value, period)

Update Cumulative Moving Average when new price comes

Parameters

  • current_cma: Previously calculated CMA
  • new_value: New price to be added in the list
  • period: MA period to be calculated.

Example

  iex> TAlib.Indicators.MA.update_cma(44.4513,44, 4)
  44.36104
Link to this function

update_ema(current_ema, new_value, period)

Update Exponential Moving Average when new price comes

Parameters

  • current_ema: Previously calculated EMA
  • new_value: New price to be added in the list
  • period: MA period to be calculated.

Example

  iex> TAlib.Indicators.MA.update_ema(1306.72, 1300, 50), 4)
  1306.456471
Link to this function

update_sma(prices, current_sma, new_value, period \\ 50)

Update Simple Moving Average when new price comes

Parameters

  • prices: List of prices, newest price is the first one in the list.
  • current_sma: Previously calculated SMA
  • new_value: New price to be added in the list
  • period: MA period to be calculated. It must be equal or less than size of prices

Example

  iex> TAlib.Indicators.MA.update_sma(@prices, 44.6028, 46.0826, 10), 4)
  44.6028
Link to this function

wma(prices, period \\ 50)

Calculate Weighted Moving Average

Parameters

  • prices: List of prices, lates price is the first one in the list.
  • period: MA period to be calculated. It must be equal or less than size of prices

Example

  iex> TAlib.Indicators.MA.wma([0,1,2,3],3)
  2.3333333333333335