Documentation
¶
Overview ¶
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-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 ¶
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 ( // 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 ( // 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 (
// 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
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AwesomeOscillator ¶
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] }
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)
func NewAwesomeOscillator ¶
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.
type ChaikinOscillator ¶
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] }
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)
func NewChaikinOscillator ¶
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.
type IchimokuCloud ¶
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 }
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)
func NewIchimokuCloud ¶
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 ¶
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] }
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)
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 ¶
IdlePeriod is the initial period that Percentage Price Oscillator won't yield any results.
type PringsSpecialK ¶ added in v2.1.17
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] }
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.
func NewPringsSpecialK ¶ added in v2.1.17
func NewPringsSpecialK[T helper.Float]() *PringsSpecialK[T]
NewPringsSpecialK function initializes a new Martin Pring's Special K instance.
func (*PringsSpecialK[T]) Compute ¶ added in v2.1.17
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 ¶
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] }
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)
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 ¶
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)
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 ¶
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)
func NewRsi ¶
NewRsi function initializes a new Relative Strength Index instance with the default parameters.
func NewRsiWithPeriod ¶
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 ¶
IdlePeriod is the initial period that Relative Strength Index won't yield any results.
type StochasticOscillator ¶
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] }
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)
func NewStochasticOscillator ¶
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.
type StochasticRsi ¶ added in v2.0.4
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] }
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)
func NewStochasticRsi ¶ added in v2.0.4
func NewStochasticRsi[T helper.Number]() *StochasticRsi[T]
NewStochasticRsi function initializes a new Storchastic RSI instance with the default parameters.
func NewStochasticRsiWithPeriod ¶ added in v2.0.4
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 ¶ added in v2.0.4
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 ¶ added in v2.0.4
func (s *StochasticRsi[T]) IdlePeriod() int
IdlePeriod is the initial period that Stochasic RSI won't yield any results.
type WilliamsR ¶
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] }
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)
func NewWilliamsR ¶
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 ¶
IdlePeriod is the initial period that Williams R won't yield any results.