Skip to content

Latest commit

 

History

History
2864 lines (2068 loc) · 85 KB

File metadata and controls

2864 lines (2068 loc) · 85 KB

trend

import "github.com/cinar/indicator/v2/trend"

Package trend contains the trend indicator functions.

This package belongs to the Indicator project. Indicator is a Golang module that supplies a variety of technical indicators, strategies, and a backtesting framework for analysis.

License

Copyright (c) 2021-2026 Onur Cinar.
The source code is provided under GNU AGPLv3 License.
https://github.com/cinar/indicator

Disclaimer

The information provided on this project is strictly for informational purposes and is not to be construed as advice or solicitation to buy or sell any security.

Index

Constants

const (
    // DefaultApoFastPeriod is the default APO fast period of 14.
    DefaultApoFastPeriod = 14

    // DefaultApoFastSmoothing is the default APO fast smoothing.
    DefaultApoFastSmoothing = DefaultEmaSmoothing

    // DefaultApoSlowPeriod is the default APO slow period of 30.
    DefaultApoSlowPeriod = 30

    // DefaultApoSlowSmoothing is the default APO slow smoothing.
    DefaultApoSlowSmoothing = DefaultEmaSmoothing
)

const (
    // DefaultEmaPeriod is the default EMA period of 20.
    DefaultEmaPeriod = 20

    // DefaultEmaSmoothing is the default EMA smooting of 2.
    DefaultEmaSmoothing = 2
)

const (
    // DefaultEnvelopePercentage is the default envelope percentage of 20%.
    DefaultEnvelopePercentage = 20

    // DefaultEnvelopePeriod is the default envelope period of 20.
    DefaultEnvelopePeriod = 20
)

const (
    // DefaultKamaErPeriod is the default Efficiency Ratio (ER) period of 10.
    DefaultKamaErPeriod = 10

    // DefaultKamaFastScPeriod is the default Fast Smoothing Constant (SC) period of 2.
    DefaultKamaFastScPeriod = 2

    // DefaultKamaSlowScPeriod is the default Slow Smoothing Constant (SC) period of 30.
    DefaultKamaSlowScPeriod = 30
)

const (
    // DefaultKdjMinMaxPeriod is the default period for moving min
    // of low, and moving max of high.
    DefaultKdjMinMaxPeriod = 9

    // DefaultKdjSma1Period is the default period for SMA of RSV.
    DefaultKdjSma1Period = 3

    // DefaultKdjSma2Period is the default period for SMA of K.
    DefaultKdjSma2Period = 3
)

const (
    // DefaultKstRocPeriod1 is the default first ROC period.
    DefaultKstRocPeriod1 = 10

    // DefaultKstRocPeriod2 is the default second ROC period.
    DefaultKstRocPeriod2 = 15

    // DefaultKstRocPeriod3 is the default third ROC period.
    DefaultKstRocPeriod3 = 20

    // DefaultKstRocPeriod4 is the default fourth ROC period.
    DefaultKstRocPeriod4 = 30

    // DefaultKstSmaPeriod1 is the default first SMA period for smoothing.
    DefaultKstSmaPeriod1 = 10

    // DefaultKstSmaPeriod2 is the default second SMA period for smoothing.
    DefaultKstSmaPeriod2 = 10

    // DefaultKstSmaPeriod3 is the default third SMA period for smoothing.
    DefaultKstSmaPeriod3 = 10

    // DefaultKstSmaPeriod4 is the default fourth SMA period for smoothing.
    DefaultKstSmaPeriod4 = 15

    // DefaultKstSignalPeriod is the default signal line period.
    DefaultKstSignalPeriod = 9
)

const (
    // DefaultMacdPeriod1 is the period for the first EMA.
    DefaultMacdPeriod1 = 12

    // DefaultMacdPeriod2 is the period for the second EMA.
    DefaultMacdPeriod2 = 26

    // DefaultMacdPeriod3 is the period for the third EMA.
    DefaultMacdPeriod3 = 9
)

const (
    // DefaultMassIndexPeriod1 is the period for the first EMA.
    DefaultMassIndexPeriod1 = 9

    // DefaultMassIndexPeriod2 is the period for the second EMA.
    DefaultMassIndexPeriod2 = 9

    // DefaultMassIndexPeriod3 is the period for the third MovingSum.
    DefaultMassIndexPeriod3 = 25
)

const (
    // DefaultSlowStochasticPeriod is the default period for the Slow Stochastic indicator.
    DefaultSlowStochasticPeriod = 10

    // DefaultSlowStochasticKPeriod is the default period for the Fast %K SMA smoothing.
    DefaultSlowStochasticKPeriod = 3

    // DefaultSlowStochasticDPeriod is the default period for the Slow %D SMA.
    DefaultSlowStochasticDPeriod = 3
)

const (
    // DefaultStcFastPeriod is the default fast EMA period for STC.
    DefaultStcFastPeriod = 23

    // DefaultStcSlowPeriod is the default slow EMA period for STC.
    DefaultStcSlowPeriod = 50

    // DefaultStcKPeriod is the default period for the Stochastic %K.
    DefaultStcKPeriod = 10

    // DefaultStcDPeriod is the default period for the Stochastic %D.
    DefaultStcDPeriod = 3
)

const (
    // DefaultStochasticPeriod is the default period for the Stochastic indicator.
    DefaultStochasticPeriod = 10

    // DefaultStochasticSmaPeriod is the default period for the SMA of %K.
    DefaultStochasticSmaPeriod = 3
)

const (
    // DefaultT3Period is the default period for the T3 Moving Average.
    DefaultT3Period = 5

    // DefaultT3VolumeFactor is the default volume factor for T3.
    DefaultT3VolumeFactor = 0.7
)

const (
    // DefaultTsiFirstSmoothingPeriod is the default first smoothing period of 25.
    DefaultTsiFirstSmoothingPeriod = 25

    // DefaultTsiSecondSmoothingPeriod is the default second smoothing period of 13.
    DefaultTsiSecondSmoothingPeriod = 13
)

const (
    // DefaultAroonPeriod is the default Aroon period of 25.
    DefaultAroonPeriod = 25
)

const (
    // DefaultCciPeriod is the default time period for CCI.
    DefaultCciPeriod = 20
)

const (
    // DefaultCfoPeriod is the default CFO period of 14.
    DefaultCfoPeriod = 14
)

DefaultDpoPeriod is the default period for DPO calculation.

const DefaultDpoPeriod = 20

const (
    // DefaultMcGinleyDynamicPeriod is the default period for the McGinley Dynamic.
    DefaultMcGinleyDynamicPeriod = 14
)

