Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

momentum

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

Package momentum contains the momentum 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 (
    // DefaultAwesomeOscillatorShortPeriod is the default short period for the Awesome Oscillator (AO).
    DefaultAwesomeOscillatorShortPeriod = 5

    // DefaultAwesomeOscillatorLongPeriod is the default long period for the Awesome Oscillator (AO).
    DefaultAwesomeOscillatorLongPeriod = 34
)

const (
    // DefaultChaikinOscillatorShortPeriod is the default short period for the Chaikin Oscillator.
    DefaultChaikinOscillatorShortPeriod = 3

    // DefaultChaikinOscillatorLongPeriod is the default long period for the Chaikin Oscillator.
    DefaultChaikinOscillatorLongPeriod = 10
)

const (
    // DefaultConnorsRsiRsiPeriod is the default RSI period.
    DefaultConnorsRsiRsiPeriod = 3
    // DefaultConnorsRsiStreakRsiPeriod is the default Streak RSI period.
    DefaultConnorsRsiStreakRsiPeriod = 2
    // DefaultConnorsRsiPercentRankPeriod is the default PercentRank period.
    DefaultConnorsRsiPercentRankPeriod = 100
)

const (
    // DefaultCoppockCurveRocPeriod1 is the default first ROC period.
    DefaultCoppockCurveRocPeriod1 = 14

    // DefaultCoppockCurveRocPeriod2 is the default second ROC period.
    DefaultCoppockCurveRocPeriod2 = 11

    // DefaultCoppockCurveWmaPeriod is the default WMA period.
    DefaultCoppockCurveWmaPeriod = 10
)

const (
    // DefaultFisherPeriod is the default period for the Fisher Transform.
    DefaultFisherPeriod = 10

    // FisherClamp is the boundary value for clamping.
    FisherClamp = 0.999
)

const (
    // DefaultIchimokuCloudConversionPeriod is the default conversion period for the Ichimoku Cloud.
    DefaultIchimokuCloudConversionPeriod = 9

    // DefaultIchimokuCloudBasePeriod is the default base period for the Ichimoku Cloud.
    DefaultIchimokuCloudBasePeriod = 26

    // DefaultIchimokuCloudLeadingPeriod is the default leading period for the Ichimoku Cloud.
    DefaultIchimokuCloudLeadingPeriod = 52

    // DefaultIchimokuCloudLaggingPeriod is the default lagging period for the Ichimoku Cloud.
    DefaultIchimokuCloudLaggingPeriod = 26
)

const (
    // DefaultPpoShortPeriod is the default short period for the Percentage Price Oscillator.
    DefaultPpoShortPeriod = 12

    // DefaultPpoLongPeriod is the default long period for the Percentage Price Oscillator.
    DefaultPpoLongPeriod = 26

    // DefaultPpoSignalPeriod is the default signal period for the Percentage Price Oscillator.
    DefaultPpoSignalPeriod = 9
)

const (
    // DefaultPvoShortPeriod is the default short period for the Percentage Volume Oscillator.
    DefaultPvoShortPeriod = 12

    // DefaultPvoLongPeriod is the default long period for the Percentage Volume Oscillator.
    DefaultPvoLongPeriod = 26

    // DefaultPvoSignalPeriod is the default signal period for the Percentage Volume Oscillator.
    DefaultPvoSignalPeriod = 9
)

const (
    // DefaultRviPeriod is the default period for the Relative Vigor Index.
    DefaultRviPeriod = 10

    // DefaultRviSignalPeriod is the default signal line period for RVI.
    DefaultRviSignalPeriod = 4

    // RviFirPeriod is the FIR filter period (4 bars).
    RviFirPeriod = 4

    // RviFirSum is the sum of FIR weights (1+2+2+1 = 6).
    RviFirSum = 6
)

const (
    // DefaultStochasticOscillatorMaxAndMinPeriod is the default max and min period for the Stochastic Oscillator.
    DefaultStochasticOscillatorMaxAndMinPeriod = 14

    // DefaultStochasticOscillatorPeriod is the default period for the Stochastic Oscillator.
    DefaultStochasticOscillatorPeriod = 3
)

