Skip to content

Latest commit

 

History

History
798 lines (561 loc) · 34.5 KB

File metadata and controls

798 lines (561 loc) · 34.5 KB

momentum

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.

License

Copyright (c) 2021-2026 The Indicator Authors.
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 and educational purposes and is not to be construed as investment, financial, or trading advice.

Index

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.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() []strategy.Strategy

AllStrategies 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() *AwesomeOscillatorStrategy

NewAwesomeOscillatorStrategy initializes an example AwesomeOscillatorStrategy instance with 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 an illustrative stream of actions.

func (*AwesomeOscillatorStrategy) Name

func (*AwesomeOscillatorStrategy) Name() string

Name returns the name of the example strategy.

func (*AwesomeOscillatorStrategy) Report

func (a *AwesomeOscillatorStrategy) Report(c <-chan *asset.Snapshot) *helper.Report

Report processes the provided asset snapshots and generates an illustrative report annotated with example actions.

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() *CoppockCurveStrategy

NewCoppockCurveStrategy initializes an example CoppockCurveStrategy instance with default parameters.

func (*CoppockCurveStrategy) Compute

func (c *CoppockCurveStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action

Compute 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.Action

ComputeWithContext processes the provided asset snapshots and generates an illustrative stream of actions.

func (*CoppockCurveStrategy) Name

func (*CoppockCurveStrategy) Name() string

Name returns the name of the example strategy.

func (*CoppockCurveStrategy) Report

func (c *CoppockCurveStrategy) Report(cr <-chan *asset.Snapshot) *helper.Report

Report processes the provided asset snapshots and generates an illustrative report annotated with example actions.

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() *ElderRayStrategy

NewElderRayStrategy initializes an example ElderRayStrategy instance with 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 an illustrative stream of actions.

func (*ElderRayStrategy) Name

func (*ElderRayStrategy) Name() string

Name returns the name of the example strategy.

func (*ElderRayStrategy) Report

func (e *ElderRayStrategy) Report(c <-chan *asset.Snapshot) *helper.Report

Report 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() *IchimokuCloudStrategy

NewIchimokuCloudStrategy initializes an example IchimokuCloudStrategy instance with 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 an illustrative stream of actions.

func (*IchimokuCloudStrategy) Name

func (*IchimokuCloudStrategy) Name() string

Name returns the name of the example strategy.

func (*IchimokuCloudStrategy) Report

func (i *IchimokuCloudStrategy) Report(c <-chan *asset.Snapshot) *helper.Report

Report processes the provided asset snapshots and generates an illustrative report annotated with example actions.

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() *RsiStrategy

NewRsiStrategy initializes an example RsiStrategy instance with default parameters.

func NewRsiStrategyWith(buyAt, sellAt float64) *RsiStrategy

NewRsiStrategyWith initializes an example RsiStrategyWith instance with default 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 an illustrative stream of actions.

func (*RsiStrategy) Name

func (r *RsiStrategy) Name() string

Name returns the name of the example strategy.

func (*RsiStrategy) Report

func (r *RsiStrategy) Report(c <-chan *asset.Snapshot) *helper.Report

Report 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() *StochasticOscillatorStrategy

NewStochasticOscillatorStrategy initializes an example StochasticOscillatorStrategy instance with default parameters. the default parameters.

func NewStochasticOscillatorStrategyWith(buyAt, sellAt float64) *StochasticOscillatorStrategy

NewStochasticOscillatorStrategyWith initializes an example StochasticOscillatorStrategyWith instance with default parameters. 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 an illustrative stream of actions.

func (*StochasticOscillatorStrategy) Name

func (s *StochasticOscillatorStrategy) Name() string

Name returns the name of the example strategy.

func (*StochasticOscillatorStrategy) Report

func (s *StochasticOscillatorStrategy) Report(c <-chan *asset.Snapshot) *helper.Report

Report 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() *StochasticRsiStrategy

NewStochasticRsiStrategy initializes an example StochasticRsiStrategy instance with default parameters.

func NewStochasticRsiStrategyWith(buyAt, sellAt float64) *StochasticRsiStrategy

NewStochasticRsiStrategyWith initializes an example StochasticRsiStrategyWith instance with default 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 an illustrative stream of actions.

func (*StochasticRsiStrategy) Name

func (s *StochasticRsiStrategy) Name() string

Name returns the name of the example strategy.

func (*StochasticRsiStrategy) Report

func (s *StochasticRsiStrategy) Report(c <-chan *asset.Snapshot) *helper.Report

Report processes the provided asset snapshots and generates an illustrative report annotated with example actions.

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() *TripleRsiStrategy

NewTripleRsiStrategy initializes an example TripleRsiStrategy instance with default parameters.

func NewTripleRsiStrategyWith(period, smaPeriod, downDays int, buySignalAt, buyAt, sellAt float64) *TripleRsiStrategy

NewTripleRsiStrategyWith initializes an example TripleRsiStrategyWith instance with default 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 an illustrative stream of actions.

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 example strategy.

func (*TripleRsiStrategy) Report

func (t *TripleRsiStrategy) Report(c <-chan *asset.Snapshot) *helper.Report

Report processes the provided asset snapshots and generates an illustrative report annotated with example actions.

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() *WilliamsRStrategy

NewWilliamsRStrategy initializes an example WilliamsRStrategy instance with default parameters.

func NewWilliamsRStrategyWith(buyAt, sellAt float64) *WilliamsRStrategy

NewWilliamsRStrategyWith initializes an example WilliamsRStrategyWith instance with default 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 an illustrative stream of actions.

func (*WilliamsRStrategy) Name

func (r *WilliamsRStrategy) Name() string

Name returns the name of the example strategy.

func (*WilliamsRStrategy) Report

func (r *WilliamsRStrategy) Report(c <-chan *asset.Snapshot) *helper.Report

Report processes the provided asset snapshots and generates an illustrative report annotated with example actions.

Generated by gomarkdoc