const (
    // DefaultRmaPeriod is the default RMA period.
    DefaultRmaPeriod = 20
)

const (
    // DefaultRocPeriod is the default ROC period.
    DefaultRocPeriod = 9
)

const (
    // DefaultSmaPeriod is the default SMA period.
    DefaultSmaPeriod = 50
)

const (
    // DefaultSmmaPeriod is the default SMMA period of 7.
    DefaultSmmaPeriod = 7
)

const (
    // DefaultTrimaPeriod is the default period for TRIMA.
    DefaultTrimaPeriod = 15
)

const (
    // DefaultTrixPeriod is the default time period for TRIX.
    DefaultTrixPeriod = 15
)

const (
    // DefaultVwmaPeriod is the default period for the VWMA.
    DefaultVwmaPeriod = 20
)

type Apo

Apo represents the configuration parameters for calculating the Absolute Price Oscillator (APO). An APO value crossing above zero suggests a bullish trend, while crossing below zero indicates a bearish trend. Positive APO values signify an upward trend, while negative values signify a downward trend.

Fast = Ema(values, fastPeriod)
Slow = Ema(values, slowPeriod)
APO = Fast - Slow

Example:

apo := trend.NewApo[float64]()
apo.FastPeriod = 12
apo.SlowPeriod = 26

result := apo.Compute(c)
type Apo[T helper.Number] struct {
    // Fast period.
    FastPeriod int

    // Fast smoothing.
    FastSmoothing T

    // Slow period.
    SlowPeriod int

    // Slow smoothing.
    SlowSmoothing T
}

func NewApo

func NewApo[T helper.Number]() *Apo[T]

NewApo function initializes a new APO instance with the default parameters.

func (*Apo[T]) Compute

func (apo *Apo[T]) Compute(c <-chan T) <-chan T

Compute function takes a channel of numbers and computes the APO over the specified period.

func (*Apo[T]) IdlePeriod

func (apo *Apo[T]) IdlePeriod() int

IdlePeriod is the initial period that APO won't yield any results.

type Aroon

Aroon represent the configuration for calculating the Aroon indicator. It is a technical analysis tool that gauges trend direction and strength in asset prices. It comprises two lines: Aroon Up and Aroon Down. Aroon Up measures uptrend strength, while Aroon Down measures downtrend strength. When Aroon Up exceeds Aroon Down, it suggests a bullish trend; when Aroon Down surpasses Aroon Up, it indicates a bearish trend.

Aroon Up = ((25 - Period Since Last 25 Period High) / 25) * 100
Aroon Down = ((25 - Period Since Last 25 Period Low) / 25) * 100

Example:

aroon := trend.NewAroon[float64]()
aroon.Period = 25

result := aroon.Compute(c)
type Aroon[T helper.Number] struct {
    // Period is the period to use.
    Period int
}

func NewAroon[T helper.Number]() *Aroon[T]

NewAroon function initializes a new Aroon instance with the default parameters.

func (*Aroon[T]) Compute

func (a *Aroon[T]) Compute(high, low <-chan T) (<-chan T, <-chan T)

Compute function takes a channel of numbers and computes the Aroon over the specified period.

type Bop

Bop gauges the strength of buying and selling forces using the Balance of Power (BoP) indicator. A positive BoP value suggests an upward trend, while a negative value indicates a downward trend. A BoP value of zero implies equilibrium between the two forces.

Formula: BOP = (Closing - Opening) / (High - Low)
type Bop[T helper.Number] struct{}

func NewBop

func NewBop[T helper.Number]() *Bop[T]

NewBop function initializes a new BOP instance with the default parameters.

func (*Bop[T]) Compute

func (*Bop[T]) Compute(opening, high, low, closing <-chan T) <-chan T

Compute processes a channel of open, high, low, and close values, computing the BOP for each entry.

type Cci

Cci represents the configuration parameters for calculating the Commodity Channel Index (CCI). CCI is a momentum-based oscillator used to help determine when an investment vehicle is reaching a condition of being overbought or oversold.

Moving Average = Sma(Period, Typical Price)
Mean Deviation = Sma(Period, Abs(Typical Price - Moving Average))
CCI = (Typical Price - Moving Average) / (0.015 * Mean Deviation)

Example:

cmi := trend.NewCmi()
cmi.Period = 20
values = cmi.Compute(highs, lows, closings)
type Cci[T helper.Number] struct {
    // Time period.
    Period int
}

func NewCci

func NewCci[T helper.Number]() *Cci[T]

NewCci function initializes a new CCI instance with the default parameters.

func NewCciWithPeriod[T helper.Number](period int) *Cci[T]

NewCciWithPeriod function initializes a new CCI instance with the given period.

func (*Cci[T]) Compute

func (c *Cci[T]) Compute(highs, lows, closings <-chan T) <-chan T

Compute function takes a channel of numbers and computes the CCI and the signal line.

func (*Cci[T]) IdlePeriod

func (c *Cci[T]) IdlePeriod() int

IdlePeriod is the initial period that CCI won't yield any results.

type Cfo

Cfo represents the configuration parameters for calculating the Chande Forecast Oscillator (CFO). CFO is a momentum indicator that measures the difference between a security's price and its linear regression forecast.

CFO = ((Price - Forecast) / Price) * 100

Example:

cfo := trend.NewCfo[float64]()
result := cfo.Compute(c)
type Cfo[T helper.Number] struct {
    // Mlr is the Moving Linear Regression instance.
    Mlr *Mlr[T]
}

func NewCfo

func NewCfo[T helper.Number]() *Cfo[T]

NewCfo function initializes a new CFO instance with the default parameters.

func NewCfoWithPeriod[T helper.Number](period int) *Cfo[T]

NewCfoWithPeriod function initializes a new CFO instance with the given period.

func (*Cfo[T]) Compute

func (c *Cfo[T]) Compute(closing <-chan T) <-chan T

Compute function takes a channel of numbers and computes the CFO.

func (*Cfo[T]) IdlePeriod

func (c *Cfo[T]) IdlePeriod() int

IdlePeriod is the initial period that CFO won't yield any results.

type Dema

Dema represents the parameters for calculating the Double Exponential Moving Average (DEMA). A bullish cross occurs when DEMA with 5 days period moves above DEMA with 35 days period. A bearish cross occurs when DEMA with 35 days period moves above DEMA With 5 days period.

DEMA = (2 * EMA1(values)) - EMA2(EMA1(values))

Example:

dema := trend.NewDema[float64]()
dema.Ema1.Period = 10
dema.Ema2.Period = 16

result := dema.Compute(input)
type Dema[T helper.Number] struct {
    // Ema1 represents the configuration parameters for
    // calculating the first EMA.
    Ema1 *Ema[T]

    // Ema2 represents the configuration parameters for
    // calculating the second EMA.
    Ema2 *Ema[T]
}

func NewDema

func NewDema[T helper.Number]() *Dema[T]

NewDema function initializes a new DEMA instance with the default parameters.

func (*Dema[T]) Compute

func (d *Dema[T]) Compute(c <-chan T) <-chan T

Compute function takes a channel of numbers and computes the DEMA over the specified period.

func (*Dema[T]) IdlePeriod

func (d *Dema[T]) IdlePeriod() int

IdlePeriod is the initial period that DEMA won't yield any results.

type Dpo

Dpo computes the Detrended Price Oscillator. Formula (common approximation): Let k = floor(period/2) + 1. For time index t >= period-1+k:

DPO[t] = Price[t] - SMA[t - k]

Example:

dpo := trend.NewDpoWithPeriod[float64](20)
out := dpo.Compute(c)
type Dpo[T helper.Float] struct {
    // contains filtered or unexported fields
}

func NewDpo

func NewDpo[T helper.Float]() *Dpo[T]

NewDpo creates a new DPO instance with default parameters.

func NewDpoWithPeriod[T helper.Float](period int) *Dpo[T]

NewDpoWithPeriod initializes a new DPO instance with the given period. Periods <= 1 are clamped to DefaultDpoPeriod.

func (*Dpo[T]) Compute

func (d *Dpo[T]) Compute(closing <-chan T) <-chan T

Compute calculates the DPO indicator over the input price channel.

func (*Dpo[T]) IdlePeriod

func (d *Dpo[T]) IdlePeriod() int

IdlePeriod returns the number of leading samples to discard before the first DPO value is available.

func (*Dpo[T]) String

func (d *Dpo[T]) String() string

String is the string representation of the DPO.

type Ema

Ema represents the parameters for calculating the Exponential Moving Average.

Example:

ema := trend.NewEma[float64]()
ema.Period = 10

result := ema.Compute(c)
type Ema[T helper.Number] struct {
    // Time period.
    Period int

    // Smoothing constant.
    Smoothing T
}

func NewEma

func NewEma[T helper.Number]() *Ema[T]

NewEma function initializes a new EMA instance with the default parameters.

func NewEmaWithPeriod[T helper.Number](period int) *Ema[T]

NewEmaWithPeriod function initializes a new EMA instance with the given period.

func (*Ema[T]) Compute

func (e *Ema[T]) Compute(c <-chan T) <-chan T

Compute function takes a channel of numbers and computes the EMA over the specified period.

func (*Ema[T]) IdlePeriod

func (e *Ema[T]) IdlePeriod() int

IdlePeriod is the initial period that EMA yield any results.

func (*Ema[T]) String

func (e *Ema[T]) String() string

String is the string representation of the EMA.

Envelope represents the parameters neededd to calcualte the Envelope.

type Envelope[T helper.Number] struct {
    // Ma is the moving average used.
    Ma  Ma[T]

    // Percentage is the envelope percentage.
    Percentage T
}

func NewEnvelope[T helper.Number](ma Ma[T], percentage T) *Envelope[T]

NewEnvelope function initializes a new Envelope instance with the default parameters.

func NewEnvelopeWithEma[T helper.Number]() *Envelope[T]

NewEnvelopeWithEma function initializes a new Envelope instance using EMA.

func NewEnvelopeWithSma[T helper.Number]() *Envelope[T]

NewEnvelopeWithSma function initalizes a new Envelope instance using SMA.

func (*Envelope[T]) Compute

func (e *Envelope[T]) Compute(closings <-chan T) (<-chan T, <-chan T, <-chan T)

Compute function takes a channel of numbers and computes the Envelope over the specified period.

func (*Envelope[T]) IdlePeriod

func (e *Envelope[T]) IdlePeriod() int

IdlePeriod is the initial period that Envelope yield any results.

func (*Envelope[T]) String

func (e *Envelope[T]) String() string

String is the string representation of the Envelope.

type Hma

Hma represents the configuration parameters for calculating the Hull Moving Average (HMA). Developed by Alan Hull in 2005, HMA attempts to minimize the lag of a traditional moving average.

WMA1 = WMA(period/2 , values)
WMA2 = WMA(period, values)
WMA3 = WMA(sqrt(period), (2 * WMA1) - WMA2)
HMA = WMA3
type Hma[T helper.Number] struct {
    // contains filtered or unexported fields
}

func NewHmaWithPeriod[T helper.Number](period int) *Hma[T]

NewHmaWithPeriod function initializes a new HMA instance with the given parameters.

func (*Hma[T]) Compute

func (h *Hma[T]) Compute(values <-chan T) <-chan T

Compute function takes a channel of numbers and computes the HMA and the signal line.

func (*Hma[T]) IdlePeriod

func (h *Hma[T]) IdlePeriod() int

IdlePeriod is the initial period that HMA won't yield any results.

func (*Hma[T]) String

func (h *Hma[T]) String() string

String is the string representation of the HMA.

type Kama

Kama represents the parameters for calculating the Kaufman's Adaptive Moving Average (KAMA). It is a type of moving average that adapts to market noise or volatility. It tracks prices closely during periods of small price swings and low noise.

Direction = Abs(Close - Previous Close Period Ago)
Volatility = MovingSum(Period, Abs(Close - Previous Close))
Efficiency Ratio (ER) = Direction / Volatility
Smoothing Constant (SC) = (ER * (2/(Fast + 1) - 2/(Slow + 1)) + (2/(Slow + 1)))^2
KAMA = Previous KAMA + SC * (Price - Previous KAMA)

Example:

kama := trend.NewKama[float64]()
result := kama.Compute(c)
type Kama[T helper.Number] struct {
    // ErPeriod is the Efficiency Ratio time period.
    ErPeriod int

    // FastScPeriod is the Fast Smoothing Constant time period.
    FastScPeriod int

    // SlowScPeriod is the Slow Smoothing Constant time period.
    SlowScPeriod int
}

func NewKama

func NewKama[T helper.Number]() *Kama[T]

NewKama function initializes a new KAMA instance with the default parameters.

func NewKamaWith[T helper.Number](erPeriod, fastScPeriod, slowScPeriod int) *Kama[T]

NewKamaWith function initializes a new KAMA instance with the given parameters.