const (
    // DefaultTdSequentialLookback is the default lookback period for comparing closes.
    DefaultTdSequentialLookback = 4

    // DefaultTdSequentialCountdownLookback is the default lookback period for countdown comparison.
    DefaultTdSequentialCountdownLookback = 2

    // DefaultTdSequentialSetupPeriod is the default setup period (9).
    DefaultTdSequentialSetupPeriod = 9

    // DefaultTdSequentialCountdownPeriod is the default countdown period (13).
    DefaultTdSequentialCountdownPeriod = 13
)

const (
    // DefaultUltimateOscillatorShortPeriod is the default short period for the Ultimate Oscillator (UO).
    DefaultUltimateOscillatorShortPeriod = 7

    // DefaultUltimateOscillatorMediumPeriod is the default medium period for the Ultimate Oscillator (UO).
    DefaultUltimateOscillatorMediumPeriod = 14

    // DefaultUltimateOscillatorLongPeriod is the default long period for the Ultimate Oscillator (UO).
    DefaultUltimateOscillatorLongPeriod = 28
)

const (
    // DefaultElderRayPeriod is the default period for Elder-Ray Index.
    DefaultElderRayPeriod = 13
)

const (
    // DefaultQstickPeriod is the default period for the Qstick SMA.
    DefaultQstickPeriod = 20
)

const (
    // DefaultRsiPeriod is the default period for the Relative Strength Index (RSI).
    DefaultRsiPeriod = 14
)

const (
    // DefaultStochasticRsiPeriod is the default period for the Stochastic Relative Strength Index (RSI).
    DefaultStochasticRsiPeriod = 14
)

const (
    // DefaultWilliamsRPeriod is the default period for the Williams R.
    DefaultWilliamsRPeriod = 14
)

AwesomeOscillator represents the configuration parameter for calculating the Awesome Oscillator (AO). It gauges market momentum by comparing short-term price action (5-period average) against long-term trends (34-period average). Its value around a zero line reflects bullishness above and bearishness below. Crossings of the zero line can signal potential trend reversals. Traders use the AO to confirm existing trends, identify entry/exit points, and understand momentum shifts.

Median Price = ((Low + High) / 2).
AO = 5-Period SMA - 34-Period SMA.

Example:

ao := momentum.AwesomeOscillator[float64]()
values := ao.Compute(lows, highs)
type AwesomeOscillator[T helper.Number] struct {
    // ShortSma is the SMA for the short period.
    ShortSma *trend.Sma[T]

    // LongSma is the SMA for the long period.
    LongSma *trend.Sma[T]
}

func NewAwesomeOscillator[T helper.Number]() *AwesomeOscillator[T]

NewAwesomeOscillator function initializes a new Awesome Oscillator instance.

func (*AwesomeOscillator[T]) Compute

func (a *AwesomeOscillator[T]) Compute(highs, lows <-chan T) <-chan T

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

func (*AwesomeOscillator[T]) IdlePeriod

func (a *AwesomeOscillator[T]) IdlePeriod() int

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

ChaikinOscillator represents the configuration parameter for calculating the Chaikin Oscillator. It measures the momentum of the Accumulation/Distribution (A/D) using the Moving Average Convergence Divergence (MACD) formula. It takes the difference between fast and slow periods EMA of the A/D. Cross above the A/D line indicates bullish.

CO = Ema(fastPeriod, AD) - Ema(slowPeriod, AD)

Example:

co := momentum.ChaikinOscillator[float64]()
values := co.Compute(lows, highs)
type ChaikinOscillator[T helper.Number] struct {
    // Ad is the Accumulation/Distribution (A/D) instance.
    Ad  *volume.Ad[T]

    // ShortEma is the SMA for the short period.
    ShortEma *trend.Ema[T]

    // LongEma is the SMA for the long period.
    LongEma *trend.Ema[T]
}

func NewChaikinOscillator[T helper.Number]() *ChaikinOscillator[T]

