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-2024 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 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
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
)
func AllStrategies
func AllStrategies() []strategy.Strategy
AllStrategies 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() *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 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 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 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.
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() *StochasticRsiStrategy
NewStochasticRsiStrategy function initializes a new Stochastic RSI strategy instance with the default parameters.
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 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(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 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.
Generated by gomarkdoc