func (*Kama[T]) Compute

func (k *Kama[T]) Compute(closings <-chan T) <-chan T

Compute function takes a channel of numbers and computes the KAMA over the specified period.

func (*Kama[T]) IdlePeriod

func (k *Kama[T]) IdlePeriod() int

IdlePeriod is the initial period that KAMA yield any results.

func (*Kama[T]) String

func (k *Kama[T]) String() string

String is the string representation of the KAMA.

type Kdj

Kdj represents the configuration parameters for calculating the KDJ, also known as the Random Index. KDJ is calculated similar to the Stochastic Oscillator with the difference of having the J line. It is used to analyze the trend and entry points.

The K and D lines show if the asset is overbought when they crosses above 80%, and oversold when they crosses below 20%. The J line represents the divergence.

RSV = ((Closing - Min(Low, rPeriod))
/ (Max(High, rPeriod) - Min(Low, rPeriod))) * 100

K = Sma(RSV, kPeriod)
D = Sma(K, dPeriod)
J = (3 * K) - (2 * D)

Example:

kdj := NewKdj[float64]()
values := kdj.Compute(highs, lows, closings)
type Kdj[T helper.Number] struct {
    // MovingMax is the highest high.
    MovingMax *MovingMax[T]

    // MovingMin is the lowest low.
    MovingMin *MovingMin[T]

    // Sma1 is the SMA of RSV.
    Sma1 *Sma[T]

    // Sma2 is the SMA of K.
    Sma2 *Sma[T]
}

func NewKdj

func NewKdj[T helper.Number]() *Kdj[T]

NewKdj function initializes a new Kdj instance with the default parameters

func (*Kdj[T]) Compute

func (kdj *Kdj[T]) Compute(high, low, closing <-chan T) (<-chan T, <-chan T, <-chan T)

Compute function takes a channel of numbers and computes the KDJ over the specified period. Returns K, D, J.

func (*Kdj[T]) IdlePeriod

func (kdj *Kdj[T]) IdlePeriod() int

IdlePeriod is the initial period that KDJ won't yield any results.

type Kst

Kst represents the configuration parameters for calculating the Know Sure Thing (KST) oscillator. KST is a momentum oscillator based on the smoothed rate-of-change for four different timeframes. A KST value crossing above zero suggests a bullish trend, while crossing below zero indicates a bearish trend.

RCMA1 = SMA(ROC(close, rocPeriod1), smaPeriod1)
RCMA2 = SMA(ROC(close, rocPeriod2), smaPeriod2)
RCMA3 = SMA(ROC(close, rocPeriod3), smaPeriod3)
RCMA4 = SMA(ROC(close, rocPeriod4), smaPeriod4)
KST = (RCMA1 × 1) + (RCMA2 × 2) + (RCMA3 × 3) + (RCMA4 × 4)
Signal = SMA(KST, signalPeriod)

Example:

kst := trend.NewKst[float64]()
kst.RocPeriod1 = 10
kst.RocPeriod2 = 15
kst.RocPeriod3 = 20
kst.RocPeriod4 = 30
kst.SmaPeriod1 = 10
kst.SmaPeriod2 = 10
kst.SmaPeriod3 = 10
kst.SmaPeriod4 = 15
kst.SignalPeriod = 9

kstResult, signalResult := kst.Compute(c)
type Kst[T helper.Float] struct {
    // RocPeriod1 is the first ROC period.
    RocPeriod1 int

    // RocPeriod2 is the second ROC period.
    RocPeriod2 int

    // RocPeriod3 is the third ROC period.
    RocPeriod3 int

    // RocPeriod4 is the fourth ROC period.
    RocPeriod4 int

    // SmaPeriod1 is the first SMA period for smoothing.
    SmaPeriod1 int

    // SmaPeriod2 is the second SMA period for smoothing.
    SmaPeriod2 int

    // SmaPeriod3 is the third SMA period for smoothing.
    SmaPeriod3 int

    // SmaPeriod4 is the fourth SMA period for smoothing.
    SmaPeriod4 int

    // SignalPeriod is the signal line period.
    SignalPeriod int
}

func NewKst

func NewKst[T helper.Float]() *Kst[T]

NewKst function initializes a new KST instance with default parameters.

func (*Kst[T]) Compute

func (k *Kst[T]) Compute(c <-chan T) (kstResult <-chan T, signalResult <-chan T)

Compute function takes a channel of numbers and computes the KST and the signal line.

func (*Kst[T]) IdlePeriod

func (k *Kst[T]) IdlePeriod() int

IdlePeriod is the initial period that KST won't yield any results.

func (*Kst[T]) String

func (k *Kst[T]) String() string

String is the string representation of the KST.

type Ma

Ma represents the interface for the Moving Average (MA) indicators.

type Ma[T helper.Number] interface {
    // Compute function takes a channel of numbers and computes the MA.
    Compute(<-chan T) <-chan T

    // IdlePeriod is the initial period that MA won't yield any results.
    IdlePeriod() int

    // String is the string representation of the MA instance.
    String() string
}

type Macd

Macd represents the configuration parameters for calculating the Moving Average Convergence Divergence (MACD).

MACD = 12-Period EMA - 26-Period EMA.
Signal = 9-Period EMA of MACD.

Example:

type Macd[T helper.Number] struct {
    Ema1 *Ema[T]
    Ema2 *Ema[T]
    Ema3 *Ema[T]
}

func NewMacd

func NewMacd[T helper.Number]() *Macd[T]

NewMacd function initializes a new MACD instance with the default parameters.

func NewMacdWithPeriod[T helper.Number](period1, period2, period3 int) *Macd[T]

NewMacdWithPeriod function initializes a new MACD instance with the given parameters.

func (*Macd[T]) Compute

func (m *Macd[T]) Compute(c <-chan T) (<-chan T, <-chan T)

Compute function takes a channel of numbers and computes the MACD and the signal line.

func (*Macd[T]) IdlePeriod

func (m *Macd[T]) IdlePeriod() int

IdlePeriod is the initial period that MACD won't yield any results.

MassIndex represents the configuration parameters for calculating the Mass Index. It uses the high-low range to identify trend reversals based on range expansions.

Single EMA = EMA(9, Highs - Lows)
Double EMA = EMA(9, Single EMA)
Ratio = Single EMA / Double Ema1
Mass Index = SUM(Ratio, 25)

Example:

type MassIndex[T helper.Number] struct {
    Ema1      *Ema[T]
    Ema2      *Ema[T]
    MovingSum *MovingSum[T]
}

