Skip to content

Latest commit

 

History

History
1703 lines (1209 loc) · 68.9 KB

File metadata and controls

1703 lines (1209 loc) · 68.9 KB

trend

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.

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

AllStrategies returns a slice containing references to all available example trend strategies.

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

NewAlligatorStrategy initializes an example AlligatorStrategy instance with default parameters.

func NewAlligatorStrategyWith(jawPeriod, teethPeriod, lipPeriod int) *AlligatorStrategy

NewAlligatorStrategyWith initializes an example AlligatorStrategyWith instance with default parameters.

func (*AlligatorStrategy) Compute

func (a *AlligatorStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action

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

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

func (*AlligatorStrategy) Name

func (a *AlligatorStrategy) Name() string

Name returns the name of the example strategy.

func (*AlligatorStrategy) Report

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

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

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

NewApoStrategy initializes an example ApoStrategy instance with default parameters.

func (*ApoStrategy) Compute

func (a *ApoStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action

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

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

func (*ApoStrategy) Name

func (*ApoStrategy) Name() string

Name returns the name of the example strategy.

func (*ApoStrategy) Report

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

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

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

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

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

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

func (*AroonStrategy) Name

func (*AroonStrategy) Name() string

Name returns the name of the example strategy.

func (*AroonStrategy) Report

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

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

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

NewBopStrategy initializes an example BopStrategy instance with default parameters.

func (*BopStrategy) Compute

func (b *BopStrategy) Compute(c <-chan *asset.Snapshot) <-chan strategy.Action

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

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

func (*BopStrategy) Name

func (*BopStrategy) Name() string

Name returns the name of the example strategy.

func (*BopStrategy) Report

func (b *BopStrategy) Report(c <-chan *asset.Snapshot) *helper.Report

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

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

NewCciStrategy initializes an example CciStrategy instance with default parameters.

func (*CciStrategy) Compute

func (t *CciStrategy) Compute(c <-chan *asset.Snapshot) <-chan strategy.Action

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

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

func (*CciStrategy) Name

func (*CciStrategy) Name() string

Name returns the name of the example strategy.

func (*CciStrategy) Report

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

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

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

NewCfoStrategy initializes an example CfoStrategy instance with default parameters.

func (*CfoStrategy) Compute

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

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

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

func (*CfoStrategy) Name

func (*CfoStrategy) Name() string

Name returns the name of the example strategy.

func (*CfoStrategy) Report

func (c *CfoStrategy) Report(snapshots <-chan *asset.Snapshot) *helper.Report

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

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

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

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

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

func (*DemaStrategy) Name

func (*DemaStrategy) Name() string

Name returns the name of the example strategy.

func (*DemaStrategy) Report

func (d *DemaStrategy) Report(c <-chan *asset.Snapshot) *helper.Report

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

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

NewEnvelopeStrategy initializes an example EnvelopeStrategy instance with default parameters.

func NewEnvelopeStrategyWith(envelope *trend.Envelope[float64]) *EnvelopeStrategy

NewEnvelopeStrategyWith initializes an example EnvelopeStrategyWith instance with default parameters.

func (*EnvelopeStrategy) Compute

func (e *EnvelopeStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action

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

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

func (*EnvelopeStrategy) Name

func (e *EnvelopeStrategy) Name() string

Name returns the name of the example strategy.

func (*EnvelopeStrategy) Report

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

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

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

NewGoldenCrossStrategy initializes an example GoldenCrossStrategy instance with default parameters.

func NewGoldenCrossStrategyWith(fastPeriod, slowPeriod int) *GoldenCrossStrategy

NewGoldenCrossStrategyWith initializes an example GoldenCrossStrategyWith instance with default parameters.

func (*GoldenCrossStrategy) Compute

func (t *GoldenCrossStrategy) Compute(c <-chan *asset.Snapshot) <-chan strategy.Action

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

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

func (*GoldenCrossStrategy) Name

func (*GoldenCrossStrategy) Name() string

Name returns the name of the example strategy.

func (*GoldenCrossStrategy) Report

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

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

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

NewHmaStrategy initializes an example HmaStrategy instance with default parameters.

func NewHmaStrategyWith(period int) *HmaStrategy

NewHmaStrategyWith initializes an example HmaStrategyWith instance with default parameters.

func (*HmaStrategy) Compute

func (h *HmaStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action

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

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

func (*HmaStrategy) Name

func (h *HmaStrategy) Name() string

Name returns the name of the example strategy.

func (*HmaStrategy) Report

func (h *HmaStrategy) Report(c <-chan *asset.Snapshot) *helper.Report

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

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

NewKamaStrategy initializes an example KamaStrategy instance with default parameters.

func NewKamaStrategyWith(erPeriod, fastScPeriod, slowScPeriod int) *KamaStrategy

NewKamaStrategyWith initializes an example KamaStrategyWith instance with default parameters.

func (*KamaStrategy) Compute

func (k *KamaStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action

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

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

func (*KamaStrategy) Name

func (k *KamaStrategy) Name() string

Name returns the name of the example strategy.

func (*KamaStrategy) Report

func (k *KamaStrategy) Report(c <-chan *asset.Snapshot) *helper.Report

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

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

NewKdjStrategy initializes an example KdjStrategy instance with default parameters.

func (*KdjStrategy) Compute

func (kdj *KdjStrategy) Compute(c <-chan *asset.Snapshot) <-chan strategy.Action

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

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

func (*KdjStrategy) Name

func (*KdjStrategy) Name() string

Name returns the name of the example strategy.

func (*KdjStrategy) Report

func (kdj *KdjStrategy) Report(c <-chan *asset.Snapshot) *helper.Report

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

MacdSignalMode selects how MacdStrategy turns a MACD/signal-line crossover into an action.

type MacdSignalMode int

const (
    // 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
)

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

NewMacdStrategy initializes an example MacdStrategy instance with default parameters.

func NewMacdStrategyWith(period1, period2, period3 int) *MacdStrategy

NewMacdStrategyWith initializes an example MacdStrategyWith instance with default parameters.

func (*MacdStrategy) Compute

func (m *MacdStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action

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

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

func (*MacdStrategy) Name

func (m *MacdStrategy) Name() string

Name returns the name of the example strategy.

func (*MacdStrategy) Report

func (m *MacdStrategy) Report(c <-chan *asset.Snapshot) *helper.Report

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

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

NewQstickStrategy initializes an example QstickStrategy instance with default parameters.

func (*QstickStrategy) Compute

func (q *QstickStrategy) Compute(c <-chan *asset.Snapshot) <-chan strategy.Action

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

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

func (*QstickStrategy) Name

func (*QstickStrategy) Name() string

Name returns the name of the example strategy.

func (*QstickStrategy) Report

func (q *QstickStrategy) Report(c <-chan *asset.Snapshot) *helper.Report

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

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

NewSmmaStrategy initializes an example SmmaStrategy instance with default parameters.

func NewSmmaStrategyWith(shortPeriod, longPeriod int) *SmmaStrategy

NewSmmaStrategyWith initializes an example SmmaStrategyWith instance with default parameters.

func (*SmmaStrategy) Compute

func (s *SmmaStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action

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

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

func (*SmmaStrategy) Name

func (s *SmmaStrategy) Name() string

Name returns the name of the example strategy.

func (*SmmaStrategy) Report

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

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

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

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

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

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

func (*TrimaStrategy) Name

func (*TrimaStrategy) Name() string

Name returns the name of the example strategy.

func (*TrimaStrategy) Report

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

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

NewTripleMovingAverageCrossoverStrategy initializes an example TripleMovingAverageCrossoverStrategy instance with default parameters.

func NewTripleMovingAverageCrossoverStrategyWith(fastPeriod, mediumPeriod, slowPeriod int) *TripleMovingAverageCrossoverStrategy

NewTripleMovingAverageCrossoverStrategyWith initializes an example TripleMovingAverageCrossoverStrategyWith instance with default parameters.

func (*TripleMovingAverageCrossoverStrategy) Compute

func (t *TripleMovingAverageCrossoverStrategy) Compute(c <-chan *asset.Snapshot) <-chan strategy.Action

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

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

func (*TripleMovingAverageCrossoverStrategy) Name

func (*TripleMovingAverageCrossoverStrategy) Name() string

Name returns the name of the example strategy.

func (*TripleMovingAverageCrossoverStrategy) Report

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

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

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

NewTrixStrategy initializes an example TrixStrategy instance with default parameters.

func (*TrixStrategy) Compute

func (t *TrixStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action

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

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

func (*TrixStrategy) Name

func (*TrixStrategy) Name() string

Name returns the name of the example strategy.

func (*TrixStrategy) Report

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

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

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

NewTsiStrategy initializes an example TsiStrategy instance with default parameters.

func NewTsiStrategyWith(firstSmoothingPeriod, secondSmoothingPeriod, signalPeriod int) *TsiStrategy

NewTsiStrategyWith initializes an example TsiStrategyWith instance with default parameters.

func (*TsiStrategy) Compute

func (t *TsiStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action

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

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

func (*TsiStrategy) IdlePeriod

func (t *TsiStrategy) IdlePeriod() int

IdlePeriod is the initial period that TSI strategy yield any results.

func (*TsiStrategy) Name

func (t *TsiStrategy) Name() string

Name returns the name of the example strategy.

func (*TsiStrategy) Report

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

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

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

NewVwmaStrategy initializes an example VwmaStrategy instance with default parameters.

func (*VwmaStrategy) Compute

func (v *VwmaStrategy) Compute(c <-chan *asset.Snapshot) <-chan strategy.Action

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

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

func (*VwmaStrategy) Name

func (*VwmaStrategy) Name() string

Name returns the name of the example strategy.

func (*VwmaStrategy) Report

func (v *VwmaStrategy) Report(c <-chan *asset.Snapshot) *helper.Report

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

NewWeightedCloseStrategy initializes an example WeightedCloseStrategy instance with default parameters.

func NewWeightedCloseStrategyWith(maPeriod int) *WeightedCloseStrategy

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

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

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

func (*WeightedCloseStrategy) Name

func (w *WeightedCloseStrategy) Name() string

Name returns the name of the example strategy.

func (*WeightedCloseStrategy) Report

func (w *WeightedCloseStrategy) Report(snapshots <-chan *asset.Snapshot) *helper.Report

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

Generated by gomarkdoc