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-2024 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 Dema
- type Ema
- type Envelope
- type Hma
- type Kama
- type Kdj
- type Ma
- type Macd
- type MassIndex
- type Mlr
- type Mls
- type MovingMax
- type MovingMin
- type MovingSum
- type Rma
- type Sma
- type Smma
- 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 ( // 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 ( // 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 (
// DefaultRmaPeriod is the default RMA period.
DefaultRmaPeriod = 20
)
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)
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 Community 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 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 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 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 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 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 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 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 function takes a channel of numbers and computes the WMA and the signal line.
func (*Wma[T]) IdlePeriod ¶
IdlePeriod is the initial period that WMA won't yield any results.