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.
Copyright (c) 2021-2026 Onur Cinar.
The source code is provided under GNU AGPLv3 License.
https://github.com/cinar/indicator
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.
- Constants
- func AllStrategies() []strategy.Strategy
- type AwesomeOscillatorStrategy
- type IchimokuCloudStrategy
- type RsiStrategy
- 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) 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) 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) 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 (
// 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.StrategyAllStrategies returns a slice containing references to all available momentum strategies.
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() *AwesomeOscillatorStrategyNewAwesomeOscillatorStrategy function initializes a new Awesome Oscillator strategy with the default parameters.
func (*AwesomeOscillatorStrategy) Compute
func (a *AwesomeOscillatorStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.ActionCompute processes the provided asset snapshots and generates a stream of actionable recommendations.
func (*AwesomeOscillatorStrategy) Name
func (*AwesomeOscillatorStrategy) Name() stringName returns the name of the strategy.
func (*AwesomeOscillatorStrategy) Report
func (a *AwesomeOscillatorStrategy) Report(c <-chan *asset.Snapshot) *helper.ReportReport processes the provided asset snapshots and generates a report annotated with the recommended actions.
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() *IchimokuCloudStrategyNewIchimokuCloudStrategy function initializes a new Ichimoku Cloud strategy with the default parameters.
func (*IchimokuCloudStrategy) Compute
func (i *IchimokuCloudStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.ActionCompute processes the provided asset snapshots and generates a stream of actionable recommendations.
func (*IchimokuCloudStrategy) Name
func (*IchimokuCloudStrategy) Name() stringName returns the name of the strategy.
func (*IchimokuCloudStrategy) Report
func (i *IchimokuCloudStrategy) Report(c <-chan *asset.Snapshot) *helper.ReportReport 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() *RsiStrategyNewRsiStrategy function initializes a new RSI strategy instance with the default parameters.
func NewRsiStrategyWith
func NewRsiStrategyWith(buyAt, sellAt float64) *RsiStrategyNewRsiStrategyWith function initializes a new RSI strategy instance with the given parameters.
func (*RsiStrategy) Compute
func (r *RsiStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.ActionCompute processes the provided asset snapshots and generates a stream of actionable recommendations.
func (*RsiStrategy) Name
func (r *RsiStrategy) Name() stringName returns the name of the strategy.
func (*RsiStrategy) Report
func (r *RsiStrategy) Report(c <-chan *asset.Snapshot) *helper.ReportReport processes the provided asset snapshots and generates a report annotated with the recommended actions.
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() *StochasticRsiStrategyNewStochasticRsiStrategy function initializes a new Stochastic RSI strategy instance with the default parameters.
func NewStochasticRsiStrategyWith(buyAt, sellAt float64) *StochasticRsiStrategyNewStochasticRsiStrategyWith 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.ActionCompute processes the provided asset snapshots and generates a stream of actionable recommendations.
func (*StochasticRsiStrategy) Name
func (s *StochasticRsiStrategy) Name() stringName returns the name of the strategy.
func (*StochasticRsiStrategy) Report
func (s *StochasticRsiStrategy) Report(c <-chan *asset.Snapshot) *helper.ReportReport 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() *TripleRsiStrategyNewTripleRsiStrategy function initializes a new Triple RSI strategy instance with the default parameters.
func NewTripleRsiStrategyWith(period, smaPeriod, downDays int, buySignalAt, buyAt, sellAt float64) *TripleRsiStrategyNewTripleRsiStrategyWith function initializes a new RSI strategy instance with the given parameters.
func (*TripleRsiStrategy) Compute
func (t *TripleRsiStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.ActionCompute processes the provided asset snapshots and generates a stream of actionable recommendations.
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 strategy.
func (*TripleRsiStrategy) Report
func (t *TripleRsiStrategy) Report(c <-chan *asset.Snapshot) *helper.ReportReport 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() *WilliamsRStrategyNewWilliamsRStrategy function initializes a new Williams R strategy instance with the default parameters.
func NewWilliamsRStrategyWith(buyAt, sellAt float64) *WilliamsRStrategyNewWilliamsRStrategyWith 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.ActionCompute processes the provided asset snapshots and generates a stream of actionable recommendations.
func (*WilliamsRStrategy) Name
func (r *WilliamsRStrategy) Name() stringName returns the name of the strategy.
func (*WilliamsRStrategy) Report
func (r *WilliamsRStrategy) Report(c <-chan *asset.Snapshot) *helper.ReportReport processes the provided asset snapshots and generates a report annotated with the recommended actions.
Generated by gomarkdoc