trend

package
v2.1.29 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2026 License: AGPL-3.0 Imports: 6 Imported by: 4

README

trend

import "github.com/cinar/indicator/v2/strategy/trend"

Package trend contains the trend strategy functions.

This package belongs to the Indicator project. Indicator is a Golang module that supplies a variety of technical indicators, strategies, and a backtesting framework for analysis.

License
Copyright (c) 2021-2026 Onur Cinar.
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 purposes and is not to be construed as advice or solicitation to buy or sell any security.

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 (
    // 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.Strategy

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

type AlligatorStrategy

AlligatorStrategy represents the configuration parameters for calculating the Alligator strategy. It is a technical indicator to help identify the presence and the direction of the trend. It uses three Smooted Moving Averges (SMMAs).

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

NewAlligatorStrategy function initializes a new Alligator strategy instance.

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

NewAlligatorStrategyWith function initializes a new Alligator strategy instance with the given parameters.

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

Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

func (*AlligatorStrategy) Name
func (a *AlligatorStrategy) Name() string

Name returns the name of the strategy.

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

Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

type ApoStrategy

ApoStrategy represents the configuration parameters for calculating the APO strategy. An APO value crossing above zero suggests a bullish trend, while crossing below zero indicates a bearish trend. Positive APO values signify an upward trend, while negative values signify a downward trend.

type ApoStrategy struct {
    // Apo represents the configuration parameters for calculating the
    // Absolute Price Oscillator (APO).
    Apo *trend.Apo[float64]
}

func NewApoStrategy
func NewApoStrategy() *ApoStrategy

NewApoStrategy function initializes a new APO strategy instance with the default parameters.

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

Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

func (*ApoStrategy) Name
func (*ApoStrategy) Name() string

Name returns the name of the strategy.

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

Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

type AroonStrategy

AroonStrategy represents the configuration parameters for calculating the Aroon strategy. Aroon is a technical analysis tool that gauges trend direction and strength in asset prices. It comprises two lines: Aroon Up and Aroon Down. Aroon Up measures uptrend strength, while Aroon Down measures downtrend strength. When Aroon Up exceeds Aroon Down, it suggests a bullish trend; when Aroon Down surpasses Aroon Up, it indicates a bearish trend.

type AroonStrategy struct {
    // Aroon represent the configuration for calculating the Aroon indicator.
    Aroon *trend.Aroon[float64]
}

func NewAroonStrategy
func NewAroonStrategy() *AroonStrategy

NewAroonStrategy function initializes a new Aroon strategy instance with the default parameters.

func (*AroonStrategy) Compute
func (a *AroonStrategy) Compute(c <-chan *asset.Snapshot) <-chan strategy.Action

Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

func (*AroonStrategy) Name
func (*AroonStrategy) Name() string

Name returns the name of the strategy.

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

Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

type BopStrategy

BopStrategy gauges the strength of buying and selling forces using the Balance of Power (BoP) indicator. A positive BoP value suggests an upward trend, while a negative value indicates a downward trend. A BoP value of zero implies equilibrium between the two forces.

type BopStrategy struct {
    // Bop represents the configuration parameters for calculating the
    // Balance of Power (BoP).
    Bop *trend.Bop[float64]
}

func NewBopStrategy
func NewBopStrategy() *BopStrategy

NewBopStrategy function initializes a new BoP strategy instance with the default parameters.

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

Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

func (*BopStrategy) Name
func (*BopStrategy) Name() string

Name returns the name of the strategy.

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

Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

type CciStrategy

CciStrategy represents the configuration parameters for calculating the CCI strategy. A CCI value crossing above the 100+ suggests a bullish trend, while crossing below the 100- indicates a bearish trend.

type CciStrategy struct {
    // Cci represents the configuration parameters for calculating the CCI.
    Cci *trend.Cci[float64]
}

func NewCciStrategy
func NewCciStrategy() *CciStrategy

NewCciStrategy function initializes a new CCI strategy instance.

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

Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

func (*CciStrategy) Name
func (*CciStrategy) Name() string

Name returns the name of the strategy.

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

Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

type CfoStrategy

CfoStrategy represents the configuration parameters for calculating the CFO strategy. A CFO value crossing above zero suggests a bullish trend, while crossing below zero indicates a bearish trend. Positive CFO values signify an upward trend, while negative values signify a downward trend.

type CfoStrategy struct {
    // Cfo represents the configuration parameters for calculating the
    // Chande Forecast Oscillator (CFO).
    Cfo *trend.Cfo[float64]
}

func NewCfoStrategy
func NewCfoStrategy() *CfoStrategy

NewCfoStrategy function initializes a new CFO strategy instance with the default parameters.

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

Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

func (*CfoStrategy) Name
func (*CfoStrategy) Name() string

Name returns the name of the strategy.

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

Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

type DemaStrategy

DemaStrategy represents the configuration parameters for calculating the DEMA strategy. A bullish cross occurs when DEMA with 5 days period moves above DEMA with 35 days period. A bearish cross occurs when DEMA with 35 days period moves above DEMA With 5 days period.

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

NewDemaStrategy function initializes a new DEMA strategy instance with the default parameters.

func (*DemaStrategy) Compute
func (d *DemaStrategy) Compute(c <-chan *asset.Snapshot) <-chan strategy.Action

Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

func (*DemaStrategy) Name
func (*DemaStrategy) Name() string

Name returns the name of the strategy.

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

Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

type EnvelopeStrategy

EnvelopeStrategy represents the configuration parameters for calculating the Envelope strategy. When the closing is above the upper band suggests a Sell recommendation, and when the closing is below the lower band suggests a buy recommendation.

type EnvelopeStrategy struct {
    // Envelope is the envelope indicator instance.
    Envelope *trend.Envelope[float64]
}

func NewEnvelopeStrategy
func NewEnvelopeStrategy() *EnvelopeStrategy

NewEnvelopeStrategy function initializes a new Envelope strategy with the default parameters.

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

NewEnvelopeStrategyWith function initializes a new Envelope strategy with the given Envelope instance.

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

Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

func (*EnvelopeStrategy) Name
func (e *EnvelopeStrategy) Name() string

Name returns the name of the strategy.

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

Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

type GoldenCrossStrategy

GoldenCrossStrategy defines the parameters used to calculate the Golden Cross trading strategy. This strategy uses two Exponential Moving Averages (EMAs) with different lengths to identify potential buy and sell signals. - A buy signal is generated when the **fastest** EMA crosses above the **slowest** EMAs. - A sell signal is generated when the fastest EMA crosses below the slowest EMAs. - Otherwise, the strategy recommends holding the asset.

type GoldenCrossStrategy struct {
    // FastEma is the fastest EMA.
    FastEma *trend.Ema[float64]

    // SlowEma is the slowest EMA.
    SlowEma *trend.Ema[float64]
}

func NewGoldenCrossStrategy
func NewGoldenCrossStrategy() *GoldenCrossStrategy

NewGoldenCrossStrategy function initializes a new Golden Cross strategy instance with the default parameters.

func NewGoldenCrossStrategyWith
func NewGoldenCrossStrategyWith(fastPeriod, slowPeriod int) *GoldenCrossStrategy

NewGoldenCrossStrategyWith function initializes a new Golden Cross strategy instance with the given periods.

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

Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

func (*GoldenCrossStrategy) Name
func (*GoldenCrossStrategy) Name() string

Name returns the name of the strategy.

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

Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

type KamaStrategy

KamaStrategy represents the configuration parameters for calculating the KAMA strategy. A closing price crossing above the KAMA suggests a bullish trend, while crossing below the KAMA indicates a bearish trend.

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

NewKamaStrategy function initializes a new KAMA strategy instance.

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

NewKamaStrategyWith function initializes a new KAMA strategy instance with the given parameters.

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

Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

func (*KamaStrategy) Name
func (k *KamaStrategy) Name() string

Name returns the name of the strategy.

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

Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

type KdjStrategy

KdjStrategy represents the configuration parameters for calculating the KDJ strategy. Generates BUY action when j value crosses above both k and d values. Generates SELL action when j value crosses below both k and d values.

type KdjStrategy struct {
    // Kdj represents the configuration parameters for calculating the KDJ.
    Kdj *trend.Kdj[float64]
}

func NewKdjStrategy
func NewKdjStrategy() *KdjStrategy

NewKdjStrategy function initializes a new KDJ strategy instance.

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

Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

func (*KdjStrategy) Name
func (*KdjStrategy) Name() string

Name returns the name of the strategy.

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

Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

type MacdStrategy

MacdStrategy represents the configuration parameters for calculating the MACD strategy. A MACD value crossing above the signal line suggests a bullish trend, while crossing below the signal line indicates a bearish trend.

type MacdStrategy struct {
    // Macd represents the configuration parameters for calculating the
    // Moving Average Convergence Divergence (MACD).
    Macd *trend.Macd[float64]
}

func NewMacdStrategy
func NewMacdStrategy() *MacdStrategy

NewMacdStrategy function initializes a new MACD strategy instance.

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

NewMacdStrategyWith function initializes a new MACD strategy instance with the given parameters.

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

Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

func (*MacdStrategy) Name
func (m *MacdStrategy) Name() string

Name returns the name of the strategy.

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

Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

type QstickStrategy

QstickStrategy represents the configuration parameters for calculating the Qstick strategy. Qstick is a momentum indicator used to identify an asset's trend by looking at the SMA of the difference between its closing and opening.

A Qstick above zero indicates increasing buying pressure, while a Qstick below zero indicates increasing selling pressure.

type QstickStrategy struct {
    // Qstick represents the configuration parameters for calculating the Qstick.
    Qstick *momentum.Qstick[float64]
}

func NewQstickStrategy
func NewQstickStrategy() *QstickStrategy

NewQstickStrategy function initializes a new Qstick strategy instance.

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

Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

func (*QstickStrategy) Name
func (*QstickStrategy) Name() string

Name returns the name of the strategy.

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

Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

type SmmaStrategy

SmmaStrategy represents the configuration parameters for calculating the Smooted Moving Averge (SMMA) strategy. A short-term SMMA crossing above the long-term SMMA suggests a bullish trend, while crossing below the long-term SMMA indicates a bearish trend.

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

NewSmmaStrategy function initializes a new SMMA strategy instance.

func NewSmmaStrategyWith
func NewSmmaStrategyWith(shortPeriod, longPeriod int) *SmmaStrategy

NewSmmaStrategyWith function initializes a new SMMA strategy instance with the given parameters.

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

Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

func (*SmmaStrategy) Name
func (s *SmmaStrategy) Name() string

Name returns the name of the strategy.

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

Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

type TrimaStrategy

TrimaStrategy represents the configuration parameters for calculating the TRIMA strategy. A bullish cross occurs when the short TRIMA moves above the long TRIMA. A bearish cross occurs when the short TRIMA moves below the long TRIME.

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

NewTrimaStrategy function initializes a new TRIMA strategy instance with the default parameters.

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

Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

func (*TrimaStrategy) Name
func (*TrimaStrategy) Name() string

Name returns the name of the strategy.

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

Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

type TripleMovingAverageCrossoverStrategy

TripleMovingAverageCrossoverStrategy defines the parameters used to calculate the Triple Moving Average Crossover trading strategy. This strategy uses three Exponential Moving Averages (EMAs) with different lengths to identify potential buy and sell signals. - A buy signal is generated when the **fastest** EMA crosses above both the **medium** and **slowest** EMAs. - A sell signal is generated when the fastest EMA crosses below both the medium and slowest EMAs. - Otherwise, the strategy recommends holding the asset.

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

NewTripleMovingAverageCrossoverStrategy function initializes a new Triple Moving Average Crossover strategy instance with the default parameters.

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

NewTripleMovingAverageCrossoverStrategyWith function initializes a new Triple Moving Average Crossover strategy instance with the given periods.

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

Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

func (*TripleMovingAverageCrossoverStrategy) Name
func (*TripleMovingAverageCrossoverStrategy) Name() string

Name returns the name of the strategy.

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

Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

type TrixStrategy

TrixStrategy represents the configuration parameters for calculating the TRIX strategy. A TRIX value crossing above the zero line suggests a bullish trend, while crossing below the zero line indicates a bearish trend.

type TrixStrategy struct {
    // Trix represents the configuration parameters for calculating the TRIX.
    Trix *trend.Trix[float64]
}

func NewTrixStrategy
func NewTrixStrategy() *TrixStrategy

NewTrixStrategy function initializes a new TRIX strategy instance.

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

Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

func (*TrixStrategy) Name
func (*TrixStrategy) Name() string

Name returns the name of the strategy.

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

Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

type TsiStrategy

TsiStrategy represents the configuration parameters for calculating the TSI strategy. When the TSI is above zero and crossing above the signal line suggests a bullish trend, while TSI being below zero and crossing below the signal line indicates a bearish trend.

Signal Line = Ema(12, TSI)
When TSI > 0, TSI > Signal Line, Buy.
When TSI < 0, TSI < Signal Line, Sell.const
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() *TsiStrategy

NewTsiStrategy function initializes a new TSI strategy instance.

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

NewTsiStrategyWith function initializes a new TSI strategy instance with the given parameters.

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

Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

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

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

Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

type VwmaStrategy

VwmaStrategy represents the configuration parameters for calculating the VWMA strategy. The VwmaStrategy function uses SMA and VWMA indicators to provide a BUY action when VWMA is above SMA, and a SELL signal when VWMA is below SMA, a HOLD otherwse.

type VwmaStrategy struct {
    // VWMA indicator.
    Vwma *trend.Vwma[float64]

    // SMA indicator.
    Sma *trend.Sma[float64]
}

func NewVwmaStrategy
func NewVwmaStrategy() *VwmaStrategy

NewVwmaStrategy function initializes a new VWMA strategy instance with the default parameters.

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

Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

func (*VwmaStrategy) Name
func (*VwmaStrategy) Name() string

Name returns the name of the strategy.

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

Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

type WeightedCloseStrategy

WeightedCloseStrategy represents the configuration parameters for calculating the Weighted Close strategy. A weighted close crossing above the moving average suggests a bullish trend, while crossing below the moving average indicates a bearish trend.

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

NewWeightedCloseStrategy function initializes a new Weighted Close strategy instance.

func NewWeightedCloseStrategyWith
func NewWeightedCloseStrategyWith(maPeriod int) *WeightedCloseStrategy

NewWeightedCloseStrategyWith function initializes a new Weighted Close strategy instance with the given parameters.

func (*WeightedCloseStrategy) Compute
func (w *WeightedCloseStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action

Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

func (*WeightedCloseStrategy) Name
func (w *WeightedCloseStrategy) Name() string

Name returns the name of the strategy.

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

Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

Generated by gomarkdoc

Documentation

Overview

Package trend contains the trend strategy functions.

This package belongs to the Indicator project. Indicator is a Golang module that supplies a variety of technical indicators, strategies, and a backtesting framework for analysis.

License

Copyright (c) 2021-2026 Onur Cinar.
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 purposes and is not to be construed as advice or solicitation to buy or sell any security.

Index

Constants

View Source
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
)
View Source
const (
	// DefaultDemaStrategyPeriod1 is the first DEMA period.
	DefaultDemaStrategyPeriod1 = 5

	// DefaultDemaStrategyPeriod2 is the second DEMA period.
	DefaultDemaStrategyPeriod2 = 35
)
View Source
const (
	// DefaultGoldenCrossStrategyFastPeriod is the default golden cross strategy fast period.
	DefaultGoldenCrossStrategyFastPeriod = 50

	// DefaultGoldenCrossStrategySlowPeriod is the default golden cross strategy slow period.
	DefaultGoldenCrossStrategySlowPeriod = 200
)
View Source
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
)
View Source
const (
	// DefaultTrimaStrategyShortPeriod is the first TRIMA period.
	DefaultTrimaStrategyShortPeriod = 20

	// DefaultTrimaStrategyLongPeriod is the second TRIMA period.
	DefaultTrimaStrategyLongPeriod = 50
)
View Source
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
)
View Source
const (
	// DefaultTsiStrategySignalPeriod is the default signal line period of 12.
	DefaultTsiStrategySignalPeriod = 12
)
View Source
const (
	// DefaultVwmaStrategyPeriod is the default VWMA period.
	DefaultVwmaStrategyPeriod = 20
)
View Source
const (
	// DefaultWeightedCloseStrategyMaPeriod is the default Moving Average period of 20.
	DefaultWeightedCloseStrategyMaPeriod = 20
)

