TAlib.Indicators.SAR (TAlib v0.13.0)

Copy Markdown View Source

Parabolic SAR Wikipedia.

The trend starts up when the second close is above the first, and the acceleration factor starts at af_start (default 0.02), stepping by af_step (default 0.02) on every new extreme, capped at af_max (default 0.2). Bars are maps with at least :high, :low and :close. See TAlib for the remaining conventions; values are defined from the second bar on.

Summary

Functions

Calculate the latest Parabolic SAR value.

The extended Parabolic SAR (TA-Lib SAREXT) with the standard start, step and maximum acceleration factors.

Calculate the full Parabolic SAR series.

Functions

sar(bars, af_start \\ 0.02, af_step \\ 0.02, af_max \\ 0.2)

@spec sar([map()], number(), number(), number()) :: number() | nil

Calculate the latest Parabolic SAR value.

Parameters

  • bars: list of bars, oldest first.
  • af_start: initial acceleration factor (default 0.02).
  • af_step: acceleration factor increment (default 0.02).
  • af_max: acceleration factor cap (default 0.2).

Examples

iex> bars = [
...>   %{high: 10, low: 9, close: 9.5},
...>   %{high: 11, low: 9.5, close: 10.5},
...>   %{high: 12, low: 10, close: 11.5},
...>   %{high: 11.5, low: 9.5, close: 10.0},
...>   %{high: 12.5, low: 10.5, close: 12.0}
...> ]
iex> TAlib.Indicators.SAR.sar(bars) |> Float.round(4)
9.2352

sar_ext(bars, af_start \\ 0.02, af_step \\ 0.02, af_max \\ 0.2)

@spec sar_ext([map()], number(), number(), number()) :: number() | nil

The extended Parabolic SAR (TA-Lib SAREXT) with the standard start, step and maximum acceleration factors.

iex> bars = [
...>   %{high: 10, low: 9, close: 9.5},
...>   %{high: 11, low: 9.5, close: 10.5},
...>   %{high: 12, low: 10, close: 11.5}
...> ]
iex> TAlib.Indicators.SAR.sar_ext(bars)
9

sar_ext_list(bars, af_start \\ 0.02, af_step \\ 0.02, af_max \\ 0.2)

sar_list(bars, af_start \\ 0.02, af_step \\ 0.02, af_max \\ 0.2)

@spec sar_list([map()], number(), number(), number()) :: [number() | nil]

Calculate the full Parabolic SAR series.

Returns a list aligned with bars: the first entry is nil (the trend needs two bars), every later entry is the SAR stop for that bar.

Parameters

  • bars: list of bars, oldest first.
  • af_start: initial acceleration factor (default 0.02).
  • af_step: acceleration factor increment (default 0.02).
  • af_max: acceleration factor cap (default 0.2).

Examples

iex> bars = [
...>   %{high: 10, low: 9, close: 9.5},
...>   %{high: 11, low: 9.5, close: 10.5},
...>   %{high: 12, low: 10, close: 11.5}
...> ]
iex> TAlib.Indicators.SAR.sar_list(bars)
[nil, 9, 9]