NewChaikinOscillator function initializes a new Chaikin Oscillator instance.

func (*ChaikinOscillator[T]) Compute

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

Compute function takes a channel of numbers and computes the Chaikin Oscillator.

func (*ChaikinOscillator[T]) IdlePeriod

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

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

ConnorsRsi represents the configuration parameters for calculating the Connors RSI. It is a momentum indicator that combines three components: 1. RSI of closing prices 2. RSI of up/down streak length 3. Percentile rank of the rate of change

CRSI = (RSI(3) + RSI(Streak, 2) + PercentRank(ROC, 100)) / 3

Example:

connorsRsi := momentum.NewConnorsRsi[float64]()
result := connorsRsi.Compute(closings)
type ConnorsRsi[T helper.Float] struct {
    // RsiPeriod is the period for the RSI on closing prices.
    RsiPeriod int
    // StreakRsiPeriod is the period for the RSI on streak length.
    StreakRsiPeriod int
    // PercentRankPeriod is the period for the PercentRank of ROC.
    PercentRankPeriod int

    // Rsi is the RSI instance for closing prices.
    Rsi *Rsi[T]
    // StreakRsi is the RSI instance for streak length.
    StreakRsi *Rsi[T]
    // Roc is the Rate of Change instance.
    Roc *trend.Roc[T]
    // Streak is the streak calculator instance.
    Streak *Streak[T]
}

func NewConnorsRsi[T helper.Float]() *ConnorsRsi[T]

NewConnorsRsi function initializes a new Connors RSI instance with the default parameters.

func NewConnorsRsiWithPeriods[T helper.Float](rsiPeriod, streakRsiPeriod, percentRankPeriod int) *ConnorsRsi[T]

NewConnorsRsiWithPeriods function initializes a new Connors RSI instance with the given periods.

func (*ConnorsRsi[T]) Compute

func (c *ConnorsRsi[T]) Compute(closings <-chan T) <-chan T

Compute function takes a channel of closings numbers and computes the Connors RSI.

func (*ConnorsRsi[T]) IdlePeriod

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

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

func (*ConnorsRsi[T]) String

func (c *ConnorsRsi[T]) String() string

String is the string representation of the Connors RSI.

CoppockCurve represents the configuration parameters for calculating the Coppock Curve oscillator. The Coppock Curve is a momentum indicator used to identify long-term buying opportunities in equity indices.

Coppock Curve = WMA(ROC(14) + ROC(11), 10)

Example:

cc := momentum.NewCoppockCurve[float64]()
result := cc.Compute(closings)
type CoppockCurve[T helper.Float] struct {
    // RocPeriod1 is the first ROC period.
    RocPeriod1 int

    // RocPeriod2 is the second ROC period.
    RocPeriod2 int

    // WmaPeriod is the WMA period for smoothing.
    WmaPeriod int
}

func NewCoppockCurve[T helper.Float]() *CoppockCurve[T]

NewCoppockCurve function initializes a new CoppockCurve instance with default parameters.

func NewCoppockCurveWithPeriods[T helper.Float](rocPeriod1, rocPeriod2, wmaPeriod int) *CoppockCurve[T]

NewCoppockCurveWithPeriods function initializes a new CoppockCurve instance with the given periods.

func (*CoppockCurve[T]) Compute

func (c *CoppockCurve[T]) Compute(values <-chan T) <-chan T

Compute function takes a channel of closings and computes the Coppock Curve.

func (*CoppockCurve[T]) IdlePeriod

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

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

func (*CoppockCurve[T]) String

func (c *CoppockCurve[T]) String() string

String is the string representation of the Coppock Curve.

ElderRay represents the configuration parameters for calculating the Elder-Ray Index. Developed by Alexander Elder, the Elder-Ray Index measures buying and selling pressure in the market. It consists of two separate indicators: Bull Power and Bear Power.

Bull Power = High - n-period EMA
Bear Power = Low - n-period EMA

Example:

er := momentum.NewElderRay[float64]()
bullPower, bearPower := er.Compute(highs, lows, closings)
type ElderRay[T helper.Number] struct {
    // Period is the time period.
    Period int
}