Variables

This section is empty.

Functions

func AllStrategies

func AllStrategies() []strategy.Strategy

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

Types

type AlligatorStrategy added in v2.1.11

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]
}

AlligatorStrategy represents the configuration parameters for calculating the Alligator strategy. It is a technical indicator to help identify the presence and the direction of the trend. It uses three Smooted Moving Averges (SMMAs).

func NewAlligatorStrategy added in v2.1.11

func NewAlligatorStrategy() *AlligatorStrategy

NewAlligatorStrategy function initializes a new Alligator strategy instance.

func NewAlligatorStrategyWith added in v2.1.11

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

NewAlligatorStrategyWith function initializes a new Alligator strategy instance with the given parameters.

func (*AlligatorStrategy) Compute added in v2.1.11

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

Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

func (*AlligatorStrategy) Name added in v2.1.11

func (a *AlligatorStrategy) Name() string

Name returns the name of the strategy.

func (*AlligatorStrategy) Report added in v2.1.11

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

Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

type ApoStrategy

type ApoStrategy struct {
	// Apo represents the configuration parameters for calculating the
	// Absolute Price Oscillator (APO).
	Apo *trend.Apo[float64]
}

ApoStrategy represents the configuration parameters for calculating the APO strategy. An APO value crossing above zero suggests a bullish trend, while crossing below zero indicates a bearish trend. Positive APO values signify an upward trend, while negative values signify a downward trend.