func NewMassIndex[T helper.Number]() *MassIndex[T]

NewMassIndex function initializes a new APO instance with the default parameters.

func (*MassIndex[T]) Compute

func (m *MassIndex[T]) Compute(highs, lows <-chan T) <-chan T

Compute function takes a channel of numbers and computes the Mass Index.

func (*MassIndex[T]) IdlePeriod

func (m *MassIndex[T]) IdlePeriod() int

IdlePeriod is the initial period that Mass Index won't yield any results.

McGinleyDynamic represents the parameters for calculating the McGinley Dynamic. It is a technical analysis indicator that is an improvement over the Exponential Moving Average (EMA). It is designed to adjust for changes in market speed.

MD_today = MD_yesterday + (Close - MD_yesterday) / (Period * (Close / MD_yesterday)^4)

Example:

md := trend.NewMcGinleyDynamic[float64]()
result := md.Compute(c)
type McGinleyDynamic[T helper.Number] struct {
    // Period is the smoothing period.
    Period int
}

func NewMcGinleyDynamic[T helper.Number]() *McGinleyDynamic[T]

NewMcGinleyDynamic function initializes a new McGinley Dynamic instance with the default parameters.

func NewMcGinleyDynamicWithPeriod[T helper.Number](period int) *McGinleyDynamic[T]

NewMcGinleyDynamicWithPeriod function initializes a new McGinley Dynamic instance with the given period.

func (*McGinleyDynamic[T]) Compute

func (m *McGinleyDynamic[T]) Compute(c <-chan T) <-chan T

Compute function takes a channel of numbers and computes the McGinley Dynamic over the specified period.

func (*McGinleyDynamic[T]) IdlePeriod

func (m *McGinleyDynamic[T]) IdlePeriod() int

IdlePeriod is the initial period that McGinley Dynamic yield any results.

func (*McGinleyDynamic[T]) String

func (m *McGinleyDynamic[T]) String() string

String is the string representation of the McGinley Dynamic.

type Mlr

Mlr represents the configuration parameters for calculating the Moving Linear Regression.

y = mx + b

Example:

mlr := trend.NewMlrWithPeriod[float64](14)
rs := mlr.Compute(x , y)
type Mlr[T helper.Number] struct {
    // Mls is the Moving Least Square instance.
    Mls *Mls[T]
}

func NewMlrWithPeriod[T helper.Number](period int) *Mlr[T]

NewMlrWithPeriod function initializes a new MLR instance with the given period.

func (*Mlr[T]) Compute

func (m *Mlr[T]) Compute(x, y <-chan T) <-chan T

Compute function takes a channel of numbers and computes the MLR r.

func (*Mlr[T]) IdlePeriod

func (m *Mlr[T]) IdlePeriod() int

IdlePeriod is the initial period that MLR won't yield any results.

type Mls

Mls represents the configuration parameters for calculating the Moving Least Square (MLS). It is a regression analysis to determine the line of best fit for the given set of data.

y = mx + b
b = y-intercept
y = slope

m = (period * sumXY - sumX * sumY) / (period * sumX2 - sumX * sumX)
b = (sumY - m * sumX) / period

Example:

mls := trend.NewMlsWithPeriod[float64](14)
ms, bs := mls.Compute(x , y)
type Mls[T helper.Number] struct {
    // Sum is the moving sum instance.
    Sum *MovingSum[T]
}

func NewMlsWithPeriod[T helper.Number](period int) *Mls[T]

NewMlsWithPeriod function initializes a new MLS instance with the given period.

func (*Mls[T]) Compute

func (m *Mls[T]) Compute(x, y <-chan T) (<-chan T, <-chan T)

Compute function takes a channel of numbers and computes the MLS m and b.

func (*Mls[T]) IdlePeriod

func (m *Mls[T]) IdlePeriod() int

IdlePeriod is the initial period that MLS won't yield any results.

MovingMax represents the configuration parameters for calculating the Moving Max over the specified period.

Example:

type MovingMax[T helper.Number] struct {
    // Time period.
    Period int
}

func NewMovingMax[T helper.Number]() *MovingMax[T]

NewMovingMax function initializes a new Moving Max instance with the default parameters.

func NewMovingMaxWithPeriod[T helper.Number](period int) *MovingMax[T]

NewMovingMaxWithPeriod function initializes a new Moving Max instance with the given period.

func (*MovingMax[T]) Compute

func (m *MovingMax[T]) Compute(c <-chan T) <-chan T

Compute function takes a channel of numbers and computes the Moving Max over the specified period.

func (*MovingMax[T]) IdlePeriod

func (m *MovingMax[T]) IdlePeriod() int

IdlePeriod is the initial period that Mocing Max won't yield any results.

MovingMin represents the configuration parameters for calculating the Moving Min over the specified period.

Example:

type MovingMin[T helper.Number] struct {
    // Time period.
    Period int
}

func NewMovingMin[T helper.Number]() *MovingMin[T]

NewMovingMin function initializes a new Moving Min instance with the default parameters.

func NewMovingMinWithPeriod[T helper.Number](period int) *MovingMin[T]

NewMovingMinWithPeriod function initializes a new Moving Min instance with the given period.

func (*MovingMin[T]) Compute

func (m *MovingMin[T]) Compute(c <-chan T) <-chan T

Compute function takes a channel of numbers and computes the Moving Min over the specified period.

func (*MovingMin[T]) IdlePeriod

func (m *MovingMin[T]) IdlePeriod() int

IdlePeriod is the initial period that Mocing Min won't yield any results.

MovingSum represents the configuration parameters for calculating the Moving Sum over the specified period.

Example:

sum := trend.NewMovingSum[float64]()
sum.Period = 20
type MovingSum[T helper.Number] struct {
    // Time period.
    Period int
}

func NewMovingSum[T helper.Number]() *MovingSum[T]

NewMovingSum function initializes a new Moving Sum instance with the default parameters.

func NewMovingSumWithPeriod[T helper.Number](period int) *MovingSum[T]

NewMovingSumWithPeriod function initializes a new Moving Sum instance with the given period.

func (*MovingSum[T]) Compute

func (m *MovingSum[T]) Compute(c <-chan T) <-chan T

Compute function takes a channel of numbers and computes the Moving Sum over the specified period.

func (*MovingSum[T]) IdlePeriod

func (m *MovingSum[T]) IdlePeriod() int

IdlePeriod is the initial period that Moving Sum won't yield any results.

PivotPoint represents the configuration parameters for calculating Pivot Points. Pivot points are calculated based on the previous period's high, low, and close, and are used to predict support and resistance levels for the current period.

