Python API reference / 2.2.1

Technical indicators

Try it in Python

Compute a three-bar simple moving average of closing prices. The first two results are None because there are fewer than three observations.

from pricegenerator.indicators import SMA

print(SMA([100.0, 101.0, 102.0, 99.0], period=3))

pricegenerator.indicators

Compute technical indicators for an ordered price series. A period counts observed bars, even across a gap in trading. Each output keeps one position per input bar, with None where a value is undefined.

IndicatorSeries

One named indicator series, aligned with the input bars. Read values[i] for the value on bar i and, when supplied, reasons[i] for the reason it is missing. The standard report distinguishes warm-up bars from inactive PSAR directions and unconfirmed ZigZag pivots.

IndicatorSeries(
    key: str,
    label: str,
    values: tuple[float | None, ...],
    group: str,
    kind: str = 'line',
    reasons: tuple[str | None, ...] = (),
)
Fields (6)
key
Stable identifier for a series, distinct from its human-readable label.
label
Human-readable name of an indicator or overlay, used in chart legends and controls.
values
Computed indicator values aligned with the input bars. None marks a warm-up bar, an inactive series or another undefined reading. Consult reasons for the explanation.
group
Name used to toggle related indicator or overlay series together in the HTML chart.
kind
Drawing style, either line for a connected line or points for individual markers.
reasons
Per-bar explanations corresponding to missing indicator values. The standard report uses None on bars with a reading. The sequence may be omitted on a custom series.

Source ↗

IndicatorReport

The collection returned by Indicators. Use series for the aligned values, graphics groups and gap explanations, and notes for the calculation conventions. It can be serialized independently of the input OHLCV table.

IndicatorReport(series: tuple[IndicatorSeries, ...], notes: tuple[str, ...])
Fields (2)
series
IndicatorSeries records containing the numeric series, chart groups and per-bar explanations for gaps.
notes
Calculation conventions that accompany the indicator results, including warm-up, shifts and pivot confirmation.

Source ↗

IndicatorReport.ToDict

Return a detached dictionary with the series records and calculation notes. Use it to inspect individual values or extract explanations for gaps.

IndicatorReport.ToDict() -> dict

Source ↗

IndicatorReport.ToJSON

Return a compact JSON string with stable key ordering. Missing indicator readings are JSON null. This method writes no file.

IndicatorReport.ToJSON() -> str

Source ↗

SMA

Return one simple moving average per observation. Each value is the arithmetic mean of the last period observations including the current one. An incomplete window or a window containing missing data yields None.

SMA(values, period: int) -> tuple[float | None, ...]
Parameters (2)
values
Input observations in time order, one real number or missing value per bar. None, NaN and pandas.NA denote missing observations. Infinity is rejected.
period
Positive whole number of observations in the trailing calculation window, including the current observation.

Source ↗

WMA

Return a linearly weighted moving average over each complete trailing window. The oldest observation has weight 1 and the newest has weight period. The result has one entry per input, with None for incomplete windows or windows with gaps.

WMA(values, period: int) -> tuple[float | None, ...]
Parameters (2)
values
Input observations in time order, one real number or missing value per bar. None, NaN and pandas.NA denote missing observations. Infinity is rejected.
period
Positive whole number of observations in the trailing calculation window, including the current observation.

Source ↗

HMA

Return Hull’s moving average on the original bars. Compute 2 × WMA(n/2) − WMA(n), then smooth that difference with WMA(√n). Both shorter window lengths are rounded down to at least one bar. With complete input, the first value is available after n + floor(√n) − 1 observations.

HMA(values, period: int) -> tuple[float | None, ...]
Parameters (2)
values
Input observations in time order, one real number or missing value per bar. None, NaN and pandas.NA denote missing observations. Infinity is rejected.
period
Positive whole number of observations in the trailing calculation window, including the current observation.

Source ↗

VWMA

Return a moving average weighted by bar volume, calculated as the sum of price × volume divided by total volume over the same window. Weights must be nonnegative and aligned with prices. A missing input, incomplete window or zero total volume gives None at that bar.

VWMA(values, volume, period: int) -> tuple[float | None, ...]
Parameters (3)
values
Input observations in time order, one real number or missing value per bar. None, NaN and pandas.NA denote missing observations. Infinity is rejected.
volume
One nonnegative trading volume per observation, in the same order as the prices. The values serve as weights.
period
Positive whole number of observations in the trailing calculation window, including the current observation.