func NewElderRay[T helper.Number]() *ElderRay[T]

NewElderRay function initializes a new Elder-Ray Index instance with the default parameters.

func NewElderRayWithPeriod[T helper.Number](period int) *ElderRay[T]

NewElderRayWithPeriod function initializes a new Elder-Ray Index instance with the given period.

func (*ElderRay[T]) Compute

func (e *ElderRay[T]) Compute(highs, lows, closings <-chan T) (<-chan T, <-chan T)

Compute function takes channels of highs, lows, and closings and computes the Elder-Ray Index. Returns bullPower and bearPower channels.

func (*ElderRay[T]) IdlePeriod

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

IdlePeriod is the initial period that Elder-Ray Index won't yield any results.

func (*ElderRay[T]) String

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

String is the string representation of the Elder-Ray Index.

type Fisher

Fisher represents the configuration parameters for calculating the Fisher Transform. The Fisher Transform is a technical indicator that transforms prices into a normal distribution to identify price reversals.

x = 2 * ((close - min) / (max - min)) - 1
Fisher = 0.5 * ln((1 + x) / (1 - x))

The clamped x value is bounded between -0.999 and +0.999 to prevent division by zero or logarithmic infinity errors.

Example:

fisher := momentum.NewFisher[float64]()
result := fisher.Compute(closings)
type Fisher[T helper.Float] struct {
    // Period is the lookback period for min/max calculation.
    Period int

    // Max is the Moving Max instance.
    Max *trend.MovingMax[T]

    // Min is the Moving Min instance.
    Min *trend.MovingMin[T]
}

func NewFisher[T helper.Float]() *Fisher[T]

NewFisher function initializes a new Fisher Transform instance.

func (*Fisher[T]) Compute

func (f *Fisher[T]) Compute(closings <-chan T) <-chan T

Compute function takes a channel of numbers and computes the Fisher Transform.

func (*Fisher[T]) IdlePeriod

func (f *Fisher[T]) IdlePeriod() int

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

func (*Fisher[T]) String

func (f *Fisher[T]) String() string

String is the string representation of the Fisher Transform.

IchimokuCloud represents the configuration parameter for calculating the Ichimoku Cloud. It is also known as the Ichimoku Kinko Hyo, is a versatile indicator that defines support and resistance, identifies trend direction, gauges momentum, and provides trading signals.

Tenkan-sen (Conversion Line) = (9-Period High + 9-Period Low) / 2
Kijun-sen (Base Line) = (26-Period High + 26-Period Low) / 2
Senkou Span A (Leading Span A) = (Conversion Line + Base Line) / 2
Senkou Span B (Leading Span B) = (52-Period High + 52-Period Low) / 2
Chikou Span (Lagging Span) = Closing plotted 26 days in the past.

Example:

ic := momentum.IchimokuCloud[float64]()
conversionLine, baseLine, leadingSpanA, leasingSpanB, laggingSpan := ic.Compute(highs, lows, closings)
type IchimokuCloud[T helper.Number] struct {
    // ConversionMax is the conversion Moving Max instance.
    ConversionMax *trend.MovingMax[T]

    // ConversionMin is the conversion Moving Min instance.
    ConversionMin *trend.MovingMin[T]

    // BaseMax is the base Moving Max instance.
    BaseMax *trend.MovingMax[T]

    // BaseMin is the base Moving Min instance.
    BaseMin *trend.MovingMin[T]

    // LeadingMax is the leading Moving Max instance.
    LeadingMax *trend.MovingMax[T]

    // LeadingMin is the leading Moving Min instance.
    LeadingMin *trend.MovingMin[T]

    // LaggingPeriod is the lagging period.
    LaggingPeriod int
}

func NewIchimokuCloud[T helper.Number]() *IchimokuCloud[T]

NewIchimokuCloud function initializes a new Ichimoku Cloud instance.

func (*IchimokuCloud[T]) Compute

func (i *IchimokuCloud[T]) Compute(highs, lows, closings <-chan T) (<-chan T, <-chan T, <-chan T, <-chan T, <-chan T)