func NewApoStrategy

func NewApoStrategy() *ApoStrategy

NewApoStrategy function initializes a new APO strategy instance with the default parameters.

func (*ApoStrategy) Compute

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

Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

func (*ApoStrategy) Name

func (*ApoStrategy) Name() string

Name returns the name of the strategy.

func (*ApoStrategy) Report

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

Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

type AroonStrategy

type AroonStrategy struct {
	// Aroon represent the configuration for calculating the Aroon indicator.
	Aroon *trend.Aroon[float64]
}

AroonStrategy represents the configuration parameters for calculating the Aroon strategy. Aroon is a technical analysis tool that gauges trend direction and strength in asset prices. It comprises two lines: Aroon Up and Aroon Down. Aroon Up measures uptrend strength, while Aroon Down measures downtrend strength. When Aroon Up exceeds Aroon Down, it suggests a bullish trend; when Aroon Down surpasses Aroon Up, it indicates a bearish trend.

func NewAroonStrategy

func NewAroonStrategy() *AroonStrategy

NewAroonStrategy function initializes a new Aroon strategy instance with the default parameters.

func (*AroonStrategy) Compute

func (a *AroonStrategy) Compute(c <-chan *asset.Snapshot) <-chan strategy.Action

Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

func (*AroonStrategy) Name