type PivotPoint[T helper.Float] struct {
    // Method is the pivot point calculation method.
    Method PivotPointMethod
}

func NewPivotPoint[T helper.Float]() *PivotPoint[T]

NewPivotPoint function initializes a new Pivot Point instance with the standard method.

func NewPivotPointWithMethod[T helper.Float](method PivotPointMethod) *PivotPoint[T]

NewPivotPointWithMethod function initializes a new Pivot Point instance with the given method.

func (*PivotPoint[T]) Compute

func (p *PivotPoint[T]) Compute(opens, highs, lows, closings <-chan T) <-chan PivotPointResult[T]

Compute function takes channels for open, high, low, and closing prices and returns a channel of PivotPointResult. It uses the values from the previous period to calculate levels for the current period.

func (*PivotPoint[T]) IdlePeriod

func (p *PivotPoint[T]) IdlePeriod() int

IdlePeriod is the initial period that Pivot Point won't yield any results.

func (*PivotPoint[T]) String

func (p *PivotPoint[T]) String() string

String is the string representation of the Pivot Point instance.

PivotPointMethod represents the method used for calculating pivot points.

type PivotPointMethod int

const (
    // PivotPointStandard is the standard pivot point calculation.
    PivotPointStandard PivotPointMethod = iota

    // PivotPointWoodie is the Woodie pivot point calculation.
    PivotPointWoodie

    // PivotPointCamarilla is the Camarilla pivot point calculation.
    PivotPointCamarilla

    // PivotPointFibonacci is the Fibonacci pivot point calculation.
    PivotPointFibonacci
)

PivotPointResult represents the result of the pivot point calculation, including the pivot point itself, and its associated resistance (R) and support (S) levels.

type PivotPointResult[T helper.Float] struct {
    P   T
    R1  T
    R2  T
    R3  T
    R4  T
    S1  T
    S2  T
    S3  T
    S4  T
}

type Rma

Rma represents the parameters for calculating Rolling Moving Average (RMA).

R[0] to R[p-1] is SMA(values)
R[p] and after is R[i] = ((R[i-1]*(p-1)) + v[i]) / p

Example:

rma := trend.NewRma[float64]()
rma.Period = 10

result := rma.Compute(c)
type Rma[T helper.Number] struct {
    // Time period.
    Period int
}

func NewRma

func NewRma[T helper.Number]() *Rma[T]

NewRma function initializes a new RMA instance with the default parameters.

func NewRmaWithPeriod[T helper.Number](period int) *Rma[T]

NewRmaWithPeriod function initializes a new RMA instance with the given period.

func (*Rma[T]) Compute

func (r *Rma[T]) Compute(c <-chan T) <-chan T

Compute function takes a channel of numbers and computes the RMA over the specified period.

func (*Rma[T]) IdlePeriod

func (r *Rma[T]) IdlePeriod() int

IdlePeriod is the initial period that RMA won't yield any results.

type Roc

Roc represents the configuration parameters for calculating the Rate Of Change (ROC) indicator.

ROC = (Current Price - Price n periods ago) / Price n periods ago
type Roc[T helper.Float] struct {
    // Time period.
    Period int
}

func NewRoc

func NewRoc[T helper.Float]() *Roc[T]

NewRoc function initializes a new Roc instance with the default parameters.

func NewRocWithPeriod[T helper.Float](period int) *Roc[T]

NewRocWithPeriod function initializes a new Roc instance with the given parameters.

func (*Roc[T]) Compute

func (r *Roc[T]) Compute(values <-chan T) <-chan T

Compute function takes a channel of numbers and computes the ROC and the signal line.

func (*Roc[T]) IdlePeriod

func (r *Roc[T]) IdlePeriod() int

IdlePeriod is the initial period that ROC won't yield any results.

func (*Roc[T]) String

func (r *Roc[T]) String() string

String is the string representation of the ROC.

SlowStochastic represents the configuration parameters for calculating the Slow Stochastic indicator. This applies additional smoothing to the Fast Stochastic values.

Fast %K = Stochastic(values, period)
Slow %K = SMA(Fast %K, kPeriod)
Slow %D = SMA(Slow %K, dPeriod)

Example:

s := trend.NewSlowStochastic[float64]()
k, d := s.Compute(values)
type SlowStochastic[T helper.Number] struct {
    // Period is the period for the min/max calculation.
    Period int

    // KPeriod is the period for smoothing Fast %K to get Slow %K.
    KPeriod int

    // DPeriod is the period for smoothing Slow %K to get Slow %D.
    DPeriod int
}

func NewSlowStochastic[T helper.Number]() *SlowStochastic[T]

NewSlowStochastic function initializes a new SlowStochastic instance with the default parameters.

func NewSlowStochasticWithPeriod[T helper.Number](period, kPeriod, dPeriod int) *SlowStochastic[T]

NewSlowStochasticWithPeriod function initializes a new SlowStochastic instance with the given periods.

func (*SlowStochastic[T]) Compute

func (s *SlowStochastic[T]) Compute(values <-chan T) (<-chan T, <-chan T)

Compute function takes a channel of numbers and computes the Slow Stochastic indicator. Returns Slow %K and Slow %D.

func (*SlowStochastic[T]) IdlePeriod

func (s *SlowStochastic[T]) IdlePeriod() int

IdlePeriod is the initial period that Slow Stochastic won't yield any results.

type Sma

Sma represents the parameters for calculating the Simple Moving Average.

Example:

sma := trend.NewSma[float64]()
sma.Period = 10

result := sma.Compute(c)
type Sma[T helper.Number] struct {
    // Period is the time period for the SMA.
    Period int
}

func NewSma

func NewSma[T helper.Number]() *Sma[T]

NewSma function initializes a new SMA instance with the default parameters.

func NewSmaWithPeriod[T helper.Number](period int) *Sma[T]

NewSmaWithPeriod function initializes a new SMA instance with the default parameters.

func (*Sma[T]) Compute

func (s *Sma[T]) Compute(c <-chan T) <-chan T

Compute function takes a channel of numbers and computes the SMA over the specified period.

func (*Sma[T]) IdlePeriod

func (s *Sma[T]) IdlePeriod() int

IdlePeriod is the initial period that SMA won't yield any results.

func (*Sma[T]) String

func (s *Sma[T]) String() string

String is the string representation of the SMA.

type Smma

Smma represents the parameters for calculating the Smoothed Moving Average (SMMA).

SMMA[0] = SMA(N)
SMMA[i] = ((SMMA[i-1] * (N - 1)) + Close[i]) / N

