momentum
May 29, 2026 · View on GitHub
import "github.com/cinar/indicator/v2/strategy/momentum"
Package momentum contains the momentum strategy 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
- func AllStrategies() []strategy.Strategy
- type AwesomeOscillatorStrategy
- func NewAwesomeOscillatorStrategy() *AwesomeOscillatorStrategy
- func (a *AwesomeOscillatorStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (a *AwesomeOscillatorStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (*AwesomeOscillatorStrategy) Name() string
- func (a *AwesomeOscillatorStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
- type ElderRayStrategy
- func NewElderRayStrategy() *ElderRayStrategy
- func (e *ElderRayStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (e *ElderRayStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (*ElderRayStrategy) Name() string
- func (e *ElderRayStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
- type IchimokuCloudStrategy
- func NewIchimokuCloudStrategy() *IchimokuCloudStrategy
- func (i *IchimokuCloudStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (i *IchimokuCloudStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (*IchimokuCloudStrategy) Name() string
- func (i *IchimokuCloudStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
- type RsiStrategy
- func NewRsiStrategy() *RsiStrategy
- func NewRsiStrategyWith(buyAt, sellAt float64) *RsiStrategy
- func (r *RsiStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (r *RsiStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (r *RsiStrategy) Name() string
- func (r *RsiStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
- type StochasticOscillatorStrategy
- func NewStochasticOscillatorStrategy() *StochasticOscillatorStrategy
- func NewStochasticOscillatorStrategyWith(buyAt, sellAt float64) *StochasticOscillatorStrategy
- func (s *StochasticOscillatorStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (s *StochasticOscillatorStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (s *StochasticOscillatorStrategy) Name() string
- func (s *StochasticOscillatorStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
- type StochasticRsiStrategy
- func NewStochasticRsiStrategy() *StochasticRsiStrategy
- func NewStochasticRsiStrategyWith(buyAt, sellAt float64) *StochasticRsiStrategy
- func (s *StochasticRsiStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (s *StochasticRsiStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (s *StochasticRsiStrategy) Name() string
- func (s *StochasticRsiStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
- type TripleRsiStrategy
- func NewTripleRsiStrategy() *TripleRsiStrategy
- func NewTripleRsiStrategyWith(period, smaPeriod, downDays int, buySignalAt, buyAt, sellAt float64) *TripleRsiStrategy
- func (t *TripleRsiStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (t *TripleRsiStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (t *TripleRsiStrategy) IdlePeriod() int
- func (t *TripleRsiStrategy) Name() string
- func (t *TripleRsiStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
- type WilliamsRStrategy
- func NewWilliamsRStrategy() *WilliamsRStrategy
- func NewWilliamsRStrategyWith(buyAt, sellAt float64) *WilliamsRStrategy
- func (r *WilliamsRStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (r *WilliamsRStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (r *WilliamsRStrategy) Name() string
- func (r *WilliamsRStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
Constants
const (
// DefaultRsiStrategyBuyAt defines the default RSI level at which a Buy action is generated.
DefaultRsiStrategyBuyAt = 30
// DefaultRsiStrategySellAt defines the default RSI level at which a Sell action is generated.
DefaultRsiStrategySellAt = 70
)
const (
// DefaultStochasticOscillatorStrategyBuyAt defines the default K level at which a Buy action is generated.
DefaultStochasticOscillatorStrategyBuyAt = 20.0
// DefaultStochasticOscillatorStrategySellAt defines the default K level at which a Sell action is generated.
DefaultStochasticOscillatorStrategySellAt = 80.0
)
const (
// DefaultStochasticRsiStrategyBuyAt defines the default level at which a Buy action is generated.
DefaultStochasticRsiStrategyBuyAt = 0.8
// DefaultStochasticRsiStrategySellAt defines the default level at which a Sell action is generated.
DefaultStochasticRsiStrategySellAt = 0.2
)
const (
// DefaultTripleRsiStrategyPeriod defines the default period for the RSI.
DefaultTripleRsiStrategyPeriod = 5
// DefaultTripleRsiStrategyMovingAveragePeriod defines the default period for the SMA.
DefaultTripleRsiStrategyMovingAveragePeriod = 200
// DefaultTripleRsiStrategyDownDays defines the default number of down days for the RSI.
DefaultTripleRsiStrategyDownDays = 3
// DefaultTripleRsiStrategyBuySignalAt defines the default RSI level at which a Buy signal is confirmed.
DefaultTripleRsiStrategyBuySignalAt = 60
// DefaultTripleRsiStrategyBuyAt defines the default RSI level at which a Buy action is generated.
DefaultTripleRsiStrategyBuyAt = 30
// DefaultTripleRsiStrategySellAt defines the default RSI level at which a Sell action is generated.
DefaultTripleRsiStrategySellAt = 50
)
const (
// DefaultWilliamsRStrategyBuyAt defines the default Williams R level at which a Buy action is generated.
DefaultWilliamsRStrategyBuyAt = -80.0
// DefaultWilliamsRStrategySellAt defines the default Williams R level at which a Sell action is generated.
DefaultWilliamsRStrategySellAt = -20.0
)
func AllStrategies
func AllStrategies() []strategy.Strategy
AllStrategies returns a slice containing references to all available momentum strategies.
type AwesomeOscillatorStrategy
AwesomeOscillatorStrategy represents the configuration parameters for calculating the Awesome Oscillator strategy.
type AwesomeOscillatorStrategy struct {
// AwesomeOscillator represents the configuration parameters for calculating the Awesome Oscillator.
AwesomeOscillator *momentum.AwesomeOscillator[float64]
}
func NewAwesomeOscillatorStrategy
func NewAwesomeOscillatorStrategy() *AwesomeOscillatorStrategy
NewAwesomeOscillatorStrategy function initializes a new Awesome Oscillator strategy with the default parameters.
func (*AwesomeOscillatorStrategy) Compute
func (a *AwesomeOscillatorStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action
Compute wraps ComputeWithContext for backwards compatibility.
Deprecated: Use ComputeWithContext instead.
func (*AwesomeOscillatorStrategy) ComputeWithContext
func (a *AwesomeOscillatorStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.Action
ComputeWithContext processes the provided asset snapshots and generates a stream of actionable recommendations.
func (*AwesomeOscillatorStrategy) Name
func (*AwesomeOscillatorStrategy) Name() string
Name returns the name of the strategy.
func (*AwesomeOscillatorStrategy) Report
func (a *AwesomeOscillatorStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
Report processes the provided asset snapshots and generates a report annotated with the recommended actions.
type ElderRayStrategy
ElderRayStrategy represents the configuration parameters for calculating the Elder Ray strategy. Buy when EMA is rising and Bear Power is negative but rising. Sell when EMA is falling and Bull Power is positive but falling.
type ElderRayStrategy struct {
// ElderRay represents the configuration parameters for calculating the Elder-Ray Index.
ElderRay *momentum.ElderRay[float64]
}
func NewElderRayStrategy
func NewElderRayStrategy() *ElderRayStrategy
NewElderRayStrategy function initializes a new Elder Ray strategy instance with the default parameters.
func (*ElderRayStrategy) Compute
func (e *ElderRayStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action
Compute wraps ComputeWithContext for backwards compatibility.
Deprecated: Use ComputeWithContext instead.
func (*ElderRayStrategy) ComputeWithContext
func (e *ElderRayStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.Action
ComputeWithContext processes the provided asset snapshots and generates a stream of actionable recommendations.
func (*ElderRayStrategy) Name
func (*ElderRayStrategy) Name() string
Name returns the name of the strategy.
func (*ElderRayStrategy) Report
func (e *ElderRayStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
Report processes the provided asset snapshots and generates a report annotated with the recommended actions.
type IchimokuCloudStrategy
IchimokuCloudStrategy represents the configuration parameters for calculating the Ichimoku Cloud strategy.
type IchimokuCloudStrategy struct {
// IchimokuCloud represents the configuration parameters for calculating the Ichimoku Cloud.
IchimokuCloud *momentum.IchimokuCloud[float64]
}
func NewIchimokuCloudStrategy
func NewIchimokuCloudStrategy() *IchimokuCloudStrategy
NewIchimokuCloudStrategy function initializes a new Ichimoku Cloud strategy with the default parameters.
func (*IchimokuCloudStrategy) Compute
func (i *IchimokuCloudStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action
Compute wraps ComputeWithContext for backwards compatibility.
Deprecated: Use ComputeWithContext instead.
func (*IchimokuCloudStrategy) ComputeWithContext
func (i *IchimokuCloudStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.Action
ComputeWithContext processes the provided asset snapshots and generates a stream of actionable recommendations.
func (*IchimokuCloudStrategy) Name
func (*IchimokuCloudStrategy) Name() string
Name returns the name of the strategy.
func (*IchimokuCloudStrategy) Report
func (i *IchimokuCloudStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
Report processes the provided asset snapshots and generates a report annotated with the recommended actions.
type RsiStrategy
RsiStrategy represents the configuration parameters for calculating the RSI strategy.
type RsiStrategy struct {
// Rsi represents the configuration parameters for calculating the Relative Strength Index (RSI).
Rsi *momentum.Rsi[float64]
// BuyAt defines the RSI level at which a Buy action is generated.
BuyAt float64
// SellAt defines the RSI level at which a Sell action is generated.
SellAt float64
}
func NewRsiStrategy
func NewRsiStrategy() *RsiStrategy
NewRsiStrategy function initializes a new RSI strategy instance with the default parameters.
func NewRsiStrategyWith
func NewRsiStrategyWith(buyAt, sellAt float64) *RsiStrategy
NewRsiStrategyWith function initializes a new RSI strategy instance with the given parameters.
func (*RsiStrategy) Compute
func (r *RsiStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action
Compute wraps ComputeWithContext for backwards compatibility.
Deprecated: Use ComputeWithContext instead.
func (*RsiStrategy) ComputeWithContext
func (r *RsiStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.Action
ComputeWithContext processes the provided asset snapshots and generates a stream of actionable recommendations.
func (*RsiStrategy) Name
func (r *RsiStrategy) Name() string
Name returns the name of the strategy.
func (*RsiStrategy) Report
func (r *RsiStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
Report processes the provided asset snapshots and generates a report annotated with the recommended actions.
type StochasticOscillatorStrategy
StochasticOscillatorStrategy represents the configuration parameters for calculating the Stochastic Oscillator strategy. When the K line is below the buy threshold, a Buy action is generated. When above the sell threshold, a Sell action is generated.
type StochasticOscillatorStrategy struct {
// StochasticOscillator represents the configuration parameters for calculating the Stochastic Oscillator.
StochasticOscillator *momentum.StochasticOscillator[float64]
// BuyAt defines the K level at which a Buy action is generated.
BuyAt float64
// SellAt defines the K level at which a Sell action is generated.
SellAt float64
}
func NewStochasticOscillatorStrategy
func NewStochasticOscillatorStrategy() *StochasticOscillatorStrategy
NewStochasticOscillatorStrategy function initializes a new Stochastic Oscillator strategy instance with the default parameters.
func NewStochasticOscillatorStrategyWith
func NewStochasticOscillatorStrategyWith(buyAt, sellAt float64) *StochasticOscillatorStrategy
NewStochasticOscillatorStrategyWith function initializes a new Stochastic Oscillator strategy instance with the given parameters.
func (*StochasticOscillatorStrategy) Compute
func (s *StochasticOscillatorStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action
Compute wraps ComputeWithContext for backwards compatibility.
Deprecated: Use ComputeWithContext instead.
func (*StochasticOscillatorStrategy) ComputeWithContext
func (s *StochasticOscillatorStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.Action
ComputeWithContext processes the provided asset snapshots and generates a stream of actionable recommendations.
func (*StochasticOscillatorStrategy) Name
func (s *StochasticOscillatorStrategy) Name() string
Name returns the name of the strategy.
func (*StochasticOscillatorStrategy) Report
func (s *StochasticOscillatorStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
Report processes the provided asset snapshots and generates a report annotated with the recommended actions.
type StochasticRsiStrategy
StochasticRsiStrategy represents the configuration parameters for calculating the Stochastic RSI strategy.
type StochasticRsiStrategy struct {
// StochasticRsi represents the configuration parameters for calculating the Stochastic RSI.
StochasticRsi *momentum.StochasticRsi[float64]
// BuyAt defines the level at which a Buy action is generated.
BuyAt float64
// SellAt defines the level at which a Sell action is generated.
SellAt float64
}
func NewStochasticRsiStrategy
func NewStochasticRsiStrategy() *StochasticRsiStrategy
NewStochasticRsiStrategy function initializes a new Stochastic RSI strategy instance with the default parameters.
func NewStochasticRsiStrategyWith
func NewStochasticRsiStrategyWith(buyAt, sellAt float64) *StochasticRsiStrategy
NewStochasticRsiStrategyWith function initializes a new Stochastic RSI strategy instance with the given parameters.
func (*StochasticRsiStrategy) Compute
func (s *StochasticRsiStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action
Compute wraps ComputeWithContext for backwards compatibility.
Deprecated: Use ComputeWithContext instead.
func (*StochasticRsiStrategy) ComputeWithContext
func (s *StochasticRsiStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.Action
ComputeWithContext processes the provided asset snapshots and generates a stream of actionable recommendations.
func (*StochasticRsiStrategy) Name
func (s *StochasticRsiStrategy) Name() string
Name returns the name of the strategy.
func (*StochasticRsiStrategy) Report
func (s *StochasticRsiStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
Report processes the provided asset snapshots and generates a report annotated with the recommended actions.
type TripleRsiStrategy
TripleRsiStrategy represents the configuration parameters for calculating the Triple RSI strategy. It assumes that the moving average period is longer than the RSI period.
Recommend Buy: - The 5-period RSI is below 30. - The 5-period RSI reading is down for the 3rd period in a row. - The 5-period RSI reading was below 60 three trading periods ago. - The close is higher than the 200-period moving average.
Recommend Sell: - Sell at the close when the 5-period RSI crosses above 50.
Based on [Triple RSI Trading Strategy: Enhance Your Win Rate to 90% — Advanced Insights](https://tradingstrategy.medium.com/triple-rsi-trading-strategy-enhance-your-win-rate-to-90-advanced-insights-6143059ce41d\).
type TripleRsiStrategy struct {
// Rsi represents the configuration parameters for calculating the Relative Strength Index (RSI).
Rsi *momentum.Rsi[float64]
// Sma represents the configuration parameters for calculating the Simple Moving Average (SMA).
Sma *trend.Sma[float64]
// DownDays is the number of down days for RSI.
DownDays int
// BuySignalAt defines the RSI level at which a Buy signal is confirmed.
BuySignalAt float64
// BuyAt defines the RSI level at which a Buy action is generated.
BuyAt float64
// SellAt defines the RSI level at which a Sell action is generated.
SellAt float64
}
func NewTripleRsiStrategy
func NewTripleRsiStrategy() *TripleRsiStrategy
NewTripleRsiStrategy function initializes a new Triple RSI strategy instance with the default parameters.
func NewTripleRsiStrategyWith
func NewTripleRsiStrategyWith(period, smaPeriod, downDays int, buySignalAt, buyAt, sellAt float64) *TripleRsiStrategy
NewTripleRsiStrategyWith function initializes a new RSI strategy instance with the given parameters.
func (*TripleRsiStrategy) Compute
func (t *TripleRsiStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action
Compute wraps ComputeWithContext for backwards compatibility.
Deprecated: Use ComputeWithContext instead.
func (*TripleRsiStrategy) ComputeWithContext
func (t *TripleRsiStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.Action
ComputeWithContext processes the provided asset snapshots and generates a stream of actionable recommendations.
func (*TripleRsiStrategy) IdlePeriod
func (t *TripleRsiStrategy) IdlePeriod() int
IdlePeriod is the initial period that the Triple RSI strategy won't yield any results.
func (*TripleRsiStrategy) Name
func (t *TripleRsiStrategy) Name() string
Name returns the name of the strategy.
func (*TripleRsiStrategy) Report
func (t *TripleRsiStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
Report processes the provided asset snapshots and generates a report annotated with the recommended actions.
type WilliamsRStrategy
WilliamsRStrategy represents the configuration parameters for calculating the Williams R strategy.
type WilliamsRStrategy struct {
// WilliamsR represents the configuration parameters for calculating the Williams %R.
WilliamsR *momentum.WilliamsR[float64]
// BuyAt defines the Williams R level at which a Buy action is generated.
BuyAt float64
// SellAt defines the Williams R level at which a Sell action is generated.
SellAt float64
}
func NewWilliamsRStrategy
func NewWilliamsRStrategy() *WilliamsRStrategy
NewWilliamsRStrategy function initializes a new Williams R strategy instance with the default parameters.
func NewWilliamsRStrategyWith
func NewWilliamsRStrategyWith(buyAt, sellAt float64) *WilliamsRStrategy
NewWilliamsRStrategyWith function initializes a new Williams R strategy instance with the given parameters.
func (*WilliamsRStrategy) Compute
func (r *WilliamsRStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action
Compute wraps ComputeWithContext for backwards compatibility.
Deprecated: Use ComputeWithContext instead.
func (*WilliamsRStrategy) ComputeWithContext
func (r *WilliamsRStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.Action
ComputeWithContext processes the provided asset snapshots and generates a stream of actionable recommendations.
func (*WilliamsRStrategy) Name
func (r *WilliamsRStrategy) Name() string
Name returns the name of the strategy.
func (*WilliamsRStrategy) Report
func (r *WilliamsRStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
Report processes the provided asset snapshots and generates a report annotated with the recommended actions.
Generated by gomarkdoc