Source ↗

Bollinger

Return three aligned series in the order lower band, middle band, upper band. The middle band is the trailing SMA. Each outer band lies deviations population standard deviations from it (ddof=0). Defaults are 20 observations and two standard deviations. Incomplete windows yield None.

Bollinger(
    values,
    period: int = 20,
    deviations: float = 2.0,
) -> tuple[tuple[float | None, ...], ...]
Parameters (3)
values
Input observations in time order, one real number or missing value per bar. None, NaN and pandas.NA denote missing observations. Infinity is rejected.
period
Positive whole number of observations in the trailing calculation window, including the current observation.
deviations
Nonnegative multiplier for the population standard deviation in each Bollinger window. At the default 2.0, the bands are two standard deviations from the mean.

Source ↗

SmoothedMA

Return a smoothed moving average (SMMA). Start each uninterrupted run with an SMA over period observations. Subsequent values equal the previous average plus (current − previous average) / period. A missing value restarts the warm-up.

SmoothedMA(values, period: int) -> tuple[float | None, ...]
Parameters (2)
values
Input observations in time order, one real number or missing value per bar. None, NaN and pandas.NA denote missing observations. Infinity is rejected.
period
Positive whole number of observations in the trailing calculation window, including the current observation.

Source ↗

Alligator

Return the Alligator’s jaw, teeth and lips, in that order. Each is an SMMA of (high + low) / 2. Their periods are 13, 8 and 5 bars and their values are plotted 8, 5 and 3 bars later, respectively, within the supplied timeline. The shifted endpoints do not create extra candles.

Alligator(high, low) -> tuple[tuple[float | None, ...], ...]
Parameters (2)
high
Sequence of per-bar high prices, aligned with low. A high must be at least the low for that bar.
low
Sequence of per-bar low prices, aligned with high. A low must be no greater than the high for that bar.

Source ↗

PSAR

Return two aligned Parabolic SAR series, first for an uptrend and then for a downtrend. Only the active side has a value. Direction is initialized from two consecutive bars and a missing high or low restarts it. In a rising trend the SAR is capped at the prior two lows, with the opposite rule in a falling trend. A reversal requires trading through the SAR.

PSAR(
    high,
    low,
    *,
    step: float = 0.02,
    maximum: float = 0.2,
) -> tuple[tuple[float | None, ...], ...]
Parameters (4)
high
Sequence of per-bar high prices, aligned with low. A high must be at least the low for that bar.
low
Sequence of per-bar low prices, aligned with high. A low must be no greater than the high for that bar.
step
Initial SAR acceleration factor and the increment applied when the trend reaches a new extreme. Must be positive and no greater than maximum.
maximum
Upper bound on the SAR acceleration factor, from step through 1 inclusive.

Source ↗

ZigZag

Return confirmed turning prices at their original bar positions and None elsewhere. A later move of at least deviation in the opposite direction confirms a pivot. The final candidate remains absent. In a backtest, the plotted bar predates confirmation. Any missing or nonpositive input makes the entire result undefined.

ZigZag(values, deviation: float = 0.05) -> tuple[float | None, ...]
Parameters (2)
values
Input observations in time order, one real number or missing value per bar. None, NaN and pandas.NA denote missing observations. Infinity is rejected.
deviation
Minimum relative reversal from the current extreme needed to confirm a ZigZag pivot. Use a fraction strictly between 0 and 1, for example 0.05 for 5%.

Source ↗

Indicators

Validate an OHLCV table and return an IndicatorReport with 17 series. It includes SMA at 5, 20, 50 and 200 bars, HMA and VWMA at 5 and 20, Bollinger bands, Parabolic SAR, Alligator and confirmed ZigZag pivots. Each series carries a reason for each missing value.

Indicators(frame, *, zigzag_deviation: float = 0.05) -> IndicatorReport
Parameters (2)
frame
OHLCV DataFrame with datetime, open, high, low, close and volume columns. Rows must be ordered in time and pass the package’s market-data checks.
zigzag_deviation
Relative reversal threshold for the ZigZag series, strictly between 0 and 1. The default 0.05 requires a 5% move from the extreme.

Source ↗ Available through pricegenerator.Indicators