Example:

smma := trend.NewSmma[float64]()
smma.Period = 10

result := smma.Compute(c)
type Smma[T helper.Number] struct {
    // Time period.
    Period int
}

func NewSmma

func NewSmma[T helper.Number]() *Smma[T]

NewSmma function initializes a new SMMA instance with the default parameters.

func NewSmmaWithPeriod[T helper.Number](period int) *Smma[T]

NewSmmaWithPeriod function initializes a new SMMA instance with the given period.

func (*Smma[T]) Compute

func (s *Smma[T]) Compute(c <-chan T) <-chan T

Compute function takes a channel of numbers and computes the SMMA over the specified period.

func (*Smma[T]) IdlePeriod

func (s *Smma[T]) IdlePeriod() int

IdlePeriod is the initial period that SMMA yield any results.

func (*Smma[T]) String

func (s *Smma[T]) String() string

String is the string representation of the SMMA.

type Stc

Stc represents the configuration parameters for calculating the Schaff Trend Cycle (STC) indicator. It combines MACD with stochastic oscillators to identify trend direction and potential entry points.

EMA1 = EMA(values, fastPeriod)
EMA2 = EMA(values, slowPeriod)
MACD = EMA1 - EMA2

%K = Stochastic %K of MACD with kPeriod
%D = Stochastic %D of MACD with dPeriod

STC = 100 * (MACD - %K) / (%D - %K)

Example:

stc := trend.NewStc[float64]()
result := stc.Compute(closings)
type Stc[T helper.Number] struct {
    // FastPeriod is the period for the fast EMA.
    FastPeriod int

    // SlowPeriod is the period for the slow EMA.
    SlowPeriod int

    // KPeriod is the period for the Stochastic %K.
    KPeriod int

    // DPeriod is the period for the Stochastic %D.
    DPeriod int

    // Apo is the APO instance for MACD calculation.
    Apo *Apo[T]

    // Stochastic is the Stochastic instance.
    Stochastic *Stochastic[T]
}

func NewStc

func NewStc[T helper.Number]() *Stc[T]

NewStc function initializes a new STC instance with the default parameters.

func NewStcWithPeriod[T helper.Number](fastPeriod, slowPeriod, kPeriod, dPeriod int) *Stc[T]

NewStcWithPeriod function initializes a new STC instance with the given periods.

func (*Stc[T]) Compute

func (s *Stc[T]) Compute(c <-chan T) <-chan T

Compute function takes a channel of numbers and computes the STC indicator.

func (*Stc[T]) IdlePeriod

func (s *Stc[T]) IdlePeriod() int

IdlePeriod is the initial period that STC won't yield any results.

Stochastic represents the configuration parameters for calculating the Stochastic indicator on a single input series. This is different from the Stochastic Oscillator which operates on high, low, and close. This generic version is useful for applying stochastic calculation to any series, such as MACD values in the Schaff Trend Cycle (STC).

K = (Value - Min(Value, period)) / (Max(Value, period) - Min(Value, period)) * 100
D = SMA(K, dPeriod)

Example:

s := trend.NewStochastic[float64]()
k, d := s.Compute(values)
type Stochastic[T helper.Number] struct {
    // Period is the period for the min/max calculation.
    Period int

    // Sma is the SMA instance for %D calculation.
    Sma *Sma[T]
}

func NewStochastic[T helper.Number]() *Stochastic[T]

NewStochastic function initializes a new Stochastic instance with the default parameters.

func NewStochasticWithPeriod[T helper.Number](period int) *Stochastic[T]

NewStochasticWithPeriod function initializes a new Stochastic instance with the given period.

func (*Stochastic[T]) Compute

func (s *Stochastic[T]) Compute(values <-chan T) (<-chan T, <-chan T)

Compute function takes a channel of numbers and computes the Stochastic indicator. Returns %K and %D.

func (*Stochastic[T]) IdlePeriod

func (s *Stochastic[T]) IdlePeriod() int

IdlePeriod is the initial period that Stochastic won't yield any results.

type T3

T3 represents the configuration parameters for calculating the Tillson T3 Moving Average. The T3 is a smooth moving average that chains multiple EMAs together with a volume factor for improved responsiveness.

T3 = c1*EMA6 + c2*EMA6(EMA6) + c3*EMA6(EMA6(EMA6)) + c4*EMA6(EMA6(EMA6(EMA6)))

where:

c1 = -a^3
c2 = 3a^2
c3 = -3a
c4 = a^3
a = volume factor

Example:

t3 := trend.NewT3[float64]()
result := t3.Compute(closings)
type T3[T helper.Float] struct {
    // Period is the period for the EMA calculations.
    Period int

    // VolumeFactor is the volume factor for the T3 calculation.
    VolumeFactor T
    // contains filtered or unexported fields
}

func NewT3

func NewT3[T helper.Float]() *T3[T]

NewT3 function initializes a new T3 instance.

func NewT3WithPeriodAndFactor[T helper.Float](period int, volumeFactor float64) *T3[T]

NewT3WithPeriodAndFactor function initializes a new T3 instance with specified period and volume factor.

func (*T3[T]) Compute

func (t *T3[T]) Compute(closings <-chan T) <-chan T

Compute function takes a channel of numbers and computes the T3 Moving Average.

func (*T3[T]) IdlePeriod

func (t *T3[T]) IdlePeriod() int

IdlePeriod is the initial period that T3 won't yield any results.

func (*T3[T]) String

func (t *T3[T]) String() string

String is the string representation of the T3.

type Tema

Tema represents the configuration parameters for calculating the Triple Exponential Moving Average (TEMA).

TEMA = (3 * EMA1) - (3 * EMA2) + EMA3
EMA1 = EMA(values)
EMA2 = EMA(EMA1)
EMA3 = EMA(EMA2)
type Tema[T helper.Number] struct {
    Ema1 *Ema[T]
    Ema2 *Ema[T]
    Ema3 *Ema[T]
}

func NewTema

func NewTema[T helper.Number]() *Tema[T]

NewTema function initializes a new TEMA instance with the default parameters.

func (*Tema[T]) Compute

func (t *Tema[T]) Compute(c <-chan T) <-chan T

Compute function takes a channel of numbers and computes the TEMA and the signal line.

func (*Tema[T]) IdlePeriod

func (t *Tema[T]) IdlePeriod() int

IdlePeriod is the initial period that TEMA won't yield any results.

type Trima

Trima represents the configuration parameters for calculating the Triangular Moving Average (TRIMA).

If period is even:

TRIMA = SMA(period / 2, SMA((period / 2) + 1, values))

If period is odd:

TRIMA = SMA((period + 1) / 2, SMA((period + 1) / 2, values))
type Trima[T helper.Number] struct {
    // Time period.
    Period int
}

func NewTrima[T helper.Number]() *Trima[T]

NewTrima function initializes a new TRIMA instance with the default parameters.

func (*Trima[T]) Compute

func (t *Trima[T]) Compute(c <-chan T) <-chan T

Compute function takes a channel of numbers and computes the TRIMA and the signal line.

func (*Trima[T]) IdlePeriod

func (t *Trima[T]) IdlePeriod() int

IdlePeriod is the initial period that TRIMA won't yield any results.

type Trix

Trix represents the configuration parameters for calculating the Triple Exponential Average (TRIX). TRIX indicator is an oscillator used to identify oversold and overbought markets, and it can also be used as a momentum indicator. Like many oscillators, TRIX oscillates around a zero line.

EMA1 = EMA(period, values)
EMA2 = EMA(period, EMA1)
EMA3 = EMA(period, EMA2)
TRIX = (EMA3 - Previous EMA3) / Previous EMA3

Example:

trix := trend.NewTrix[float64]()
result := trix.Compute(values)
type Trix[T helper.Number] struct {
    // Time period.
    Period int
}

func NewTrix

func NewTrix[T helper.Number]() *Trix[T]

NewTrix function initializes a new TRIX instance with the default parameters.

func (*Trix[T]) Compute

func (t *Trix[T]) Compute(c <-chan T) <-chan T

Compute function takes a channel of numbers and computes the TRIX and the signal line.

func (*Trix[T]) IdlePeriod

func (t *Trix[T]) IdlePeriod() int

IdlePeriod is the initial period that TRIX won't yield any results.

type Tsi

Tsi represents the parameters needed to calculate the True Strength Index (TSI). It is a technical momentum oscillator used in financial analysis. The TSI helps identify trends and potential trend reversals.

PCDS = Ema(13, Ema(25, (Current - Prior)))
APCDS = Ema(13, Ema(25, Abs(Current - Prior)))
TSI = (PCDS / APCDS) * 100

Example:

tsi := trend.NewTsi[float64]()
result := tsi.Compute(closings)
type Tsi[T helper.Number] struct {
    // FirstSmoothing is the first smoothing moving average.
    FirstSmoothing Ma[T]

    // SecondSmoothing is the second smoothing moving average.
    SecondSmoothing Ma[T]
}

func NewTsi

func NewTsi[T helper.Number]() *Tsi[T]

NewTsi function initializes a new TSI instance with the default parameters.

func NewTsiWith[T helper.Number](firstSmoothingPeriod, secondSmoothingPeriod int) *Tsi[T]

NewTsiWith function initializes a new TSI instance with the given parameters.

func (*Tsi[T]) Compute

func (t *Tsi[T]) Compute(closings <-chan T) <-chan T

Compute function takes a channel of numbers and computes the TSI over the specified period.

func (*Tsi[T]) IdlePeriod

func (t *Tsi[T]) IdlePeriod() int

IdlePeriod is the initial period that TSI yield any results.

func (*Tsi[T]) String

func (t *Tsi[T]) String() string

String is the string representation of the TSI.

TypicalPrice represents the configuration parameters for calculating the Typical Price. It is another approximation of average price for each period and can be used as a filter for moving average systems.

Typical Price = (High + Low + Closing) / 3
type TypicalPrice[T helper.Number] struct{}

func NewTypicalPrice[T helper.Number]() *TypicalPrice[T]

NewTypicalPrice function initializes a new Typical Price instance with the default parameters.

func (*TypicalPrice[T]) Compute

func (*TypicalPrice[T]) Compute(high, low, closing <-chan T) <-chan T

Compute function takes a channel of numbers and computes the Typical Price and the signal line.

type Vwma

Vwma represents the configuration parameters for calculating the Volume Weighted Moving Average (VWMA) It averages the price data with an emphasis on volume, meaning areas with higher volume will have a greater weight.

VWMA = Sum(Price * Volume) / Sum(Volume)
type Vwma[T helper.Number] struct {
    // Time period.
    Period int
}

func NewVwma

func NewVwma[T helper.Number]() *Vwma[T]

NewVwma function initializes a new VWMA instance with the default parameters.

func (*Vwma[T]) Compute

func (v *Vwma[T]) Compute(closing, volume <-chan T) <-chan T

Compute function takes a channel of numbers and computes the VWMA and the signal line.

func (*Vwma[T]) IdlePeriod

func (v *Vwma[T]) IdlePeriod() int

IdlePeriod is the initial period that VWMA won't yield any results.

WeightedClose represents the parameters for calculating the Weighted Close indicator.

Weighted Close = (High + Low + (Close * 2)) / 4

Example:

weightedClose := trend.NewWeightedClose[float64]()
result := weightedClose.Compute(highs, lows, closes)
type WeightedClose[T helper.Number] struct {
}

func NewWeightedClose[T helper.Number]() *WeightedClose[T]

NewWeightedClose function initializes a new Weighted Close instance with the default parameters.

func (*WeightedClose[T]) Compute

func (*WeightedClose[T]) Compute(highs, lows, closes <-chan T) <-chan T

Compute function takes a channel of numbers and computes the Weighted Close over the specified period.

func (*WeightedClose[T]) IdlePeriod

func (*WeightedClose[T]) IdlePeriod() int

IdlePeriod is the initial period that Weighted Close yield any results.

func (*WeightedClose[T]) String

func (*WeightedClose[T]) String() string

String is the string representation of the Weighted Close.

type Wma

Wma represents the configuration parameters for calculating the Weighted Moving Average (WMA). It calculates a moving average by putting more weight on recent data and less on past data.

WMA = ((Value1 * 1/N) + (Value2 * 2/N) + ...) / 2
type Wma[T helper.Number] struct {
    // Time period.
    Period int
}

func NewWmaWith[T helper.Number](period int) *Wma[T]

NewWmaWith function initializes a new WMA instance with the given parameters.

func (*Wma[T]) Compute

func (w *Wma[T]) Compute(values <-chan T) <-chan T

Compute computes the WMA over the input stream.

func (*Wma[T]) IdlePeriod

func (w *Wma[T]) IdlePeriod() int

IdlePeriod is the initial period that WMA won't yield any results.

func (*Wma[T]) String

func (w *Wma[T]) String() string

String is the string representation of the WMA.

Generated by gomarkdoc