import "github.com/cinar/indicator/v2/examples/volume"Package volume provides illustrative examples demonstrating how to compose volume indicators into trading strategies for educational and research purposes.
This package belongs to the Indicator project. Indicator is a Golang module that supplies a variety of technical indicators, strategies, and a backtesting framework for analysis.
Copyright (c) 2021-2026 The Indicator Authors.
The source code is provided under GNU AGPLv3 License.
https://github.com/cinar/indicator
The information provided on this project is strictly for informational and educational purposes and is not to be construed as investment, financial, or trading advice.
- Constants
- func AllStrategies() []strategy.Strategy
- type ChaikinMoneyFlowStrategy
- func NewChaikinMoneyFlowStrategy() *ChaikinMoneyFlowStrategy
- func NewChaikinMoneyFlowStrategyWith(period int) *ChaikinMoneyFlowStrategy
- func (c *ChaikinMoneyFlowStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (c *ChaikinMoneyFlowStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (c *ChaikinMoneyFlowStrategy) Name() string
- func (c *ChaikinMoneyFlowStrategy) Report(snapshots <-chan *asset.Snapshot) *helper.Report
- type EaseOfMovementStrategy
- func NewEaseOfMovementStrategy() *EaseOfMovementStrategy
- func NewEaseOfMovementStrategyWith(period int) *EaseOfMovementStrategy
- func (e *EaseOfMovementStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (e *EaseOfMovementStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (e *EaseOfMovementStrategy) Name() string
- func (e *EaseOfMovementStrategy) Report(snapshots <-chan *asset.Snapshot) *helper.Report
- type ForceIndexStrategy
- func NewForceIndexStrategy() *ForceIndexStrategy
- func NewForceIndexStrategyWith(period int) *ForceIndexStrategy
- func (f *ForceIndexStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (f *ForceIndexStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (f *ForceIndexStrategy) Name() string
- func (f *ForceIndexStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
- type MoneyFlowIndexStrategy
- func NewMoneyFlowIndexStrategy() *MoneyFlowIndexStrategy
- func NewMoneyFlowIndexStrategyWith(sellAt, buyAt float64) *MoneyFlowIndexStrategy
- func (m *MoneyFlowIndexStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (m *MoneyFlowIndexStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (m *MoneyFlowIndexStrategy) Name() string
- func (m *MoneyFlowIndexStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
- type NegativeVolumeIndexStrategy
- func NewNegativeVolumeIndexStrategy() *NegativeVolumeIndexStrategy
- func NewNegativeVolumeIndexStrategyWith(emaPeriod int) *NegativeVolumeIndexStrategy
- func (n *NegativeVolumeIndexStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (n *NegativeVolumeIndexStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (n *NegativeVolumeIndexStrategy) Name() string
- func (n *NegativeVolumeIndexStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
- type ObvStrategy
- func NewObvStrategy() *ObvStrategy
- func NewObvStrategyWith(period int) *ObvStrategy
- func (s *ObvStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (s *ObvStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (s *ObvStrategy) Name() string
- func (s *ObvStrategy) Report(snapshots <-chan *asset.Snapshot) *helper.Report
- type PercentBandMFIStrategy
- func NewPercentBandMFIStrategy() *PercentBandMFIStrategy
- func NewPercentBandMFIStrategyWith(sellPercentBAt, buyPercentBAt, sellMfiAt, buyMfiAt float64) *PercentBandMFIStrategy
- func (m *PercentBandMFIStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (m *PercentBandMFIStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (m *PercentBandMFIStrategy) Name() string
- func (m *PercentBandMFIStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
- type WeightedAveragePriceStrategy
- func NewWeightedAveragePriceStrategy() *WeightedAveragePriceStrategy
- func NewWeightedAveragePriceStrategyWith(period int) *WeightedAveragePriceStrategy
- func (v *WeightedAveragePriceStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (v *WeightedAveragePriceStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (v *WeightedAveragePriceStrategy) Name() string
- func (v *WeightedAveragePriceStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
const (
// DefaultMoneyFlowIndexStrategySellAt is the default sell at of 80.
DefaultMoneyFlowIndexStrategySellAt = 80
// DefaultMoneyFlowIndexStrategyBuyAt is the default buy at of 20.
DefaultMoneyFlowIndexStrategyBuyAt = 20
)const (
// DefaultPercentBandMFIStrategyPercentBBuyAt is the default buy for %B at of 0.8.
DefaultPercentBandMFIStrategyPercentBBuyAt = 0.8
// DefaultPercentBandMFIStrategyPercentBSellAt is the default sell for %B at of 0.2.
DefaultPercentBandMFIStrategyPercentBSellAt = 0.2
// DefaultPercentBandMFIStrategyMfiBuyAt is the default buy for MFI at of 80.
DefaultPercentBandMFIStrategyMfiBuyAt = 80
// DefaultPercentBandMFIStrategyMfiSellAt is the default sell for MFI at of 20.
DefaultPercentBandMFIStrategyMfiSellAt = 20
)const (
// DefaultNegativeVolumeIndexStrategyEmaPeriod is the default EMA period of 255.
DefaultNegativeVolumeIndexStrategyEmaPeriod = 255
)const (
// DefaultObvStrategyPeriod is the default OBV strategy period.
DefaultObvStrategyPeriod = 10
)func AllStrategies
func AllStrategies() []strategy.StrategyAllStrategies returns a slice containing references to all available example volume strategies.
ChaikinMoneyFlowStrategy demonstrates how to compose the Chaikin Money Flow (CMF) indicator into an illustrative zero-line crossover strategy.
type ChaikinMoneyFlowStrategy struct {
// ChaikinMoneyFlow is the Chaikin Money Flow indicator instance.
ChaikinMoneyFlow *volume.Cmf[float64]
}func NewChaikinMoneyFlowStrategy() *ChaikinMoneyFlowStrategyNewChaikinMoneyFlowStrategy initializes an example ChaikinMoneyFlowStrategy instance with default parameters. default parameters.
func NewChaikinMoneyFlowStrategyWith(period int) *ChaikinMoneyFlowStrategyNewChaikinMoneyFlowStrategyWith initializes an example ChaikinMoneyFlowStrategyWith instance with default parameters. given parameters.
func (*ChaikinMoneyFlowStrategy) Compute
func (c *ChaikinMoneyFlowStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.ActionCompute wraps ComputeWithContext for backwards compatibility.
Deprecated: Use ComputeWithContext instead.
func (*ChaikinMoneyFlowStrategy) ComputeWithContext
func (c *ChaikinMoneyFlowStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.ActionComputeWithContext function processes the provided asset snapshots and generates a stream of actionable recommendations.
func (*ChaikinMoneyFlowStrategy) Name
func (c *ChaikinMoneyFlowStrategy) Name() stringName function returns the name of the strategy.
func (*ChaikinMoneyFlowStrategy) Report
func (c *ChaikinMoneyFlowStrategy) Report(snapshots <-chan *asset.Snapshot) *helper.ReportReport function processes the provided asset snapshots and generates a report annotated with the recommended actions.
EaseOfMovementStrategy demonstrates how to compose the Ease of Movement (EMV) indicator into an illustrative zero-line crossover strategy.
type EaseOfMovementStrategy struct {
// EaseOfMovement is the Ease of Movement indicator instance.
EaseOfMovement *volume.Emv[float64]
}func NewEaseOfMovementStrategy() *EaseOfMovementStrategyNewEaseOfMovementStrategy initializes an example EaseOfMovementStrategy instance with default parameters. default parameters.
func NewEaseOfMovementStrategyWith(period int) *EaseOfMovementStrategyNewEaseOfMovementStrategyWith initializes an example EaseOfMovementStrategyWith instance with default parameters. given parameters.
func (*EaseOfMovementStrategy) Compute
func (e *EaseOfMovementStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.ActionCompute wraps ComputeWithContext for backwards compatibility.
Deprecated: Use ComputeWithContext instead.
func (*EaseOfMovementStrategy) ComputeWithContext
func (e *EaseOfMovementStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.ActionComputeWithContext function processes the provided asset snapshots and generates a stream of actionable recommendations.
func (*EaseOfMovementStrategy) Name
func (e *EaseOfMovementStrategy) Name() stringName function returns the name of the strategy.
func (*EaseOfMovementStrategy) Report
func (e *EaseOfMovementStrategy) Report(snapshots <-chan *asset.Snapshot) *helper.ReportReport function processes the provided asset snapshots and generates a report annotated with the recommended actions.
type ForceIndexStrategy
ForceIndexStrategy demonstrates how to compose the Force Index indicator into an illustrative zero-line crossover strategy.
type ForceIndexStrategy struct {
// ForceIndex is the Force Index instance.
ForceIndex *volume.Fi[float64]
}func NewForceIndexStrategy() *ForceIndexStrategyNewForceIndexStrategy initializes an example ForceIndexStrategy instance with default parameters.
func NewForceIndexStrategyWith(period int) *ForceIndexStrategyNewForceIndexStrategyWith initializes an example ForceIndexStrategyWith instance with default parameters.
func (*ForceIndexStrategy) Compute
func (f *ForceIndexStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.ActionCompute wraps ComputeWithContext for backwards compatibility.
Deprecated: Use ComputeWithContext instead.
func (*ForceIndexStrategy) ComputeWithContext
func (f *ForceIndexStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.ActionComputeWithContext processes the provided asset snapshots and generates an illustrative stream of actions.
func (*ForceIndexStrategy) Name
func (f *ForceIndexStrategy) Name() stringName returns the name of the example strategy.
func (*ForceIndexStrategy) Report
func (f *ForceIndexStrategy) Report(c <-chan *asset.Snapshot) *helper.ReportReport processes the provided asset snapshots and generates an illustrative report annotated with example actions.
MoneyFlowIndexStrategy demonstrates how to compose the Money Flow Index (MFI) into an illustrative threshold-based strategy.
type MoneyFlowIndexStrategy struct {
// MoneyFlowIndex is the Money Flow Index indicator instance.
MoneyFlowIndex *volume.Mfi[float64]
// SellAt is the sell at value.
SellAt float64
// BuyAt is the buy at value.
BuyAt float64
}func NewMoneyFlowIndexStrategy() *MoneyFlowIndexStrategyNewMoneyFlowIndexStrategy initializes an example MoneyFlowIndexStrategy instance with default parameters.
func NewMoneyFlowIndexStrategyWith(sellAt, buyAt float64) *MoneyFlowIndexStrategyNewMoneyFlowIndexStrategyWith initializes an example MoneyFlowIndexStrategyWith instance with default parameters. given parameters.
func (*MoneyFlowIndexStrategy) Compute
func (m *MoneyFlowIndexStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.ActionCompute wraps ComputeWithContext for backwards compatibility.
Deprecated: Use ComputeWithContext instead.
func (*MoneyFlowIndexStrategy) ComputeWithContext
func (m *MoneyFlowIndexStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.ActionComputeWithContext processes the provided asset snapshots and generates an illustrative stream of actions.
func (*MoneyFlowIndexStrategy) Name
func (m *MoneyFlowIndexStrategy) Name() stringName returns the name of the example strategy.
func (*MoneyFlowIndexStrategy) Report
func (m *MoneyFlowIndexStrategy) Report(c <-chan *asset.Snapshot) *helper.ReportReport processes the provided asset snapshots and generates an illustrative report annotated with example actions.
NegativeVolumeIndexStrategy demonstrates how to compose the Negative Volume Index (NVI) and its moving average into an illustrative crossover strategy.
type NegativeVolumeIndexStrategy struct {
// NegativeVolumeIndex is the Negative Volume Index indicator instance.
NegativeVolumeIndex *volume.Nvi[float64]
// NegativeVolumeIndexEma is the Negative Volume Index EMA instance.
NegativeVolumeIndexEma *trend.Ema[float64]
}func NewNegativeVolumeIndexStrategy() *NegativeVolumeIndexStrategyNewNegativeVolumeIndexStrategy initializes an example NegativeVolumeIndexStrategy instance with default parameters. default parameters.
func NewNegativeVolumeIndexStrategyWith(emaPeriod int) *NegativeVolumeIndexStrategyNewNegativeVolumeIndexStrategyWith initializes an example NegativeVolumeIndexStrategyWith instance with default parameters. given parameters.
func (*NegativeVolumeIndexStrategy) Compute
func (n *NegativeVolumeIndexStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.ActionCompute wraps ComputeWithContext for backwards compatibility.
Deprecated: Use ComputeWithContext instead.
func (*NegativeVolumeIndexStrategy) ComputeWithContext
func (n *NegativeVolumeIndexStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.ActionComputeWithContext processes the provided asset snapshots and generates an illustrative stream of actions.
func (*NegativeVolumeIndexStrategy) Name
func (n *NegativeVolumeIndexStrategy) Name() stringName returns the name of the example strategy.
func (*NegativeVolumeIndexStrategy) Report
func (n *NegativeVolumeIndexStrategy) Report(c <-chan *asset.Snapshot) *helper.ReportReport processes the provided asset snapshots and generates an illustrative report annotated with example actions.
type ObvStrategy
ObvStrategy demonstrates how to compose the On-Balance Volume (OBV) indicator and its moving average into an illustrative crossover strategy.
type ObvStrategy struct {
// Obv is the OBV indicator instance.
Obv *volume.Obv[float64]
// Sma is the SMA indicator instance.
Sma *trend.Sma[float64]
}func NewObvStrategy
func NewObvStrategy() *ObvStrategyNewObvStrategy initializes an example ObvStrategy instance with default parameters.
func NewObvStrategyWith
func NewObvStrategyWith(period int) *ObvStrategyNewObvStrategyWith initializes an example ObvStrategyWith instance with default parameters.
func (*ObvStrategy) Compute
func (s *ObvStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.ActionCompute wraps ComputeWithContext for backwards compatibility.
Deprecated: Use ComputeWithContext instead.
func (*ObvStrategy) ComputeWithContext
func (s *ObvStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.ActionComputeWithContext function processes the provided asset snapshots and generates a stream of actionable recommendations.
func (*ObvStrategy) Name
func (s *ObvStrategy) Name() stringName function returns the name of the strategy.
func (*ObvStrategy) Report
func (s *ObvStrategy) Report(snapshots <-chan *asset.Snapshot) *helper.ReportReport function processes the provided asset snapshots and generates a report annotated with the recommended actions.
PercentBandMFIStrategy demonstrates how to compose Bollinger %B and Money Flow Index (MFI) into an illustrative multi-indicator strategy.
type PercentBandMFIStrategy struct {
// MoneyFlowIndex is the Money Flow Index indicator instance.
MoneyFlowIndex *volume.Mfi[float64]
// PercentB is the %B indicator instance.
PercentB *volatility.PercentB[float64]
// SellPercentBAt is the sell at value of %B.
SellPercentBAt float64
// BuyPercentBAt is the buy at value of %B.
BuyPercentBAt float64
// SellMfiAt is the sell at value of MFI.
SellMfiAt float64
// BuyMfiAt is the buy at value of MFI.
BuyMfiAt float64
}func NewPercentBandMFIStrategy() *PercentBandMFIStrategyNewPercentBandMFIStrategy initializes an example PercentBandMFIStrategy instance with default parameters.
func NewPercentBandMFIStrategyWith(sellPercentBAt, buyPercentBAt, sellMfiAt, buyMfiAt float64) *PercentBandMFIStrategyNewPercentBandMFIStrategyWith initializes an example PercentBandMFIStrategyWith instance with default parameters. given parameters.
func (*PercentBandMFIStrategy) Compute
func (m *PercentBandMFIStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.ActionCompute wraps ComputeWithContext for backwards compatibility.
Deprecated: Use ComputeWithContext instead.
func (*PercentBandMFIStrategy) ComputeWithContext
func (m *PercentBandMFIStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.ActionComputeWithContext processes the provided asset snapshots and generates an illustrative stream of actions.
func (*PercentBandMFIStrategy) Name
func (m *PercentBandMFIStrategy) Name() stringName returns the name of the example strategy.
func (*PercentBandMFIStrategy) Report
func (m *PercentBandMFIStrategy) Report(c <-chan *asset.Snapshot) *helper.ReportReport processes the provided asset snapshots and generates an illustrative report annotated with example actions.
WeightedAveragePriceStrategy demonstrates how to compose Volume Weighted Average Price (VWAP) into an illustrative price crossover strategy.
type WeightedAveragePriceStrategy struct {
// WeightedAveragePrice is the Weighted Average Price indicator instance.
WeightedAveragePrice *volume.Vwap[float64]
}func NewWeightedAveragePriceStrategy() *WeightedAveragePriceStrategyNewWeightedAveragePriceStrategy initializes an example WeightedAveragePriceStrategy instance with default parameters. instance with the default parameters.
func NewWeightedAveragePriceStrategyWith(period int) *WeightedAveragePriceStrategyNewWeightedAveragePriceStrategyWith initializes an example WeightedAveragePriceStrategyWith instance with default parameters. instance with the given parameters.
func (*WeightedAveragePriceStrategy) Compute
func (v *WeightedAveragePriceStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.ActionCompute wraps ComputeWithContext for backwards compatibility.
Deprecated: Use ComputeWithContext instead.
func (*WeightedAveragePriceStrategy) ComputeWithContext
func (v *WeightedAveragePriceStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.ActionComputeWithContext processes the provided asset snapshots and generates an illustrative stream of actions.
func (*WeightedAveragePriceStrategy) Name
func (v *WeightedAveragePriceStrategy) Name() stringName returns the name of the example strategy.
func (*WeightedAveragePriceStrategy) Report
func (v *WeightedAveragePriceStrategy) Report(c <-chan *asset.Snapshot) *helper.ReportReport processes the provided asset snapshots and generates an illustrative report annotated with example actions.
Generated by gomarkdoc