Compute function takes a channel of numbers and computes the Ichimoku Cloud. Returns conversionLine, baseLine, leadingSpanA, leadingSpanB, laggingSpan

func (*IchimokuCloud[T]) IdlePeriod

func (i *IchimokuCloud[T]) IdlePeriod() int

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

type Ppo

Ppo represents the configuration parameter for calculating the Percentage Price Oscillator (PPO). It is a momentum oscillator for the price. It is used to indicate the ups and downs based on the price. A breakout is confirmed when PPO is positive.

PPO = ((EMA(shortPeriod, prices) - EMA(longPeriod, prices)) / EMA(longPeriod, prices)) * 100
Signal = EMA(9, PPO)
Histogram = PPO - Signal

Example:

ppo := momentum.Ppo[float64]()
p, s, h := ppo.Compute(closings)
type Ppo[T helper.Number] struct {
    // ShortEma is the short EMA instance.
    ShortEma *trend.Ema[T]

    // LongEma is the long EMA instance.
    LongEma *trend.Ema[T]

    // SignalEma is the signal EMA instance.
    SignalEma *trend.Ema[T]
}

func NewPpo

func NewPpo[T helper.Number]() *Ppo[T]

NewPpo function initializes a new Percentage Price Oscillator instance.

func (*Ppo[T]) Compute

func (p *Ppo[T]) Compute(closings <-chan T) (<-chan T, <-chan T, <-chan T)

Compute function takes a channel of numbers and computes the Percentage Price Oscillator. Returns ppo, signal, histogram.

func (*Ppo[T]) IdlePeriod

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

IdlePeriod is the initial period that Percentage Price Oscillator won't yield any results.

PringsSpecialK implements Martin Pring's Special K momentum indicator. It composes multiple Rate-of-Change (ROC) series smoothed by Simple Moving Averages (SMA) and outputs a weighted sum aligned to the slowest path so all terms are time-synchronized. See Compute for the exact composition and weights.

type PringsSpecialK[T helper.Float] struct {
    Roc10  *trend.Roc[T]
    Roc15  *trend.Roc[T]
    Roc20  *trend.Roc[T]
    Roc30  *trend.Roc[T]
    Roc40  *trend.Roc[T]
    Roc65  *trend.Roc[T]
    Roc75  *trend.Roc[T]
    Roc100 *trend.Roc[T]
    Roc195 *trend.Roc[T]
    Roc265 *trend.Roc[T]
    Roc390 *trend.Roc[T]
    Roc530 *trend.Roc[T]

    Sma10Roc10   *trend.Sma[T]
    Sma10Roc15   *trend.Sma[T]
    Sma10Roc20   *trend.Sma[T]
    Sma15Roc30   *trend.Sma[T]
    Sma50Roc40   *trend.Sma[T]
    Sma65Roc65   *trend.Sma[T]
    Sma75Roc75   *trend.Sma[T]
    Sma100Roc100 *trend.Sma[T]
    Sma130Roc195 *trend.Sma[T]
    Sma130Roc265 *trend.Sma[T]
    Sma130Roc390 *trend.Sma[T]
    Sma195Roc530 *trend.Sma[T]
}

func NewPringsSpecialK[T helper.Float]() *PringsSpecialK[T]

NewPringsSpecialK function initializes a new Martin Pring's Special K instance.

func (*PringsSpecialK[T]) Compute

func (p *PringsSpecialK[T]) Compute(closings <-chan T) <-chan T

Compute function takes a channel of numbers and computes the Prings Special K.

type Pvo

Pvo represents the configuration parameter for calculating the Percentage Volume Oscillator (PVO). It is a momentum oscillator for the price. It is used to indicate the ups and downs based on the price. A breakout is confirmed when PVO is positive.

PVO = ((EMA(shortPeriod, prices) - EMA(longPeriod, prices)) / EMA(longPeriod, prices)) * 100
Signal = EMA(9, PVO)
Histogram = PVO - Signal

Example:

pvo := momentum.Pvo[float64]()
p, s, h := pvo.Compute(volumes)
type Pvo[T helper.Number] struct {
    // ShortEma is the short EMA instance.
    ShortEma *trend.Ema[T]

    // LongEma is the long EMA instance.
    LongEma *trend.Ema[T]

    // SignalEma is the signal EMA instance.
    SignalEma *trend.Ema[T]
}

func NewPvo

func NewPvo[T helper.Number]() *Pvo[T]

NewPvo function initializes a new Percentage Volume Oscillator instance.

func (*Pvo[T]) Compute

func (p *Pvo[T]) Compute(volumes <-chan T) (<-chan T, <-chan T, <-chan T)

Compute function takes a channel of numbers and computes the Percentage Volume Oscillator. Returns pvo, signal, histogram.

func (*Pvo[T]) IdlePeriod

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

IdlePeriod is the initial period that Percentage Volume Oscillator won't yield any results.

type Qstick

Qstick represents the configuration parameter for calculating the Qstick indicator. Qstick is a momentum indicator used to identify an asset's trend by looking at the SMA of the difference between its closing and opening.

A Qstick above zero indicates increasing buying pressure, while a Qstick below zero indicates increasing selling pressure.

QS = SMA(Closings - Openings)

Example:

qstick := momentum.Qstick[float64]()
qstick.Sma.Period = 50

values := qstick.Compute(openings, closings)
type Qstick[T helper.Number] struct {
    Sma *trend.Sma[T]
}

func NewQstick[T helper.Number]() *Qstick[T]

NewQstick function initializes a new QStick instance.

func (*Qstick[T]) Compute

func (q *Qstick[T]) Compute(openings, closings <-chan T) <-chan T

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

func (*Qstick[T]) IdlePeriod

func (q *Qstick[T]) IdlePeriod() int

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

type Rsi

Rsi represents the configuration parameter for calculating the Relative Strength Index (RSI). It is a momentum indicator that measures the magnitude of recent price changes to evaluate overbought and oversold conditions.

RS = Average Gain / Average Loss
RSI = 100 - (100 / (1 + RS))

Example:

rsi := momentum.NewRsi[float64]()
result := rsi.Compute(closings)
type Rsi[T helper.Number] struct {
    // Rma is the RMA instance.
    Rma *trend.Rma[T]
}

func NewRsi

func NewRsi[T helper.Number]() *Rsi[T]

NewRsi function initializes a new Relative Strength Index instance with the default parameters.

func NewRsiWithPeriod[T helper.Number](period int) *Rsi[T]

NewRsiWithPeriod function initializes a new Relative Strength Index instance with the given period.

func (*Rsi[T]) Compute

func (r *Rsi[T]) Compute(closings <-chan T) <-chan T

Compute function takes a channel of closings numbers and computes the Relative Strength Index.

func (*Rsi[T]) IdlePeriod

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

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

type Rvi

Rvi represents the configuration parameters for calculating the Relative Vigor Index (RVI). The RVI is a momentum indicator that measures the strength of a trend by comparing close and open prices.

The indicator uses a 4-bar FIR filter with weights 1-2-2-1:

Numerator = Close - Open
Denominator = High - Low
FIR(Numerator) = (1*Num[0] + 2*Num[1] + 2*Num[2] + 1*Num[3]) / 6
FIR(Denominator) = (1*Den[0] + 2*Den[1] + 2*Den[2] + 1*Den[3]) / 6
RVI = SMA(FIR(Numerator), period) / SMA(FIR(Denominator), period)
Signal = SMA(RVI, signalPeriod)

Example:

rvi := momentum.NewRvi[float64]()
rviResult, signalResult := rvi.Compute(opens, highs, lows, closings)
type Rvi[T helper.Float] struct {
    // Period is the lookback period for the RVI.
    Period int

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

func NewRvi

func NewRvi[T helper.Float]() *Rvi[T]

NewRvi function initializes a new RVI instance.

func (*Rvi[T]) Compute

func (r *Rvi[T]) Compute(opens, highs, lows, closings <-chan T) (rviResult <-chan T, signalResult <-chan T)

Compute function takes channels of OHLC numbers and computes the Relative Vigor Index and its signal line.

func (*Rvi[T]) IdlePeriod

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

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

func (*Rvi[T]) String

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

String is the string representation of the RVI.

StochasticOscillator represents the configuration parameter for calculating the Stochastic Oscillator. It is a momentum indicator that shows the location of the closing relative to high-low range over a set number of periods.

K = (Closing - Lowest Low) / (Highest High - Lowest Low) * 100
D = 3-Period SMA of K

Example:

so := momentum.StochasticOscillator[float64]()
k, d := wr.Compute(highs, lows, closings)
type StochasticOscillator[T helper.Number] struct {
    // Max is the Moving Max instance.
    Max *trend.MovingMax[T]

    // Min is the Moving Min instance.
    Min *trend.MovingMin[T]

    // Sma is the SMA instance.
    Sma *trend.Sma[T]
}

func NewStochasticOscillator[T helper.Number]() *StochasticOscillator[T]

NewStochasticOscillator function initializes a new Stochastic Oscillator instance.

func (*StochasticOscillator[T]) Compute

func (s *StochasticOscillator[T]) Compute(highs, lows, closings <-chan T) (<-chan T, <-chan T)

Compute function takes a channel of numbers and computes the Stochastic Oscillator. Returns k and d.

func (*StochasticOscillator[T]) IdlePeriod

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

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

StochasticRsi represents the configuration parameter for calculating the Stochastic Relative Strength Index (RSI). It is a momentum indicator that focuses on the historical performance to evaluate overbought and oversold conditions.

RSI - Min(RSI)
Stochastic RSI = -------------------------
                   Max(RSI) - Min(RSI)

Example:

stochasticRsi := momentum.NewStochasticRsi[float64]()
result := stochasticRsi.Compute(closings)
type StochasticRsi[T helper.Number] struct {
    // Rsi is that RSI instance.
    Rsi *Rsi[T]

    // Min is the Moving Min instance.
    Min *trend.MovingMin[T]

    // Max is the Moving Max instance.
    Max *trend.MovingMax[T]
}

func NewStochasticRsi[T helper.Number]() *StochasticRsi[T]

NewStochasticRsi function initializes a new Storchastic RSI instance with the default parameters.

func NewStochasticRsiWithPeriod[T helper.Number](period int) *StochasticRsi[T]

NewStochasticRsiWithPeriod function initializes a new Stochastic RSI instance with the given period.

func (*StochasticRsi[T]) Compute

func (s *StochasticRsi[T]) Compute(closings <-chan T) <-chan T

Compute function takes a channel of closings numbers and computes the Stochastic RSI.

func (*StochasticRsi[T]) IdlePeriod

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

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

type Streak

Streak represents the configuration for calculating the up/down streak length. The streak is the number of consecutive days the price has closed up or down.

type Streak[T helper.Float] struct{}

func NewStreak[T helper.Float]() *Streak[T]

NewStreak function initializes a new Streak instance.

func (*Streak[T]) Compute

func (s *Streak[T]) Compute(closings <-chan T) <-chan T

Compute function takes a channel of closings numbers and computes the streak length. Positive values indicate consecutive up closes, negative values indicate consecutive down closes.

func (*Streak[T]) IdlePeriod

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

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

TdSequential represents the configuration parameters for calculating the Tom DeMark's TD Sequential indicator. TD Sequential is a momentum indicator that identifies potential trend exhaustion and reversals.

The indicator consists of two phases:

TD Setup: Counts 9 consecutive closes higher (sell) or lower (buy) than
the close 4 bars ago.

TD Countdown: After a completed setup, counts 13 closes higher (sell) or
lower (buy) than the close 2 bars ago.

Example:

td := momentum.NewTdSequential[float64]()
buySetup, sellSetup, buyCountdown, sellCountdown := td.Compute(closings)
type TdSequential[T helper.Number] struct {
    // Lookback is the number of bars to look back for comparison in the setup phase.
    Lookback int

    // CountdownLookback is the number of bars to look back for comparison in the countdown phase.
    CountdownLookback int

    // SetupPeriod is the number of consecutive closes required to complete a setup.
    SetupPeriod int

    // CountdownPeriod is the number of closes required to complete a countdown.
    CountdownPeriod int
}

func NewTdSequential[T helper.Number]() *TdSequential[T]

NewTdSequential function initializes a new TD Sequential instance with default parameters.

func (*TdSequential[T]) Compute

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

Compute function takes a channel of numbers and computes the TD Sequential indicator. Returns four channels: buySetup, sellSetup, buyCountdown, sellCountdown.

func (*TdSequential[T]) IdlePeriod

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

IdlePeriod is the initial period that TD Sequential won't yield meaningful results.

UltimateOscillator represents the configuration parameter for calculating the Ultimate Oscillator (UO). It was developed by Larry Williams in 1976 to measure the price momentum of an asset across multiple timeframes. By using the weighted average of three different timeframes the indicator has less volatility and fewer trade signals compared to other oscillators that rely on a single timeframe.

BP = Close - Minimum(Low, Prior Close)
TR = Maximum(High, Prior Close) - Minimum(Low, Prior Close)
Average7 = Sum(BP for 7 periods) / Sum(TR for 7 periods)
Average14 = Sum(BP for 14 periods) / Sum(TR for 14 periods)
Average28 = Sum(BP for 28 periods) / Sum(TR for 28 periods)
UO = 100 * [(4 * Average7) + (2 * Average14) + Average28] / (4 + 2 + 1)

Example:

uo := momentum.NewUltimateOscillator[float64]()
values := uo.Compute(highs, lows, closings)
type UltimateOscillator[T helper.Number] struct {
    // ShortPeriod is the short period for the UO.
    ShortPeriod int

    // MediumPeriod is the medium period for the UO.
    MediumPeriod int

    // LongPeriod is the long period for the UO.
    LongPeriod int
}

func NewUltimateOscillator[T helper.Number]() *UltimateOscillator[T]

NewUltimateOscillator function initializes a new Ultimate Oscillator instance.

func NewUltimateOscillatorWithPeriods[T helper.Number](shortPeriod, mediumPeriod, longPeriod int) *UltimateOscillator[T]

NewUltimateOscillatorWithPeriods function initializes a new Ultimate Oscillator instance with the given periods.

func (*UltimateOscillator[T]) Compute

func (u *UltimateOscillator[T]) Compute(highs, lows, closings <-chan T) <-chan T

Compute function takes a channel of numbers and computes the Ultimate Oscillator.

func (*UltimateOscillator[T]) IdlePeriod

func (u *UltimateOscillator[T]) IdlePeriod() int

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

func (*UltimateOscillator[T]) String

func (u *UltimateOscillator[T]) String() string

WilliamsR represents the configuration parameter for calculating the Williams %R, or just %R. It is a technical analysis oscillator showing the current closing price in relation to the high and low of the past N days (for a given N). It was developed by a publisher and promoter of trading materials, Larry Williams. Its purpose is to tell whether a stock or commodity market is trading near the high or the low, or somewhere in between, of its recent trading range. Buy when -80 and below. Sell when -20 and above.

WR = (Highest High - Closing) / (Highest High - Lowest Low) * -100.

Example:

wr := momentum.WilliamsR[float64]()
values := wr.Compute(highs, lows, closings)
type WilliamsR[T helper.Number] struct {
    // Max is the Moving Max instance.
    Max *trend.MovingMax[T]

    // Min is the Moving Min instance.
    Min *trend.MovingMin[T]
}

func NewWilliamsR[T helper.Number]() *WilliamsR[T]

NewWilliamsR function initializes a new Williams R instance.

func (*WilliamsR[T]) Compute

func (w *WilliamsR[T]) Compute(highs, lows, closings <-chan T) <-chan T

Compute function takes a channel of numbers and computes the Williams R.

func (*WilliamsR[T]) IdlePeriod

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

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

Generated by gomarkdoc