TAlib.Indicators.MFI (TAlib v0.13.0)

Copy Markdown View Source

Money Flow Index Wikipedia.

With the typical price TP = (high + low + close) / 3 and the raw money flow TP * volume, over the lookback window:

MFI = 100 - 100 / (1 + positive_flow / negative_flow)

Bars are maps with at least :high, :low, :close and :volume. See TAlib for the remaining conventions: chronological order, oldest first, series aligned with the input, nil when there is not enough data or the window has no movement.

Summary

Functions

Calculate the latest Money Flow Index.

Calculate the full Money Flow Index series.

Functions

mfi(bars, period \\ 14)

@spec mfi([map()], pos_integer()) :: float() | nil

Calculate the latest Money Flow Index.

Parameters

  • bars: list of bars, oldest first.
  • period: lookback window, a positive integer (default 14).

Examples

iex> bars = [
...>   %{high: 12, low: 8, close: 10, volume: 100},
...>   %{high: 13, low: 9, close: 12, volume: 200},
...>   %{high: 11, low: 9, close: 10, volume: 150}
...> ]
iex> TAlib.Indicators.MFI.mfi(bars, 2) |> Float.round(4)
60.177

mfi_list(bars, period \\ 14)

@spec mfi_list([map()], pos_integer()) :: [float() | nil]

Calculate the full Money Flow Index series.

Returns a list aligned with bars: the first period entries are nil, and every later entry is the MFI of the window ending at that point.

Parameters

  • bars: list of bars, oldest first.
  • period: lookback window, a positive integer (default 14).

Examples

iex> bars = [
...>   %{high: 12, low: 8, close: 10, volume: 100},
...>   %{high: 13, low: 9, close: 12, volume: 200},
...>   %{high: 11, low: 9, close: 10, volume: 150}
...> ]
iex> TAlib.Indicators.MFI.mfi_list(bars, 2) |> Enum.map(fn
...>   nil -> nil
...>   x -> Float.round(x, 4)
...> end)
[nil, nil, 60.177]