func (*AroonStrategy) Name() string

Name returns the name of the strategy.

func (*AroonStrategy) Report

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

Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

type BopStrategy

type BopStrategy struct {
	// Bop represents the configuration parameters for calculating the
	// Balance of Power (BoP).
	Bop *trend.Bop[float64]
}

BopStrategy gauges the strength of buying and selling forces using the Balance of Power (BoP) indicator. A positive BoP value suggests an upward trend, while a negative value indicates a downward trend. A BoP value of zero implies equilibrium between the two forces.

func NewBopStrategy

func NewBopStrategy() *BopStrategy

NewBopStrategy function initializes a new BoP strategy instance with the default parameters.

func (*BopStrategy) Compute

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

Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

func (*BopStrategy) Name

func (*BopStrategy) Name() string

Name returns the name of the strategy.

func (*BopStrategy) Report

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

Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

type CciStrategy

type CciStrategy struct {
	// Cci represents the configuration parameters for calculating the CCI.
	Cci *trend.Cci[float64]
}

CciStrategy represents the configuration parameters for calculating the CCI strategy. A CCI value crossing above the 100+ suggests a bullish trend, while crossing below the 100- indicates a bearish trend.

func NewCciStrategy

func NewCciStrategy() *CciStrategy

NewCciStrategy function initializes a new CCI strategy instance.

