Documentation
¶
Overview ¶
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
- type Apo
- type Aroon
- type Bop
- type Cci
- type Cfo
- type Dema
- type Dpo
- type Ema
- type Envelope
- type Hma
- type Kama
- type Kdj
- type Kst
- type Ma
- type Macd
- type MassIndex
- type McGinleyDynamic
- type Mlr
- type Mls
- type MovingMax
- type MovingMin
- type MovingSum
- type PivotPoint
- type PivotPointMethod
- type PivotPointResult
- type Rma
- type Roc
- type SlowStochastic
- type Sma
- type Smma
- type Stc
- type Stochastic
- type T3
- type Tema
- type Trima
- type Trix
- type Tsi
- type TypicalPrice
- type Vwma
- type WeightedClose
- type Wma
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
)
const DefaultDpoPeriod = 20
DefaultDpoPeriod is the default period for DPO calculation.
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
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Apo ¶
type Apo[T helper.Number] struct { // Fast period. FastPeriod int // Fast smoothing. FastSmoothing T // Slow period. SlowPeriod int // Slow smoothing. SlowSmoothing T }
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)
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 ¶ added in v2.1.25
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 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 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)
func NewCciWithPeriod ¶
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 ¶
IdlePeriod is the initial period that CCI won't yield any results.
type Cfo ¶ added in v2.1.26
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)
func NewCfo ¶ added in v2.1.26
NewCfo function initializes a new CFO instance with the default parameters.
func NewCfoWithPeriod ¶ added in v2.1.26
NewCfoWithPeriod function initializes a new CFO instance with the given period.
func (*Cfo[T]) Compute ¶ added in v2.1.26
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 ¶ added in v2.1.26
IdlePeriod is the initial period that CFO won't yield any results.
type Dema ¶
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] }
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)
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 ¶
IdlePeriod is the initial period that DEMA won't yield any results.
type Dpo ¶ added in v2.1.18
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)
func NewDpoWithPeriod ¶ added in v2.1.18
NewDpoWithPeriod initializes a new DPO instance with the given period. Periods <= 1 are clamped to DefaultDpoPeriod.
func (*Dpo[T]) Compute ¶ added in v2.1.18
func (d *Dpo[T]) Compute(closing <-chan T) <-chan T
Compute calculates the DPO indicator over the input price channel.
func (*Dpo[T]) IdlePeriod ¶ added in v2.1.18
IdlePeriod returns the number of leading samples to discard before the first DPO value is available.
type Ema ¶
Ema represents the parameters for calculating the Exponential Moving Average.
Example:
ema := trend.NewEma[float64]() ema.Period = 10 result := ema.Compute(c)
func NewEmaWithPeriod ¶
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 ¶
IdlePeriod is the initial period that EMA yield any results.
type Envelope ¶ added in v2.1.7
type Envelope[T helper.Number] struct { // Ma is the moving average used. Ma Ma[T] // Percentage is the envelope percentage. Percentage T }
Envelope represents the parameters neededd to calcualte the Envelope.
func NewEnvelope ¶ added in v2.1.7
NewEnvelope function initializes a new Envelope instance with the default parameters.
func NewEnvelopeWithEma ¶ added in v2.1.7
NewEnvelopeWithEma function initializes a new Envelope instance using EMA.
func NewEnvelopeWithSma ¶ added in v2.1.7
NewEnvelopeWithSma function initalizes a new Envelope instance using SMA.
func (*Envelope[T]) Compute ¶ added in v2.1.7
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 ¶ added in v2.1.7
IdlePeriod is the initial period that Envelope yield any results.
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
func NewHmaWithPeriod ¶
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 ¶
IdlePeriod is the initial period that HMA won't yield any results.
type Kama ¶ added in v2.0.2
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 }
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)
func NewKama ¶ added in v2.0.2
NewKama function initializes a new KAMA instance with the default parameters.
func NewKamaWith ¶ added in v2.0.3
NewKamaWith function initializes a new KAMA instance with the given parameters.
func (*Kama[T]) Compute ¶ added in v2.0.2
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 ¶ added in v2.0.2
IdlePeriod is the initial period that KAMA yield any results.
type Kdj ¶
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] }
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)
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 ¶
IdlePeriod is the initial period that KDJ won't yield any results.
type Kst ¶ added in v2.1.25
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 }
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)
func NewKst ¶ added in v2.1.25
NewKst function initializes a new KST instance with default parameters.
func (*Kst[T]) Compute ¶ added in v2.1.25
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 ¶ added in v2.1.25
IdlePeriod is the initial period that KST won't yield any results.
type Ma ¶
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 }
Ma represents the interface for the Moving Average (MA) indicators.
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:
func NewMacdWithPeriod ¶
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 ¶
IdlePeriod is the initial period that MACD won't yield any results.
type MassIndex ¶
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:
func NewMassIndex ¶
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 ¶
IdlePeriod is the initial period that Mass Index won't yield any results.
type McGinleyDynamic ¶ added in v2.1.29
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)
func NewMcGinleyDynamic ¶ added in v2.1.29
func NewMcGinleyDynamic[T helper.Number]() *McGinleyDynamic[T]
NewMcGinleyDynamic function initializes a new McGinley Dynamic instance with the default parameters.
func NewMcGinleyDynamicWithPeriod ¶ added in v2.1.29
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 ¶ added in v2.1.29
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 ¶ added in v2.1.29
func (m *McGinleyDynamic[T]) IdlePeriod() int
IdlePeriod is the initial period that McGinley Dynamic yield any results.
func (*McGinleyDynamic[T]) String ¶ added in v2.1.29
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)
func NewMlrWithPeriod ¶
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 ¶
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)
func NewMlsWithPeriod ¶
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 ¶
IdlePeriod is the initial period that MLS won't yield any results.
type MovingMax ¶
MovingMax represents the configuration parameters for calculating the Moving Max over the specified period.
Example:
func NewMovingMax ¶
NewMovingMax function initializes a new Moving Max instance with the default parameters.
func NewMovingMaxWithPeriod ¶
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 ¶
IdlePeriod is the initial period that Mocing Max won't yield any results.
type MovingMin ¶
MovingMin represents the configuration parameters for calculating the Moving Min over the specified period.
Example:
func NewMovingMin ¶
NewMovingMin function initializes a new Moving Min instance with the default parameters.
func NewMovingMinWithPeriod ¶
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 ¶
IdlePeriod is the initial period that Mocing Min won't yield any results.
type MovingSum ¶
MovingSum represents the configuration parameters for calculating the Moving Sum over the specified period.
Example:
sum := trend.NewMovingSum[float64]() sum.Period = 20
func NewMovingSum ¶
NewMovingSum function initializes a new Moving Sum instance with the default parameters.
func NewMovingSumWithPeriod ¶
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 ¶
IdlePeriod is the initial period that Moving Sum won't yield any results.
type PivotPoint ¶ added in v2.1.29
type PivotPoint[T helper.Float] struct { // Method is the pivot point calculation method. Method PivotPointMethod }
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.
func NewPivotPoint ¶ added in v2.1.29
func NewPivotPoint[T helper.Float]() *PivotPoint[T]
NewPivotPoint function initializes a new Pivot Point instance with the standard method.
func NewPivotPointWithMethod ¶ added in v2.1.29
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 ¶ added in v2.1.29
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 ¶ added in v2.1.29
func (p *PivotPoint[T]) IdlePeriod() int
IdlePeriod is the initial period that Pivot Point won't yield any results.
func (*PivotPoint[T]) String ¶ added in v2.1.29
func (p *PivotPoint[T]) String() string
String is the string representation of the Pivot Point instance.
type PivotPointMethod ¶ added in v2.1.29
type PivotPointMethod int
PivotPointMethod represents the method used for calculating pivot points.
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 )
type PivotPointResult ¶ added in v2.1.29
PivotPointResult represents the result of the pivot point calculation, including the pivot point itself, and its associated resistance (R) and support (S) levels.
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)
func NewRmaWithPeriod ¶
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 ¶
IdlePeriod is the initial period that RMA won't yield any results.
type Roc ¶ added in v2.1.16
Roc represents the configuration parameters for calculating the Rate Of Change (ROC) indicator.
ROC = (Current Price - Price n periods ago) / Price n periods ago
func NewRoc ¶ added in v2.1.16
NewRoc function initializes a new Roc instance with the default parameters.
func NewRocWithPeriod ¶ added in v2.1.16
NewRocWithPeriod function initializes a new Roc instance with the given parameters.
func (*Roc[T]) Compute ¶ added in v2.1.16
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 ¶ added in v2.1.16
IdlePeriod is the initial period that ROC won't yield any results.
type SlowStochastic ¶ added in v2.1.25
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 }
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)
func NewSlowStochastic ¶ added in v2.1.25
func NewSlowStochastic[T helper.Number]() *SlowStochastic[T]
NewSlowStochastic function initializes a new SlowStochastic instance with the default parameters.
func NewSlowStochasticWithPeriod ¶ added in v2.1.25
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 ¶ added in v2.1.25
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 ¶ added in v2.1.25
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)
func NewSmaWithPeriod ¶
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 ¶
IdlePeriod is the initial period that SMA won't yield any results.
type Smma ¶ added in v2.1.10
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)
func NewSmma ¶ added in v2.1.10
NewSmma function initializes a new SMMA instance with the default parameters.
func NewSmmaWithPeriod ¶ added in v2.1.10
NewSmmaWithPeriod function initializes a new SMMA instance with the given period.
func (*Smma[T]) Compute ¶ added in v2.1.10
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 ¶ added in v2.1.10
IdlePeriod is the initial period that SMMA yield any results.
type Stc ¶ added in v2.1.25
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] }
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)
func NewStc ¶ added in v2.1.25
NewStc function initializes a new STC instance with the default parameters.
func NewStcWithPeriod ¶ added in v2.1.25
NewStcWithPeriod function initializes a new STC instance with the given periods.
func (*Stc[T]) Compute ¶ added in v2.1.25
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 ¶ added in v2.1.25
IdlePeriod is the initial period that STC won't yield any results.
type Stochastic ¶ added in v2.1.25
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] }
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)
func NewStochastic ¶ added in v2.1.25
func NewStochastic[T helper.Number]() *Stochastic[T]
NewStochastic function initializes a new Stochastic instance with the default parameters.
func NewStochasticWithPeriod ¶ added in v2.1.25
func NewStochasticWithPeriod[T helper.Number](period int) *Stochastic[T]
NewStochasticWithPeriod function initializes a new Stochastic instance with the given period.
func (*Stochastic[T]) Compute ¶ added in v2.1.25
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 ¶ added in v2.1.25
func (s *Stochastic[T]) IdlePeriod() int
IdlePeriod is the initial period that Stochastic won't yield any results.
type T3 ¶ added in v2.1.27
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 }
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)
func NewT3WithPeriodAndFactor ¶ added in v2.1.27
NewT3WithPeriodAndFactor function initializes a new T3 instance with specified period and volume factor.
func (*T3[T]) Compute ¶ added in v2.1.27
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 ¶ added in v2.1.27
IdlePeriod is the initial period that T3 won't yield any results.
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)
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 ¶
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))
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 ¶
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)
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 ¶
IdlePeriod is the initial period that TRIX won't yield any results.
type Tsi ¶ added in v2.0.3
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] }
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)
func NewTsi ¶ added in v2.0.3
NewTsi function initializes a new TSI instance with the default parameters.
func NewTsiWith ¶ added in v2.0.3
NewTsiWith function initializes a new TSI instance with the given parameters.
func (*Tsi[T]) Compute ¶ added in v2.0.3
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 ¶ added in v2.0.3
IdlePeriod is the initial period that TSI yield any results.
type TypicalPrice ¶
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
func NewTypicalPrice ¶
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)
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 ¶
IdlePeriod is the initial period that VWMA won't yield any results.
type WeightedClose ¶ added in v2.1.12
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)
func NewWeightedClose ¶ added in v2.1.12
func NewWeightedClose[T helper.Number]() *WeightedClose[T]
NewWeightedClose function initializes a new Weighted Close instance with the default parameters.
func (*WeightedClose[T]) Compute ¶ added in v2.1.12
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 ¶ added in v2.1.12
func (*WeightedClose[T]) IdlePeriod() int
IdlePeriod is the initial period that Weighted Close yield any results.
func (*WeightedClose[T]) String ¶ added in v2.1.12
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
func NewWmaWith ¶
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 ¶
IdlePeriod is the initial period that WMA won't yield any results.
Source Files
¶
- apo.go
- aroon.go
- bop.go
- cci.go
- cfo.go
- dema.go
- dpo.go
- ema.go
- envelope.go
- hma.go
- kama.go
- kdj.go
- kst.go
- ma.go
- macd.go
- mass_index.go
- mcginley_dynamic.go
- mlr.go
- mls.go
- moving_max.go
- moving_min.go
- moving_sum.go
- pivot_point.go
- rma.go
- roc.go
- slow_stochastic.go
- sma.go
- smma.go
- stc.go
- stochastic.go
- t3.go
- tema.go
- trend.go
- trima.go
- trix.go
- tsi.go
- typical_price.go
- vwma.go
- weighted_close.go
- wma.go