import "github.com/cinar/indicator/v2/examples/trend"Package trend provides illustrative examples demonstrating how to compose trend 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 AlligatorStrategy
- func NewAlligatorStrategy() *AlligatorStrategy
- func NewAlligatorStrategyWith(jawPeriod, teethPeriod, lipPeriod int) *AlligatorStrategy
- func (a *AlligatorStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (a *AlligatorStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (a *AlligatorStrategy) Name() string
- func (a *AlligatorStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
- type ApoStrategy
- func NewApoStrategy() *ApoStrategy
- func (a *ApoStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (a *ApoStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (*ApoStrategy) Name() string
- func (a *ApoStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
- type AroonStrategy
- func NewAroonStrategy() *AroonStrategy
- func (a *AroonStrategy) Compute(c <-chan *asset.Snapshot) <-chan strategy.Action
- func (a *AroonStrategy) ComputeWithContext(ctx context.Context, c <-chan *asset.Snapshot) <-chan strategy.Action
- func (*AroonStrategy) Name() string
- func (a *AroonStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
- type BopStrategy
- func NewBopStrategy() *BopStrategy
- func (b *BopStrategy) Compute(c <-chan *asset.Snapshot) <-chan strategy.Action
- func (b *BopStrategy) ComputeWithContext(ctx context.Context, c <-chan *asset.Snapshot) <-chan strategy.Action
- func (*BopStrategy) Name() string
- func (b *BopStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
- type CciStrategy
- func NewCciStrategy() *CciStrategy
- func (t *CciStrategy) Compute(c <-chan *asset.Snapshot) <-chan strategy.Action
- func (t *CciStrategy) ComputeWithContext(ctx context.Context, c <-chan *asset.Snapshot) <-chan strategy.Action
- func (*CciStrategy) Name() string
- func (t *CciStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
- type CfoStrategy
- func NewCfoStrategy() *CfoStrategy
- func (c *CfoStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (c *CfoStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (*CfoStrategy) Name() string
- func (c *CfoStrategy) Report(snapshots <-chan *asset.Snapshot) *helper.Report
- type DemaStrategy
- func NewDemaStrategy() *DemaStrategy
- func (d *DemaStrategy) Compute(c <-chan *asset.Snapshot) <-chan strategy.Action
- func (d *DemaStrategy) ComputeWithContext(ctx context.Context, c <-chan *asset.Snapshot) <-chan strategy.Action
- func (*DemaStrategy) Name() string
- func (d *DemaStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
- type EnvelopeStrategy
- func NewEnvelopeStrategy() *EnvelopeStrategy
- func NewEnvelopeStrategyWith(envelope *trend.Envelope[float64]) *EnvelopeStrategy
- func (e *EnvelopeStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (e *EnvelopeStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (e *EnvelopeStrategy) Name() string
- func (e *EnvelopeStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
- type GoldenCrossStrategy
- func NewGoldenCrossStrategy() *GoldenCrossStrategy
- func NewGoldenCrossStrategyWith(fastPeriod, slowPeriod int) *GoldenCrossStrategy
- func (t *GoldenCrossStrategy) Compute(c <-chan *asset.Snapshot) <-chan strategy.Action
- func (t *GoldenCrossStrategy) ComputeWithContext(ctx context.Context, c <-chan *asset.Snapshot) <-chan strategy.Action
- func (*GoldenCrossStrategy) Name() string
- func (t *GoldenCrossStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
- type HmaStrategy
- func NewHmaStrategy() *HmaStrategy
- func NewHmaStrategyWith(period int) *HmaStrategy
- func (h *HmaStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (h *HmaStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (h *HmaStrategy) Name() string
- func (h *HmaStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
- type KamaStrategy
- func NewKamaStrategy() *KamaStrategy
- func NewKamaStrategyWith(erPeriod, fastScPeriod, slowScPeriod int) *KamaStrategy
- func (k *KamaStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (k *KamaStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (k *KamaStrategy) Name() string
- func (k *KamaStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
- type KdjStrategy
- func NewKdjStrategy() *KdjStrategy
- func (kdj *KdjStrategy) Compute(c <-chan *asset.Snapshot) <-chan strategy.Action
- func (kdj *KdjStrategy) ComputeWithContext(ctx context.Context, c <-chan *asset.Snapshot) <-chan strategy.Action
- func (*KdjStrategy) Name() string
- func (kdj *KdjStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
- type MacdSignalMode
- type MacdStrategy
- func NewMacdStrategy() *MacdStrategy
- func NewMacdStrategyWith(period1, period2, period3 int) *MacdStrategy
- func (m *MacdStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (m *MacdStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (m *MacdStrategy) Name() string
- func (m *MacdStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
- type QstickStrategy
- func NewQstickStrategy() *QstickStrategy
- func (q *QstickStrategy) Compute(c <-chan *asset.Snapshot) <-chan strategy.Action
- func (q *QstickStrategy) ComputeWithContext(ctx context.Context, c <-chan *asset.Snapshot) <-chan strategy.Action
- func (*QstickStrategy) Name() string
- func (q *QstickStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
- type SmmaStrategy
- func NewSmmaStrategy() *SmmaStrategy
- func NewSmmaStrategyWith(shortPeriod, longPeriod int) *SmmaStrategy
- func (s *SmmaStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (s *SmmaStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (s *SmmaStrategy) Name() string
- func (s *SmmaStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
- type TrimaStrategy
- func NewTrimaStrategy() *TrimaStrategy
- func (t *TrimaStrategy) Compute(c <-chan *asset.Snapshot) <-chan strategy.Action
- func (t *TrimaStrategy) ComputeWithContext(ctx context.Context, c <-chan *asset.Snapshot) <-chan strategy.Action
- func (*TrimaStrategy) Name() string
- func (t *TrimaStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
- type TripleMovingAverageCrossoverStrategy
- func NewTripleMovingAverageCrossoverStrategy() *TripleMovingAverageCrossoverStrategy
- func NewTripleMovingAverageCrossoverStrategyWith(fastPeriod, mediumPeriod, slowPeriod int) *TripleMovingAverageCrossoverStrategy
- func (t *TripleMovingAverageCrossoverStrategy) Compute(c <-chan *asset.Snapshot) <-chan strategy.Action
- func (t *TripleMovingAverageCrossoverStrategy) ComputeWithContext(ctx context.Context, c <-chan *asset.Snapshot) <-chan strategy.Action
- func (*TripleMovingAverageCrossoverStrategy) Name() string
- func (t *TripleMovingAverageCrossoverStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
- type TrixStrategy
- func NewTrixStrategy() *TrixStrategy
- func (t *TrixStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (t *TrixStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (*TrixStrategy) Name() string
- func (t *TrixStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
- type TsiStrategy
- func NewTsiStrategy() *TsiStrategy
- func NewTsiStrategyWith(firstSmoothingPeriod, secondSmoothingPeriod, signalPeriod int) *TsiStrategy
- func (t *TsiStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (t *TsiStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (t *TsiStrategy) IdlePeriod() int
- func (t *TsiStrategy) Name() string
- func (t *TsiStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
- type VwmaStrategy
- func NewVwmaStrategy() *VwmaStrategy
- func (v *VwmaStrategy) Compute(c <-chan *asset.Snapshot) <-chan strategy.Action
- func (v *VwmaStrategy) ComputeWithContext(ctx context.Context, c <-chan *asset.Snapshot) <-chan strategy.Action
- func (*VwmaStrategy) Name() string
- func (v *VwmaStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
- type WeightedCloseStrategy
- func NewWeightedCloseStrategy() *WeightedCloseStrategy
- func NewWeightedCloseStrategyWith(maPeriod int) *WeightedCloseStrategy
- func (w *WeightedCloseStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (w *WeightedCloseStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (w *WeightedCloseStrategy) Name() string
- func (w *WeightedCloseStrategy) Report(snapshots <-chan *asset.Snapshot) *helper.Report
const (
// DefaultAlligatorStrategyJawPeriod is the default jaw period of 13.
DefaultAlligatorStrategyJawPeriod = 13
// DefaultAlligatorStrategyTeethPeriod is the default teeth period of 8.
DefaultAlligatorStrategyTeethPeriod = 8
// DefaultAlligatorStrategyLipPeriod is the default lip period of 5.
DefaultAlligatorStrategyLipPeriod = 5
)const (
// DefaultDemaStrategyPeriod1 is the first DEMA period.
DefaultDemaStrategyPeriod1 = 5
// DefaultDemaStrategyPeriod2 is the second DEMA period.
DefaultDemaStrategyPeriod2 = 35
)const (
// DefaultGoldenCrossStrategyFastPeriod is the default golden cross strategy fast period.
DefaultGoldenCrossStrategyFastPeriod = 50
// DefaultGoldenCrossStrategySlowPeriod is the default golden cross strategy slow period.
DefaultGoldenCrossStrategySlowPeriod = 200
)const (
// DefaultSmmaStrategyShortPeriod is the default short-term SMMA period of 20.
DefaultSmmaStrategyShortPeriod = 20
// DefaultSmmaStrategyLongPeriod is the default short-term SMMA period of 50.
DefaultSmmaStrategyLongPeriod = 50
)const (
// DefaultTrimaStrategyShortPeriod is the first TRIMA period.
DefaultTrimaStrategyShortPeriod = 20
// DefaultTrimaStrategyLongPeriod is the second TRIMA period.
DefaultTrimaStrategyLongPeriod = 50
)const (
// DefaultTripleMovingAverageCrossoverStrategyFastPeriod is the default triple moving average crossover strategy fast period.
DefaultTripleMovingAverageCrossoverStrategyFastPeriod = 21
// DefaultTripleMovingAverageCrossoverStrategyMediumPeriod is the default triple moving average crossover strategy medium period.
DefaultTripleMovingAverageCrossoverStrategyMediumPeriod = 50
// DefaultTripleMovingAverageCrossoverStrategySlowPeriod is the default triple moving average crossover strategy slow period.
DefaultTripleMovingAverageCrossoverStrategySlowPeriod = 200
)const (
// DefaultHmaStrategyPeriod is the default period for the HMA strategy.
DefaultHmaStrategyPeriod = 9
)const (
// DefaultTsiStrategySignalPeriod is the default signal line period of 12.
DefaultTsiStrategySignalPeriod = 12
)const (
// DefaultVwmaStrategyPeriod is the default VWMA period.
DefaultVwmaStrategyPeriod = 20
)const (
// DefaultWeightedCloseStrategyMaPeriod is the default Moving Average period of 20.
DefaultWeightedCloseStrategyMaPeriod = 20
)func AllStrategies
func AllStrategies() []strategy.StrategyAllStrategies returns a slice containing references to all available example trend strategies.
type AlligatorStrategy
AlligatorStrategy demonstrates how to compose three Smoothed Moving Averages (SMMAs) (jaw, teeth, lip) into an illustrative multi-moving-average trend-following strategy.
type AlligatorStrategy struct {
// Jaw represents the slowest moving aveage.
Jaw *trend.Smma[float64]
// Teeth represents the medium moving average.
Teeth *trend.Smma[float64]
// Lip represents the fastest moving average.
Lip *trend.Smma[float64]
}func NewAlligatorStrategy
func NewAlligatorStrategy() *AlligatorStrategyNewAlligatorStrategy initializes an example AlligatorStrategy instance with default parameters.
func NewAlligatorStrategyWith(jawPeriod, teethPeriod, lipPeriod int) *AlligatorStrategyNewAlligatorStrategyWith initializes an example AlligatorStrategyWith instance with default parameters.
func (*AlligatorStrategy) Compute
func (a *AlligatorStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.ActionCompute wraps ComputeWithContext for backwards compatibility.
Deprecated: Use ComputeWithContext instead.
func (*AlligatorStrategy) ComputeWithContext
func (a *AlligatorStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.ActionComputeWithContext processes the provided asset snapshots and generates an illustrative stream of actions.
func (*AlligatorStrategy) Name
func (a *AlligatorStrategy) Name() stringName returns the name of the example strategy.
func (*AlligatorStrategy) Report
func (a *AlligatorStrategy) Report(c <-chan *asset.Snapshot) *helper.ReportReport processes the provided asset snapshots and generates an illustrative report annotated with example actions.
type ApoStrategy
ApoStrategy demonstrates how to compose the Absolute Price Oscillator (APO) indicator into an illustrative centerline crossover strategy.
type ApoStrategy struct {
// Apo represents the configuration parameters for calculating the
// Absolute Price Oscillator (APO).
Apo *trend.Apo[float64]
}func NewApoStrategy
func NewApoStrategy() *ApoStrategyNewApoStrategy initializes an example ApoStrategy instance with default parameters.
func (*ApoStrategy) Compute
func (a *ApoStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.ActionCompute wraps ComputeWithContext for backwards compatibility.
Deprecated: Use ComputeWithContext instead.
func (*ApoStrategy) ComputeWithContext
func (a *ApoStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.ActionComputeWithContext processes the provided asset snapshots and generates an illustrative stream of actions.
func (*ApoStrategy) Name
func (*ApoStrategy) Name() stringName returns the name of the example strategy.
func (*ApoStrategy) Report
func (a *ApoStrategy) Report(c <-chan *asset.Snapshot) *helper.ReportReport processes the provided asset snapshots and generates an illustrative report annotated with example actions.
type AroonStrategy
AroonStrategy demonstrates how to compose Aroon Up and Aroon Down indicator lines into an illustrative trend crossover strategy.
type AroonStrategy struct {
// Aroon represent the configuration for calculating the Aroon indicator.
Aroon *trend.Aroon[float64]
}func NewAroonStrategy
func NewAroonStrategy() *AroonStrategyNewAroonStrategy initializes an example AroonStrategy instance with default parameters. with the default parameters.
func (*AroonStrategy) Compute
func (a *AroonStrategy) Compute(c <-chan *asset.Snapshot) <-chan strategy.ActionCompute wraps ComputeWithContext for backwards compatibility.
Deprecated: Use ComputeWithContext instead.
func (*AroonStrategy) ComputeWithContext
func (a *AroonStrategy) ComputeWithContext(ctx context.Context, c <-chan *asset.Snapshot) <-chan strategy.ActionComputeWithContext processes the provided asset snapshots and generates an illustrative stream of actions.
func (*AroonStrategy) Name
func (*AroonStrategy) Name() stringName returns the name of the example strategy.
func (*AroonStrategy) Report
func (a *AroonStrategy) Report(c <-chan *asset.Snapshot) *helper.ReportReport processes the provided asset snapshots and generates an illustrative report annotated with example actions.
type BopStrategy
BopStrategy demonstrates how to compose the Balance of Power (BoP) indicator into an illustrative zero-line crossover strategy.
type BopStrategy struct {
// Bop represents the configuration parameters for calculating the
// Balance of Power (BoP).
Bop *trend.Bop[float64]
}func NewBopStrategy
func NewBopStrategy() *BopStrategyNewBopStrategy initializes an example BopStrategy instance with default parameters.
func (*BopStrategy) Compute
func (b *BopStrategy) Compute(c <-chan *asset.Snapshot) <-chan strategy.ActionCompute wraps ComputeWithContext for backwards compatibility.
Deprecated: Use ComputeWithContext instead.
func (*BopStrategy) ComputeWithContext
func (b *BopStrategy) ComputeWithContext(ctx context.Context, c <-chan *asset.Snapshot) <-chan strategy.ActionComputeWithContext processes the provided asset snapshots and generates an illustrative stream of actions.
func (*BopStrategy) Name
func (*BopStrategy) Name() stringName returns the name of the example strategy.
func (*BopStrategy) Report
func (b *BopStrategy) Report(c <-chan *asset.Snapshot) *helper.ReportReport processes the provided asset snapshots and generates an illustrative report annotated with example actions.
type CciStrategy
CciStrategy demonstrates how to compose the Commodity Channel Index (CCI) indicator into an illustrative threshold-based strategy.
type CciStrategy struct {
// Cci represents the configuration parameters for calculating the CCI.
Cci *trend.Cci[float64]
}func NewCciStrategy
func NewCciStrategy() *CciStrategyNewCciStrategy initializes an example CciStrategy instance with default parameters.
func (*CciStrategy) Compute
func (t *CciStrategy) Compute(c <-chan *asset.Snapshot) <-chan strategy.ActionCompute wraps ComputeWithContext for backwards compatibility.
Deprecated: Use ComputeWithContext instead.
func (*CciStrategy) ComputeWithContext
func (t *CciStrategy) ComputeWithContext(ctx context.Context, c <-chan *asset.Snapshot) <-chan strategy.ActionComputeWithContext processes the provided asset snapshots and generates an illustrative stream of actions.
func (*CciStrategy) Name
func (*CciStrategy) Name() stringName returns the name of the example strategy.
func (*CciStrategy) Report
func (t *CciStrategy) Report(c <-chan *asset.Snapshot) *helper.ReportReport processes the provided asset snapshots and generates an illustrative report annotated with example actions.
type CfoStrategy
CfoStrategy demonstrates how to compose the Chande Forecast Oscillator (CFO) indicator into an illustrative zero-line crossover strategy.
type CfoStrategy struct {
// Cfo represents the configuration parameters for calculating the
// Chande Forecast Oscillator (CFO).
Cfo *trend.Cfo[float64]
}func NewCfoStrategy
func NewCfoStrategy() *CfoStrategyNewCfoStrategy initializes an example CfoStrategy instance with default parameters.
func (*CfoStrategy) Compute
func (c *CfoStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.ActionCompute wraps ComputeWithContext for backwards compatibility.
Deprecated: Use ComputeWithContext instead.
func (*CfoStrategy) ComputeWithContext
func (c *CfoStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.ActionComputeWithContext processes the provided asset snapshots and generates an illustrative stream of actions.
func (*CfoStrategy) Name
func (*CfoStrategy) Name() stringName returns the name of the example strategy.
func (*CfoStrategy) Report
func (c *CfoStrategy) Report(snapshots <-chan *asset.Snapshot) *helper.ReportReport processes the provided asset snapshots and generates an illustrative report annotated with example actions.
type DemaStrategy
DemaStrategy demonstrates how to compose Double Exponential Moving Averages (DEMAs) with fast and slow periods into an illustrative moving average crossover strategy.
type DemaStrategy struct {
// Dema1 represents the configuration parameters for
// calculating the first DEMA.
Dema1 *trend.Dema[float64]
// Dema2 represents the configuration parameters for
// calculating the second DEMA.
Dema2 *trend.Dema[float64]
}func NewDemaStrategy
func NewDemaStrategy() *DemaStrategyNewDemaStrategy initializes an example DemaStrategy instance with default parameters. with the default parameters.
func (*DemaStrategy) Compute
func (d *DemaStrategy) Compute(c <-chan *asset.Snapshot) <-chan strategy.ActionCompute wraps ComputeWithContext for backwards compatibility.
Deprecated: Use ComputeWithContext instead.
func (*DemaStrategy) ComputeWithContext
func (d *DemaStrategy) ComputeWithContext(ctx context.Context, c <-chan *asset.Snapshot) <-chan strategy.ActionComputeWithContext processes the provided asset snapshots and generates an illustrative stream of actions.
func (*DemaStrategy) Name
func (*DemaStrategy) Name() stringName returns the name of the example strategy.
func (*DemaStrategy) Report
func (d *DemaStrategy) Report(c <-chan *asset.Snapshot) *helper.ReportReport processes the provided asset snapshots and generates an illustrative report annotated with example actions.
type EnvelopeStrategy
EnvelopeStrategy demonstrates how to compose moving average envelope bands into an illustrative band breakout strategy.
type EnvelopeStrategy struct {
// Envelope is the envelope indicator instance.
Envelope *trend.Envelope[float64]
}func NewEnvelopeStrategy
func NewEnvelopeStrategy() *EnvelopeStrategyNewEnvelopeStrategy initializes an example EnvelopeStrategy instance with default parameters.
func NewEnvelopeStrategyWith(envelope *trend.Envelope[float64]) *EnvelopeStrategyNewEnvelopeStrategyWith initializes an example EnvelopeStrategyWith instance with default parameters.
func (*EnvelopeStrategy) Compute
func (e *EnvelopeStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.ActionCompute wraps ComputeWithContext for backwards compatibility.
Deprecated: Use ComputeWithContext instead.
func (*EnvelopeStrategy) ComputeWithContext
func (e *EnvelopeStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.ActionComputeWithContext processes the provided asset snapshots and generates an illustrative stream of actions.
func (*EnvelopeStrategy) Name
func (e *EnvelopeStrategy) Name() stringName returns the name of the example strategy.
func (*EnvelopeStrategy) Report
func (e *EnvelopeStrategy) Report(c <-chan *asset.Snapshot) *helper.ReportReport processes the provided asset snapshots and generates an illustrative report annotated with example actions.
type GoldenCrossStrategy
GoldenCrossStrategy demonstrates how to compose fast and slow Exponential Moving Averages (EMAs) into an illustrative golden cross / death cross crossover strategy.
type GoldenCrossStrategy struct {
// FastEma is the fastest EMA.
FastEma *trend.Ema[float64]
// SlowEma is the slowest EMA.
SlowEma *trend.Ema[float64]
}func NewGoldenCrossStrategy() *GoldenCrossStrategyNewGoldenCrossStrategy initializes an example GoldenCrossStrategy instance with default parameters.
func NewGoldenCrossStrategyWith(fastPeriod, slowPeriod int) *GoldenCrossStrategyNewGoldenCrossStrategyWith initializes an example GoldenCrossStrategyWith instance with default parameters.
func (*GoldenCrossStrategy) Compute
func (t *GoldenCrossStrategy) Compute(c <-chan *asset.Snapshot) <-chan strategy.ActionCompute wraps ComputeWithContext for backwards compatibility.
Deprecated: Use ComputeWithContext instead.
func (*GoldenCrossStrategy) ComputeWithContext
func (t *GoldenCrossStrategy) ComputeWithContext(ctx context.Context, c <-chan *asset.Snapshot) <-chan strategy.ActionComputeWithContext processes the provided asset snapshots and generates an illustrative stream of actions.
func (*GoldenCrossStrategy) Name
func (*GoldenCrossStrategy) Name() stringName returns the name of the example strategy.
func (*GoldenCrossStrategy) Report
func (t *GoldenCrossStrategy) Report(c <-chan *asset.Snapshot) *helper.ReportReport processes the provided asset snapshots and generates an illustrative report annotated with example actions.
type HmaStrategy
HmaStrategy demonstrates how to compose Hull Moving Averages (HMAs) with fast and slow periods into an illustrative moving average crossover strategy.
type HmaStrategy struct {
// Hma represents the configuration parameters for calculating the Hull Moving Average.
Hma *trend.Hma[float64]
}func NewHmaStrategy
func NewHmaStrategy() *HmaStrategyNewHmaStrategy initializes an example HmaStrategy instance with default parameters.
func NewHmaStrategyWith
func NewHmaStrategyWith(period int) *HmaStrategyNewHmaStrategyWith initializes an example HmaStrategyWith instance with default parameters.
func (*HmaStrategy) Compute
func (h *HmaStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.ActionCompute wraps ComputeWithContext for backwards compatibility.
Deprecated: Use ComputeWithContext instead.
func (*HmaStrategy) ComputeWithContext
func (h *HmaStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.ActionComputeWithContext processes the provided asset snapshots and generates an illustrative stream of actions.
func (*HmaStrategy) Name
func (h *HmaStrategy) Name() stringName returns the name of the example strategy.
func (*HmaStrategy) Report
func (h *HmaStrategy) Report(c <-chan *asset.Snapshot) *helper.ReportReport processes the provided asset snapshots and generates an illustrative report annotated with example actions.
type KamaStrategy
KamaStrategy demonstrates how to compose Kaufman's Adaptive Moving Averages (KAMAs) with fast and slow periods into an illustrative adaptive moving average crossover strategy.
type KamaStrategy struct {
// Kama represents the configuration parameters for calculating the Kaufman's Adaptive Moving Average (KAMA).
Kama *trend.Kama[float64]
}func NewKamaStrategy
func NewKamaStrategy() *KamaStrategyNewKamaStrategy initializes an example KamaStrategy instance with default parameters.
func NewKamaStrategyWith
func NewKamaStrategyWith(erPeriod, fastScPeriod, slowScPeriod int) *KamaStrategyNewKamaStrategyWith initializes an example KamaStrategyWith instance with default parameters.
func (*KamaStrategy) Compute
func (k *KamaStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.ActionCompute wraps ComputeWithContext for backwards compatibility.
Deprecated: Use ComputeWithContext instead.
func (*KamaStrategy) ComputeWithContext
func (k *KamaStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.ActionComputeWithContext processes the provided asset snapshots and generates an illustrative stream of actions.
func (*KamaStrategy) Name
func (k *KamaStrategy) Name() stringName returns the name of the example strategy.
func (*KamaStrategy) Report
func (k *KamaStrategy) Report(c <-chan *asset.Snapshot) *helper.ReportReport processes the provided asset snapshots and generates an illustrative report annotated with example actions.
type KdjStrategy
KdjStrategy demonstrates how to compose Random Index (KDJ) indicator lines into an illustrative crossover strategy.
type KdjStrategy struct {
// Kdj represents the configuration parameters for calculating the KDJ.
Kdj *trend.Kdj[float64]
}func NewKdjStrategy
func NewKdjStrategy() *KdjStrategyNewKdjStrategy initializes an example KdjStrategy instance with default parameters.
func (*KdjStrategy) Compute
func (kdj *KdjStrategy) Compute(c <-chan *asset.Snapshot) <-chan strategy.ActionCompute wraps ComputeWithContext for backwards compatibility.
Deprecated: Use ComputeWithContext instead.
func (*KdjStrategy) ComputeWithContext
func (kdj *KdjStrategy) ComputeWithContext(ctx context.Context, c <-chan *asset.Snapshot) <-chan strategy.ActionComputeWithContext processes the provided asset snapshots and generates an illustrative stream of actions.
func (*KdjStrategy) Name
func (*KdjStrategy) Name() stringName returns the name of the example strategy.
func (*KdjStrategy) Report
func (kdj *KdjStrategy) Report(c <-chan *asset.Snapshot) *helper.ReportReport processes the provided asset snapshots and generates an illustrative report annotated with example actions.
type MacdSignalMode
MacdSignalMode selects how MacdStrategy turns a MACD/signal-line crossover into an action.
type MacdSignalMode intconst (
// LevelTriggered evaluates the crossover condition independently on every bar, so it keeps
// returning Buy (or Sell) on every consecutive bar for which the condition holds, not just
// the bar on which the crossing actually happened. This is the existing default behavior.
LevelTriggered MacdSignalMode = iota
// EdgeTriggered fires Buy/Sell only once, on the bar where the MACD/signal-line crossing
// actually occurs, by comparing the previous bar's MACD/signal pair against the current
// one. This requires one additional bar of history, so the strategy's idle period is one
// bar longer than in LevelTriggered mode.
EdgeTriggered
)type MacdStrategy
MacdStrategy demonstrates how to compose the Moving Average Convergence Divergence (MACD) and its signal line into an illustrative, zero-line-filtered MACD crossover strategy. Buy signals fire only on a MACD-above-signal crossing that occurs while MACD is still below zero; Sell signals fire only on a MACD-below-signal crossing while MACD is still above zero.
type MacdStrategy struct {
// Macd represents the configuration parameters for calculating the
// Moving Average Convergence Divergence (MACD).
Macd *trend.Macd[float64]
// SignalMode selects between LevelTriggered (default) and EdgeTriggered crossover
// detection. See MacdSignalMode for details.
SignalMode MacdSignalMode
}func NewMacdStrategy
func NewMacdStrategy() *MacdStrategyNewMacdStrategy initializes an example MacdStrategy instance with default parameters.
func NewMacdStrategyWith
func NewMacdStrategyWith(period1, period2, period3 int) *MacdStrategyNewMacdStrategyWith initializes an example MacdStrategyWith instance with default parameters.
func (*MacdStrategy) Compute
func (m *MacdStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.ActionCompute wraps ComputeWithContext for backwards compatibility.
Deprecated: Use ComputeWithContext instead.
func (*MacdStrategy) ComputeWithContext
func (m *MacdStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.ActionComputeWithContext processes the provided asset snapshots and generates an illustrative stream of actions.
func (*MacdStrategy) Name
func (m *MacdStrategy) Name() stringName returns the name of the example strategy.
func (*MacdStrategy) Report
func (m *MacdStrategy) Report(c <-chan *asset.Snapshot) *helper.ReportReport processes the provided asset snapshots and generates an illustrative report annotated with example actions.
type QstickStrategy
QstickStrategy demonstrates how to compose the Qstick momentum indicator into an illustrative zero-line crossover strategy.
type QstickStrategy struct {
// Qstick represents the configuration parameters for calculating the Qstick.
Qstick *momentum.Qstick[float64]
}func NewQstickStrategy
func NewQstickStrategy() *QstickStrategyNewQstickStrategy initializes an example QstickStrategy instance with default parameters.
func (*QstickStrategy) Compute
func (q *QstickStrategy) Compute(c <-chan *asset.Snapshot) <-chan strategy.ActionCompute wraps ComputeWithContext for backwards compatibility.
Deprecated: Use ComputeWithContext instead.
func (*QstickStrategy) ComputeWithContext
func (q *QstickStrategy) ComputeWithContext(ctx context.Context, c <-chan *asset.Snapshot) <-chan strategy.ActionComputeWithContext processes the provided asset snapshots and generates an illustrative stream of actions.
func (*QstickStrategy) Name
func (*QstickStrategy) Name() stringName returns the name of the example strategy.
func (*QstickStrategy) Report
func (q *QstickStrategy) Report(c <-chan *asset.Snapshot) *helper.ReportReport processes the provided asset snapshots and generates an illustrative report annotated with example actions.
type SmmaStrategy
SmmaStrategy demonstrates how to compose Smoothed Moving Averages (SMMAs) with fast and slow periods into an illustrative moving average crossover strategy.
type SmmaStrategy struct {
// ShortSmma represents the configuration parameters for calculating the
// short-term Smooted Moving Averge (SMMA).
ShortSmma *trend.Smma[float64]
// LongSmma represents the configuration parameters for calculating the
// long-term Smooted Moving Averge (SMMA).
LongSmma *trend.Smma[float64]
}func NewSmmaStrategy
func NewSmmaStrategy() *SmmaStrategyNewSmmaStrategy initializes an example SmmaStrategy instance with default parameters.
func NewSmmaStrategyWith
func NewSmmaStrategyWith(shortPeriod, longPeriod int) *SmmaStrategyNewSmmaStrategyWith initializes an example SmmaStrategyWith instance with default parameters.
func (*SmmaStrategy) Compute
func (s *SmmaStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.ActionCompute wraps ComputeWithContext for backwards compatibility.
Deprecated: Use ComputeWithContext instead.
func (*SmmaStrategy) ComputeWithContext
func (s *SmmaStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.ActionComputeWithContext processes the provided asset snapshots and generates an illustrative stream of actions.
func (*SmmaStrategy) Name
func (s *SmmaStrategy) Name() stringName returns the name of the example strategy.
func (*SmmaStrategy) Report
func (s *SmmaStrategy) Report(c <-chan *asset.Snapshot) *helper.ReportReport processes the provided asset snapshots and generates an illustrative report annotated with example actions.
type TrimaStrategy
TrimaStrategy demonstrates how to compose Triangular Moving Averages (TRIMAs) with fast and slow periods into an illustrative moving average crossover strategy.
type TrimaStrategy struct {
// Trima1 represents the configuration parameters for calculating the short TRIMA.
Short *trend.Trima[float64]
// Trima2 represents the configuration parameters for calculating the long TRIMA.
Long *trend.Trima[float64]
}func NewTrimaStrategy
func NewTrimaStrategy() *TrimaStrategyNewTrimaStrategy initializes an example TrimaStrategy instance with default parameters. with the default parameters.
func (*TrimaStrategy) Compute
func (t *TrimaStrategy) Compute(c <-chan *asset.Snapshot) <-chan strategy.ActionCompute wraps ComputeWithContext for backwards compatibility.
Deprecated: Use ComputeWithContext instead.
func (*TrimaStrategy) ComputeWithContext
func (t *TrimaStrategy) ComputeWithContext(ctx context.Context, c <-chan *asset.Snapshot) <-chan strategy.ActionComputeWithContext processes the provided asset snapshots and generates an illustrative stream of actions.
func (*TrimaStrategy) Name
func (*TrimaStrategy) Name() stringName returns the name of the example strategy.
func (*TrimaStrategy) Report
func (t *TrimaStrategy) Report(c <-chan *asset.Snapshot) *helper.ReportReport processes the provided asset snapshots and generates an illustrative report annotated with example actions.
TripleMovingAverageCrossoverStrategy demonstrates how to compose three Exponential Moving Averages (EMAs) with different periods into an illustrative triple crossover strategy.
type TripleMovingAverageCrossoverStrategy struct {
// FastEma is the fastest EMA.
FastEma *trend.Ema[float64]
// MediumEma is the meium EMA.
MediumEma *trend.Ema[float64]
// SlowEma is the slowest EMA.
SlowEma *trend.Ema[float64]
}func NewTripleMovingAverageCrossoverStrategy() *TripleMovingAverageCrossoverStrategyNewTripleMovingAverageCrossoverStrategy initializes an example TripleMovingAverageCrossoverStrategy instance with default parameters.
func NewTripleMovingAverageCrossoverStrategyWith(fastPeriod, mediumPeriod, slowPeriod int) *TripleMovingAverageCrossoverStrategyNewTripleMovingAverageCrossoverStrategyWith initializes an example TripleMovingAverageCrossoverStrategyWith instance with default parameters.
func (*TripleMovingAverageCrossoverStrategy) Compute
func (t *TripleMovingAverageCrossoverStrategy) Compute(c <-chan *asset.Snapshot) <-chan strategy.ActionCompute wraps ComputeWithContext for backwards compatibility.
Deprecated: Use ComputeWithContext instead.
func (*TripleMovingAverageCrossoverStrategy) ComputeWithContext
func (t *TripleMovingAverageCrossoverStrategy) ComputeWithContext(ctx context.Context, c <-chan *asset.Snapshot) <-chan strategy.ActionComputeWithContext processes the provided asset snapshots and generates an illustrative stream of actions.
func (*TripleMovingAverageCrossoverStrategy) Name
func (*TripleMovingAverageCrossoverStrategy) Name() stringName returns the name of the example strategy.
func (*TripleMovingAverageCrossoverStrategy) Report
func (t *TripleMovingAverageCrossoverStrategy) Report(c <-chan *asset.Snapshot) *helper.ReportReport processes the provided asset snapshots and generates an illustrative report annotated with example actions.
type TrixStrategy
TrixStrategy demonstrates how to compose the Triple Exponential Average (TRIX) indicator into an illustrative zero-line crossover strategy.
type TrixStrategy struct {
// Trix represents the configuration parameters for calculating the TRIX.
Trix *trend.Trix[float64]
}func NewTrixStrategy
func NewTrixStrategy() *TrixStrategyNewTrixStrategy initializes an example TrixStrategy instance with default parameters.
func (*TrixStrategy) Compute
func (t *TrixStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.ActionCompute wraps ComputeWithContext for backwards compatibility.
Deprecated: Use ComputeWithContext instead.
func (*TrixStrategy) ComputeWithContext
func (t *TrixStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.ActionComputeWithContext processes the provided asset snapshots and generates an illustrative stream of actions.
func (*TrixStrategy) Name
func (*TrixStrategy) Name() stringName returns the name of the example strategy.
func (*TrixStrategy) Report
func (t *TrixStrategy) Report(c <-chan *asset.Snapshot) *helper.ReportReport processes the provided asset snapshots and generates an illustrative report annotated with example actions.
type TsiStrategy
TsiStrategy demonstrates how to compose the True Strength Index (TSI) indicator and its signal line into an illustrative crossover strategy.
type TsiStrategy struct {
// Tsi represents the configuration parameters for calculating the True Strength Index (TSI).
Tsi *trend.Tsi[float64]
// Signal line is the moving average of the TSI.
Signal trend.Ma[float64]
}func NewTsiStrategy
func NewTsiStrategy() *TsiStrategyNewTsiStrategy initializes an example TsiStrategy instance with default parameters.
func NewTsiStrategyWith
func NewTsiStrategyWith(firstSmoothingPeriod, secondSmoothingPeriod, signalPeriod int) *TsiStrategyNewTsiStrategyWith initializes an example TsiStrategyWith instance with default parameters.
func (*TsiStrategy) Compute
func (t *TsiStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.ActionCompute wraps ComputeWithContext for backwards compatibility.
Deprecated: Use ComputeWithContext instead.
func (*TsiStrategy) ComputeWithContext
func (t *TsiStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.ActionComputeWithContext processes the provided asset snapshots and generates an illustrative stream of actions.
func (*TsiStrategy) IdlePeriod
func (t *TsiStrategy) IdlePeriod() intIdlePeriod is the initial period that TSI strategy yield any results.
func (*TsiStrategy) Name
func (t *TsiStrategy) Name() stringName returns the name of the example strategy.
func (*TsiStrategy) Report
func (t *TsiStrategy) Report(c <-chan *asset.Snapshot) *helper.ReportReport processes the provided asset snapshots and generates an illustrative report annotated with example actions.
type VwmaStrategy
VwmaStrategy demonstrates how to compose Volume Weighted Moving Average (VWMA) and Simple Moving Average (SMA) into an illustrative moving average crossover strategy.
type VwmaStrategy struct {
// VWMA indicator.
Vwma *trend.Vwma[float64]
// SMA indicator.
Sma *trend.Sma[float64]
}func NewVwmaStrategy
func NewVwmaStrategy() *VwmaStrategyNewVwmaStrategy initializes an example VwmaStrategy instance with default parameters.
func (*VwmaStrategy) Compute
func (v *VwmaStrategy) Compute(c <-chan *asset.Snapshot) <-chan strategy.ActionCompute wraps ComputeWithContext for backwards compatibility.
Deprecated: Use ComputeWithContext instead.
func (*VwmaStrategy) ComputeWithContext
func (v *VwmaStrategy) ComputeWithContext(ctx context.Context, c <-chan *asset.Snapshot) <-chan strategy.ActionComputeWithContext processes the provided asset snapshots and generates an illustrative stream of actions.
func (*VwmaStrategy) Name
func (*VwmaStrategy) Name() stringName returns the name of the example strategy.
func (*VwmaStrategy) Report
func (v *VwmaStrategy) Report(c <-chan *asset.Snapshot) *helper.ReportReport processes the provided asset snapshots and generates an illustrative report annotated with example actions.
WeightedCloseStrategy demonstrates how to compose Weighted Close prices and their moving average into an illustrative crossover strategy.
type WeightedCloseStrategy struct {
// WeightedClose represents the configuration parameters for calculating the weighted close.
WeightedClose *trend.WeightedClose[float64]
// Ma represents the configuration parameters for calculating the moving average.
Ma trend.Ma[float64]
}func NewWeightedCloseStrategy() *WeightedCloseStrategyNewWeightedCloseStrategy initializes an example WeightedCloseStrategy instance with default parameters.
func NewWeightedCloseStrategyWith(maPeriod int) *WeightedCloseStrategyNewWeightedCloseStrategyWith initializes an example WeightedCloseStrategyWith instance with default parameters. with the given parameters.
func (*WeightedCloseStrategy) Compute
func (w *WeightedCloseStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.ActionCompute wraps ComputeWithContext for backwards compatibility.
Deprecated: Use ComputeWithContext instead.
func (*WeightedCloseStrategy) ComputeWithContext
func (w *WeightedCloseStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.ActionComputeWithContext processes the provided asset snapshots and generates an illustrative stream of actions.
func (*WeightedCloseStrategy) Name
func (w *WeightedCloseStrategy) Name() stringName returns the name of the example strategy.
func (*WeightedCloseStrategy) Report
func (w *WeightedCloseStrategy) Report(snapshots <-chan *asset.Snapshot) *helper.ReportReport processes the provided asset snapshots and generates an illustrative report annotated with example actions.
Generated by gomarkdoc