func (*CciStrategy) Compute

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

Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

func (*CciStrategy) Name

func (*CciStrategy) Name() string

Name returns the name of the strategy.

func (*CciStrategy) Report

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

Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

type CfoStrategy added in v2.1.26

type CfoStrategy struct {
	// Cfo represents the configuration parameters for calculating the
	// Chande Forecast Oscillator (CFO).
	Cfo *trend.Cfo[float64]
}

CfoStrategy represents the configuration parameters for calculating the CFO strategy. A CFO value crossing above zero suggests a bullish trend, while crossing below zero indicates a bearish trend. Positive CFO values signify an upward trend, while negative values signify a downward trend.

func NewCfoStrategy added in v2.1.26

func NewCfoStrategy() *CfoStrategy

NewCfoStrategy function initializes a new CFO strategy instance with the default parameters.

func (*CfoStrategy) Compute added in v2.1.26

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

Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

func (*CfoStrategy) Name added in v2.1.26

func (*CfoStrategy) Name() string

Name returns the name of the strategy.

func (*CfoStrategy) Report added in v2.1.26

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

Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

type DemaStrategy

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]
}

DemaStrategy represents the configuration parameters for calculating the DEMA strategy. A bullish cross occurs when DEMA with 5 days period moves above DEMA with 35 days period. A bearish cross occurs when DEMA with 35 days period moves above DEMA With 5 days period.

