import "github.com/cinar/indicator/v2/examples/momentum"Package momentum provides illustrative examples demonstrating how to compose momentum indicators into trading strategies for educational and research purposes.
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.
Copyright (c) 2021-2026 The Indicator Authors.
The source code is provided under GNU AGPLv3 License.
https://github.com/cinar/indicator
The information provided on this project is strictly for informational and educational purposes and is not to be construed as investment, financial, or trading advice.
- 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 CoppockCurveStrategy
- func NewCoppockCurveStrategy() *CoppockCurveStrategy
- func (c *CoppockCurveStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (c *CoppockCurveStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (*CoppockCurveStrategy) Name() string
- func (c *CoppockCurveStrategy) Report(cr <-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
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.2
// DefaultStochasticRsiStrategySellAt defines the default level at which a Sell action is generated.
DefaultStochasticRsiStrategySellAt = 0.8
)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.StrategyAllStrategies returns a slice containing references to all available example momentum strategies.
AwesomeOscillatorStrategy demonstrates how to compose the Awesome Oscillator indicator into an illustrative zero-line crossover strategy.
type AwesomeOscillatorStrategy struct {
// AwesomeOscillator represents the configuration parameters for calculating the Awesome Oscillator.
AwesomeOscillator *momentum.AwesomeOscillator[float64]
}func NewAwesomeOscillatorStrategy() *AwesomeOscillatorStrategyNewAwesomeOscillatorStrategy initializes an example AwesomeOscillatorStrategy instance with default parameters.
func (*AwesomeOscillatorStrategy) Compute
func (a *AwesomeOscillatorStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.ActionCompute 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.ActionComputeWithContext processes the provided asset snapshots and generates an illustrative stream of actions.
func (*AwesomeOscillatorStrategy) Name
func (*AwesomeOscillatorStrategy) Name() stringName returns the name of the example strategy.
func (*AwesomeOscillatorStrategy) Report
func (a *AwesomeOscillatorStrategy) Report(c <-chan *asset.Snapshot) *helper.ReportReport processes the provided asset snapshots and generates an illustrative report annotated with example actions.
type CoppockCurveStrategy
CoppockCurveStrategy demonstrates how to compose the Coppock Curve indicator into an illustrative zero-line crossover strategy.
type CoppockCurveStrategy struct {
// CoppockCurve represents the configuration parameters for calculating the Coppock Curve.
CoppockCurve *momentum.CoppockCurve[float64]
}func NewCoppockCurveStrategy() *CoppockCurveStrategyNewCoppockCurveStrategy initializes an example CoppockCurveStrategy instance with default parameters.
func (*CoppockCurveStrategy) Compute
func (c *CoppockCurveStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.ActionCompute wraps ComputeWithContext for backwards compatibility.
Deprecated: Use ComputeWithContext instead.
func (*CoppockCurveStrategy) ComputeWithContext
func (c *CoppockCurveStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.ActionComputeWithContext processes the provided asset snapshots and generates an illustrative stream of actions.
func (*CoppockCurveStrategy) Name
func (*CoppockCurveStrategy) Name() stringName returns the name of the example strategy.
func (*CoppockCurveStrategy) Report
func (c *CoppockCurveStrategy) Report(cr <-chan *asset.Snapshot) *helper.ReportReport processes the provided asset snapshots and generates an illustrative report annotated with example actions.
type ElderRayStrategy
ElderRayStrategy demonstrates how to compose Elder-Ray Bull Power and Bear Power indicators into an illustrative strategy.
type ElderRayStrategy struct {
// ElderRay represents the configuration parameters for calculating the Elder-Ray Index.
ElderRay *momentum.ElderRay[float64]
}func NewElderRayStrategy
func NewElderRayStrategy() *ElderRayStrategyNewElderRayStrategy initializes an example ElderRayStrategy instance with default parameters.
func (*ElderRayStrategy) Compute
func (e *ElderRayStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.ActionCompute 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.ActionComputeWithContext processes the provided asset snapshots and generates an illustrative stream of actions.
func (*ElderRayStrategy) Name
func (*ElderRayStrategy) Name() stringName returns the name of the example strategy.
func (*ElderRayStrategy) Report
func (e *ElderRayStrategy) Report(c <-chan *asset.Snapshot) *helper.ReportReport processes the provided asset snapshots and generates an illustrative report annotated with example actions.
IchimokuCloudStrategy demonstrates how to compose Tenkan-sen and Kijun-sen lines from the Ichimoku Cloud into an illustrative crossover strategy.
type IchimokuCloudStrategy struct {
// IchimokuCloud represents the configuration parameters for calculating the Ichimoku Cloud.
IchimokuCloud *momentum.IchimokuCloud[float64]
}func NewIchimokuCloudStrategy() *IchimokuCloudStrategyNewIchimokuCloudStrategy initializes an example IchimokuCloudStrategy instance with default parameters.
func (*IchimokuCloudStrategy) Compute
func (i *IchimokuCloudStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.ActionCompute 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.ActionComputeWithContext processes the provided asset snapshots and generates an illustrative stream of actions.
func (*IchimokuCloudStrategy) Name
func (*IchimokuCloudStrategy) Name() stringName returns the name of the example strategy.
func (*IchimokuCloudStrategy) Report
func (i *IchimokuCloudStrategy) Report(c <-chan *asset.Snapshot) *helper.ReportReport processes the provided asset snapshots and generates an illustrative report annotated with example actions.
type RsiStrategy
RsiStrategy demonstrates how to compose the Relative Strength Index (RSI) into an illustrative threshold-based overbought/oversold 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() *RsiStrategyNewRsiStrategy initializes an example RsiStrategy instance with default parameters.
func NewRsiStrategyWith
func NewRsiStrategyWith(buyAt, sellAt float64) *RsiStrategyNewRsiStrategyWith initializes an example RsiStrategyWith instance with default parameters.
func (*RsiStrategy) Compute
func (r *RsiStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.ActionCompute 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.ActionComputeWithContext processes the provided asset snapshots and generates an illustrative stream of actions.
func (*RsiStrategy) Name
func (r *RsiStrategy) Name() stringName returns the name of the example strategy.
func (*RsiStrategy) Report
func (r *RsiStrategy) Report(c <-chan *asset.Snapshot) *helper.ReportReport processes the provided asset snapshots and generates an illustrative report annotated with example actions.
StochasticOscillatorStrategy demonstrates how to compose %K and %D Stochastic Oscillator lines into an illustrative crossover strategy.
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() *StochasticOscillatorStrategyNewStochasticOscillatorStrategy initializes an example StochasticOscillatorStrategy instance with default parameters. the default parameters.
func NewStochasticOscillatorStrategyWith(buyAt, sellAt float64) *StochasticOscillatorStrategyNewStochasticOscillatorStrategyWith initializes an example StochasticOscillatorStrategyWith instance with default parameters. the given parameters.
func (*StochasticOscillatorStrategy) Compute
func (s *StochasticOscillatorStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.ActionCompute 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.ActionComputeWithContext processes the provided asset snapshots and generates an illustrative stream of actions.
func (*StochasticOscillatorStrategy) Name
func (s *StochasticOscillatorStrategy) Name() stringName returns the name of the example strategy.
func (*StochasticOscillatorStrategy) Report
func (s *StochasticOscillatorStrategy) Report(c <-chan *asset.Snapshot) *helper.ReportReport processes the provided asset snapshots and generates an illustrative report annotated with example actions.
StochasticRsiStrategy demonstrates how to compose Stochastic RSI indicator lines into an illustrative crossover 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() *StochasticRsiStrategyNewStochasticRsiStrategy initializes an example StochasticRsiStrategy instance with default parameters.
func NewStochasticRsiStrategyWith(buyAt, sellAt float64) *StochasticRsiStrategyNewStochasticRsiStrategyWith initializes an example StochasticRsiStrategyWith instance with default parameters.
func (*StochasticRsiStrategy) Compute
func (s *StochasticRsiStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.ActionCompute 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.ActionComputeWithContext processes the provided asset snapshots and generates an illustrative stream of actions.
func (*StochasticRsiStrategy) Name
func (s *StochasticRsiStrategy) Name() stringName returns the name of the example strategy.
func (*StochasticRsiStrategy) Report
func (s *StochasticRsiStrategy) Report(c <-chan *asset.Snapshot) *helper.ReportReport processes the provided asset snapshots and generates an illustrative report annotated with example actions.
type TripleRsiStrategy
TripleRsiStrategy demonstrates how to compose three Relative Strength Index (RSI) calculations of varying periods into an illustrative multi-timeframe strategy.
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() *TripleRsiStrategyNewTripleRsiStrategy initializes an example TripleRsiStrategy instance with default parameters.
func NewTripleRsiStrategyWith(period, smaPeriod, downDays int, buySignalAt, buyAt, sellAt float64) *TripleRsiStrategyNewTripleRsiStrategyWith initializes an example TripleRsiStrategyWith instance with default parameters.
func (*TripleRsiStrategy) Compute
func (t *TripleRsiStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.ActionCompute 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.ActionComputeWithContext processes the provided asset snapshots and generates an illustrative stream of actions.
func (*TripleRsiStrategy) IdlePeriod
func (t *TripleRsiStrategy) IdlePeriod() intIdlePeriod is the initial period that the Triple RSI strategy won't yield any results.
func (*TripleRsiStrategy) Name
func (t *TripleRsiStrategy) Name() stringName returns the name of the example strategy.
func (*TripleRsiStrategy) Report
func (t *TripleRsiStrategy) Report(c <-chan *asset.Snapshot) *helper.ReportReport processes the provided asset snapshots and generates an illustrative report annotated with example actions.
type WilliamsRStrategy
WilliamsRStrategy demonstrates how to compose Williams %R into an illustrative threshold-based 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() *WilliamsRStrategyNewWilliamsRStrategy initializes an example WilliamsRStrategy instance with default parameters.
func NewWilliamsRStrategyWith(buyAt, sellAt float64) *WilliamsRStrategyNewWilliamsRStrategyWith initializes an example WilliamsRStrategyWith instance with default parameters.
func (*WilliamsRStrategy) Compute
func (r *WilliamsRStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.ActionCompute 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.ActionComputeWithContext processes the provided asset snapshots and generates an illustrative stream of actions.
func (*WilliamsRStrategy) Name
func (r *WilliamsRStrategy) Name() stringName returns the name of the example strategy.
func (*WilliamsRStrategy) Report
func (r *WilliamsRStrategy) Report(c <-chan *asset.Snapshot) *helper.ReportReport processes the provided asset snapshots and generates an illustrative report annotated with example actions.
Generated by gomarkdoc