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-2024 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
- func AllStrategies() []strategy.Strategy
- type ApoStrategy
- type AroonStrategy
- type BopStrategy
- type CciStrategy
- type DemaStrategy
- type GoldenCrossStrategy
- type KamaStrategy
- type KdjStrategy
- type MacdStrategy
- type QstickStrategy
- type TrimaStrategy
- type TripleMovingAverageCrossoverStrategy
- type TrixStrategy
- type TsiStrategy
- type VwmaStrategy
Constants ¶
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 ( // 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
)
Variables ¶
This section is empty.
Functions ¶
func AllStrategies ¶
AllStrategies returns a slice containing references to all available trend strategies.
Types ¶
type ApoStrategy ¶
type ApoStrategy struct {
strategy.Strategy
// 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.
type AroonStrategy ¶
type AroonStrategy struct {
strategy.Strategy
// 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.
type BopStrategy ¶
type BopStrategy struct {
strategy.Strategy
// 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.
type CciStrategy ¶
type CciStrategy struct {
strategy.Strategy
// 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.
type DemaStrategy ¶
type DemaStrategy struct {
strategy.Strategy
// 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.
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.
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 indicats 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.
type KdjStrategy ¶
type KdjStrategy struct {
strategy.Strategy
// 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.
type MacdStrategy ¶
type MacdStrategy struct {
strategy.Strategy
// 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.
type QstickStrategy ¶
type QstickStrategy struct {
strategy.Strategy
// 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.
type TrimaStrategy ¶
type TrimaStrategy struct {
strategy.Strategy
// 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.
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 ¶
func (*TripleMovingAverageCrossoverStrategy) Name() string
Name returns the name of the strategy.
type TrixStrategy ¶
type TrixStrategy struct {
strategy.Strategy
// 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.
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.
type VwmaStrategy ¶
type VwmaStrategy struct {
strategy.Strategy
// 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.