func NewDemaStrategy

func NewDemaStrategy() *DemaStrategy

NewDemaStrategy function initializes a new DEMA strategy instance with the default parameters.

func (*DemaStrategy) Compute

func (d *DemaStrategy) Compute(c <-chan *asset.Snapshot) <-chan strategy.Action

Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

func (*DemaStrategy) Name

func (*DemaStrategy) Name() string

Name returns the name of the strategy.

func (*DemaStrategy) Report

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

Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

type EnvelopeStrategy added in v2.1.7

type EnvelopeStrategy struct {
	// Envelope is the envelope indicator instance.
	Envelope *trend.Envelope[float64]
}

EnvelopeStrategy represents the configuration parameters for calculating the Envelope strategy. When the closing is above the upper band suggests a Sell recommendation, and when the closing is below the lower band suggests a buy recommendation.

func NewEnvelopeStrategy added in v2.1.7

func NewEnvelopeStrategy() *EnvelopeStrategy

NewEnvelopeStrategy function initializes a new Envelope strategy with the default parameters.

func NewEnvelopeStrategyWith added in v2.1.7

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

NewEnvelopeStrategyWith function initializes a new Envelope strategy with the given Envelope instance.

func (*EnvelopeStrategy) Compute added in v2.1.7

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

Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

func (*EnvelopeStrategy) Name added in v2.1.7

func (e *EnvelopeStrategy) Name() string

Name returns the name of the strategy.

func (*EnvelopeStrategy) Report added in v2.1.7

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

Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

type GoldenCrossStrategy

type GoldenCrossStrategy struct {
	// FastEma is the fastest EMA.
	FastEma *trend.Ema[float64]

	// SlowEma is the slowest EMA.
	SlowEma *trend.Ema[float64]
}

GoldenCrossStrategy defines the parameters used to calculate the Golden Cross trading strategy. This strategy uses two Exponential Moving Averages (EMAs) with different lengths to identify potential buy and sell signals. - A buy signal is generated when the **fastest** EMA crosses above the **slowest** EMAs. - A sell signal is generated when the fastest EMA crosses below the slowest EMAs. - Otherwise, the strategy recommends holding the asset.

func NewGoldenCrossStrategy

func NewGoldenCrossStrategy() *GoldenCrossStrategy

NewGoldenCrossStrategy function initializes a new Golden Cross strategy instance with the default parameters.

func NewGoldenCrossStrategyWith

func NewGoldenCrossStrategyWith(fastPeriod, slowPeriod int) *GoldenCrossStrategy

NewGoldenCrossStrategyWith function initializes a new Golden Cross strategy instance with the given periods.

func (*GoldenCrossStrategy) Compute

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

Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

func (*GoldenCrossStrategy) Name

func (*GoldenCrossStrategy) Name() string

Name returns the name of the strategy.

func (*GoldenCrossStrategy) Report

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

Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

type KamaStrategy added in v2.0.3

type KamaStrategy struct {
	// Kama represents the configuration parameters for calculating the Kaufman's Adaptive Moving Average (KAMA).
	Kama *trend.Kama[float64]
}

KamaStrategy represents the configuration parameters for calculating the KAMA strategy. A closing price crossing above the KAMA suggests a bullish trend, while crossing below the KAMA indicates a bearish trend.

func NewKamaStrategy added in v2.0.3

func NewKamaStrategy() *KamaStrategy

NewKamaStrategy function initializes a new KAMA strategy instance.

func NewKamaStrategyWith added in v2.0.3

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

NewKamaStrategyWith function initializes a new KAMA strategy instance with the given parameters.

func (*KamaStrategy) Compute added in v2.0.3

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

Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

func (*KamaStrategy) Name added in v2.0.3

func (k *KamaStrategy) Name() string

Name returns the name of the strategy.

func (*KamaStrategy) Report added in v2.0.3

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

Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

type KdjStrategy

type KdjStrategy struct {
	// Kdj represents the configuration parameters for calculating the KDJ.
	Kdj *trend.Kdj[float64]
}

KdjStrategy represents the configuration parameters for calculating the KDJ strategy. Generates BUY action when j value crosses above both k and d values. Generates SELL action when j value crosses below both k and d values.

func NewKdjStrategy

func NewKdjStrategy() *KdjStrategy

NewKdjStrategy function initializes a new KDJ strategy instance.

func (*KdjStrategy) Compute

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

Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

func (*KdjStrategy) Name

func (*KdjStrategy) Name() string

Name returns the name of the strategy.

func (*KdjStrategy) Report

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

Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

type MacdStrategy

type MacdStrategy struct {
	// Macd represents the configuration parameters for calculating the
	// Moving Average Convergence Divergence (MACD).
	Macd *trend.Macd[float64]
}

MacdStrategy represents the configuration parameters for calculating the MACD strategy. A MACD value crossing above the signal line suggests a bullish trend, while crossing below the signal line indicates a bearish trend.

func NewMacdStrategy

func NewMacdStrategy() *MacdStrategy

NewMacdStrategy function initializes a new MACD strategy instance.

func NewMacdStrategyWith

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

NewMacdStrategyWith function initializes a new MACD strategy instance with the given parameters.

func (*MacdStrategy) Compute

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

Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

func (*MacdStrategy) Name

func (m *MacdStrategy) Name() string

Name returns the name of the strategy.

func (*MacdStrategy) Report

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

Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

type QstickStrategy

type QstickStrategy struct {
	// Qstick represents the configuration parameters for calculating the Qstick.
	Qstick *momentum.Qstick[float64]
}

QstickStrategy represents the configuration parameters for calculating the Qstick strategy. Qstick is a momentum indicator used to identify an asset's trend by looking at the SMA of the difference between its closing and opening.

A Qstick above zero indicates increasing buying pressure, while a Qstick below zero indicates increasing selling pressure.

func NewQstickStrategy

func NewQstickStrategy() *QstickStrategy

NewQstickStrategy function initializes a new Qstick strategy instance.

func (*QstickStrategy) Compute

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

Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

func (*QstickStrategy) Name

func (*QstickStrategy) Name() string

Name returns the name of the strategy.

func (*QstickStrategy) Report

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

Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

type SmmaStrategy added in v2.1.10

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]
}

SmmaStrategy represents the configuration parameters for calculating the Smooted Moving Averge (SMMA) strategy. A short-term SMMA crossing above the long-term SMMA suggests a bullish trend, while crossing below the long-term SMMA indicates a bearish trend.

func NewSmmaStrategy added in v2.1.10

func NewSmmaStrategy() *SmmaStrategy

NewSmmaStrategy function initializes a new SMMA strategy instance.

func NewSmmaStrategyWith added in v2.1.10

func NewSmmaStrategyWith(shortPeriod, longPeriod int) *SmmaStrategy

NewSmmaStrategyWith function initializes a new SMMA strategy instance with the given parameters.

func (*SmmaStrategy) Compute added in v2.1.10

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

Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

func (*SmmaStrategy) Name added in v2.1.10

func (s *SmmaStrategy) Name() string

Name returns the name of the strategy.

func (*SmmaStrategy) Report added in v2.1.10

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

Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

type TrimaStrategy

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]
}

TrimaStrategy represents the configuration parameters for calculating the TRIMA strategy. A bullish cross occurs when the short TRIMA moves above the long TRIMA. A bearish cross occurs when the short TRIMA moves below the long TRIME.

func NewTrimaStrategy

func NewTrimaStrategy() *TrimaStrategy

NewTrimaStrategy function initializes a new TRIMA strategy instance with the default parameters.

func (*TrimaStrategy) Compute

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

Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

func (*TrimaStrategy) Name

func (*TrimaStrategy) Name() string

Name returns the name of the strategy.

func (*TrimaStrategy) Report

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

Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

type TripleMovingAverageCrossoverStrategy

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]
}

TripleMovingAverageCrossoverStrategy defines the parameters used to calculate the Triple Moving Average Crossover trading strategy. This strategy uses three Exponential Moving Averages (EMAs) with different lengths to identify potential buy and sell signals. - A buy signal is generated when the **fastest** EMA crosses above both the **medium** and **slowest** EMAs. - A sell signal is generated when the fastest EMA crosses below both the medium and slowest EMAs. - Otherwise, the strategy recommends holding the asset.

func NewTripleMovingAverageCrossoverStrategy

func NewTripleMovingAverageCrossoverStrategy() *TripleMovingAverageCrossoverStrategy

NewTripleMovingAverageCrossoverStrategy function initializes a new Triple Moving Average Crossover strategy instance with the default parameters.

func NewTripleMovingAverageCrossoverStrategyWith

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

NewTripleMovingAverageCrossoverStrategyWith function initializes a new Triple Moving Average Crossover strategy instance with the given periods.

func (*TripleMovingAverageCrossoverStrategy) Compute

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

Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

func (*TripleMovingAverageCrossoverStrategy) Name

Name returns the name of the strategy.

func (*TripleMovingAverageCrossoverStrategy) Report

Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

type TrixStrategy

type TrixStrategy struct {
	// Trix represents the configuration parameters for calculating the TRIX.
	Trix *trend.Trix[float64]
}

TrixStrategy represents the configuration parameters for calculating the TRIX strategy. A TRIX value crossing above the zero line suggests a bullish trend, while crossing below the zero line indicates a bearish trend.

func NewTrixStrategy

func NewTrixStrategy() *TrixStrategy

NewTrixStrategy function initializes a new TRIX strategy instance.

func (*TrixStrategy) Compute

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

Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

func (*TrixStrategy) Name

func (*TrixStrategy) Name() string

Name returns the name of the strategy.

func (*TrixStrategy) Report

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

Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

type TsiStrategy added in v2.0.3

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]
}

TsiStrategy represents the configuration parameters for calculating the TSI strategy. When the TSI is above zero and crossing above the signal line suggests a bullish trend, while TSI being below zero and crossing below the signal line indicates a bearish trend.

Signal Line = Ema(12, TSI)
When TSI > 0, TSI > Signal Line, Buy.
When TSI < 0, TSI < Signal Line, Sell.const

func NewTsiStrategy added in v2.0.3

func NewTsiStrategy() *TsiStrategy

NewTsiStrategy function initializes a new TSI strategy instance.

func NewTsiStrategyWith added in v2.0.3

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

NewTsiStrategyWith function initializes a new TSI strategy instance with the given parameters.

func (*TsiStrategy) Compute added in v2.0.3

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

Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

func (*TsiStrategy) IdlePeriod added in v2.0.3

func (t *TsiStrategy) IdlePeriod() int

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

func (*TsiStrategy) Name added in v2.0.3

func (t *TsiStrategy) Name() string

Name returns the name of the strategy.

func (*TsiStrategy) Report added in v2.0.3

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

Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

type VwmaStrategy

type VwmaStrategy struct {
	// VWMA indicator.
	Vwma *trend.Vwma[float64]

	// SMA indicator.
	Sma *trend.Sma[float64]
}

VwmaStrategy represents the configuration parameters for calculating the VWMA strategy. The VwmaStrategy function uses SMA and VWMA indicators to provide a BUY action when VWMA is above SMA, and a SELL signal when VWMA is below SMA, a HOLD otherwse.

func NewVwmaStrategy

func NewVwmaStrategy() *VwmaStrategy

NewVwmaStrategy function initializes a new VWMA strategy instance with the default parameters.

func (*VwmaStrategy) Compute

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

Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

func (*VwmaStrategy) Name

func (*VwmaStrategy) Name() string

Name returns the name of the strategy.

func (*VwmaStrategy) Report

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

Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

type WeightedCloseStrategy added in v2.1.12

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]
}

WeightedCloseStrategy represents the configuration parameters for calculating the Weighted Close strategy. A weighted close crossing above the moving average suggests a bullish trend, while crossing below the moving average indicates a bearish trend.

func NewWeightedCloseStrategy added in v2.1.12

func NewWeightedCloseStrategy() *WeightedCloseStrategy

NewWeightedCloseStrategy function initializes a new Weighted Close strategy instance.

func NewWeightedCloseStrategyWith added in v2.1.12

func NewWeightedCloseStrategyWith(maPeriod int) *WeightedCloseStrategy

NewWeightedCloseStrategyWith function initializes a new Weighted Close strategy instance with the given parameters.

func (*WeightedCloseStrategy) Compute added in v2.1.12

func (w *WeightedCloseStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action

Compute processes the provided asset snapshots and generates a stream of actionable recommendations.

func (*WeightedCloseStrategy) Name added in v2.1.12

func (w *WeightedCloseStrategy) Name() string

Name returns the name of the strategy.

func (*WeightedCloseStrategy) Report added in v2.1.12

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

Report processes the provided asset snapshots and generates a report annotated with the recommended actions.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL