Skip to content

Latest commit

 

History

History
717 lines (504 loc) · 31.7 KB

File metadata and controls

717 lines (504 loc) · 31.7 KB

volume

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.

License

Copyright (c) 2021-2026 The Indicator Authors.
The source code is provided under GNU AGPLv3 License.
https://github.com/cinar/indicator

Disclaimer

The information provided on this project is strictly for informational and educational purposes and is not to be construed as investment, financial, or trading advice.

Index

Constants

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

AllStrategies 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() *ChaikinMoneyFlowStrategy

NewChaikinMoneyFlowStrategy initializes an example ChaikinMoneyFlowStrategy instance with default parameters. default parameters.

func NewChaikinMoneyFlowStrategyWith(period int) *ChaikinMoneyFlowStrategy

NewChaikinMoneyFlowStrategyWith initializes an example ChaikinMoneyFlowStrategyWith instance with default parameters. given parameters.

func (*ChaikinMoneyFlowStrategy) Compute

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

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

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

func (*ChaikinMoneyFlowStrategy) Name

func (c *ChaikinMoneyFlowStrategy) Name() string

Name function returns the name of the strategy.

func (*ChaikinMoneyFlowStrategy) Report

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

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

NewEaseOfMovementStrategy initializes an example EaseOfMovementStrategy instance with default parameters. default parameters.

func NewEaseOfMovementStrategyWith(period int) *EaseOfMovementStrategy

NewEaseOfMovementStrategyWith initializes an example EaseOfMovementStrategyWith instance with default parameters. given parameters.

func (*EaseOfMovementStrategy) Compute

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

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

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

func (*EaseOfMovementStrategy) Name

func (e *EaseOfMovementStrategy) Name() string

Name function returns the name of the strategy.

func (*EaseOfMovementStrategy) Report

func (e *EaseOfMovementStrategy) Report(snapshots <-chan *asset.Snapshot) *helper.Report

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

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

NewForceIndexStrategy initializes an example ForceIndexStrategy instance with default parameters.

func NewForceIndexStrategyWith(period int) *ForceIndexStrategy

NewForceIndexStrategyWith initializes an example ForceIndexStrategyWith instance with default parameters.

func (*ForceIndexStrategy) Compute

func (f *ForceIndexStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action

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

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

func (*ForceIndexStrategy) Name

func (f *ForceIndexStrategy) Name() string

Name returns the name of the example strategy.

func (*ForceIndexStrategy) Report

func (f *ForceIndexStrategy) Report(c <-chan *asset.Snapshot) *helper.Report

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

NewMoneyFlowIndexStrategy initializes an example MoneyFlowIndexStrategy instance with default parameters.

func NewMoneyFlowIndexStrategyWith(sellAt, buyAt float64) *MoneyFlowIndexStrategy

NewMoneyFlowIndexStrategyWith initializes an example MoneyFlowIndexStrategyWith instance with default parameters. given parameters.

func (*MoneyFlowIndexStrategy) Compute

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

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

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

func (*MoneyFlowIndexStrategy) Name

func (m *MoneyFlowIndexStrategy) Name() string

Name returns the name of the example strategy.

func (*MoneyFlowIndexStrategy) Report

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

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

NewNegativeVolumeIndexStrategy initializes an example NegativeVolumeIndexStrategy instance with default parameters. default parameters.

func NewNegativeVolumeIndexStrategyWith(emaPeriod int) *NegativeVolumeIndexStrategy

NewNegativeVolumeIndexStrategyWith initializes an example NegativeVolumeIndexStrategyWith instance with default parameters. given parameters.

func (*NegativeVolumeIndexStrategy) Compute

func (n *NegativeVolumeIndexStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action

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

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

func (*NegativeVolumeIndexStrategy) Name

func (n *NegativeVolumeIndexStrategy) Name() string

Name returns the name of the example strategy.

func (*NegativeVolumeIndexStrategy) Report

func (n *NegativeVolumeIndexStrategy) Report(c <-chan *asset.Snapshot) *helper.Report

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

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

NewObvStrategy initializes an example ObvStrategy instance with default parameters.

func NewObvStrategyWith(period int) *ObvStrategy

NewObvStrategyWith initializes an example ObvStrategyWith instance with default parameters.

func (*ObvStrategy) Compute

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

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

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

func (*ObvStrategy) Name

func (s *ObvStrategy) Name() string

Name function returns the name of the strategy.

func (*ObvStrategy) Report

func (s *ObvStrategy) Report(snapshots <-chan *asset.Snapshot) *helper.Report

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

NewPercentBandMFIStrategy initializes an example PercentBandMFIStrategy instance with default parameters.

func NewPercentBandMFIStrategyWith(sellPercentBAt, buyPercentBAt, sellMfiAt, buyMfiAt float64) *PercentBandMFIStrategy

NewPercentBandMFIStrategyWith initializes an example PercentBandMFIStrategyWith instance with default parameters. given parameters.

func (*PercentBandMFIStrategy) Compute

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

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

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

func (*PercentBandMFIStrategy) Name

func (m *PercentBandMFIStrategy) Name() string

Name returns the name of the example strategy.

func (*PercentBandMFIStrategy) Report

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

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

NewWeightedAveragePriceStrategy initializes an example WeightedAveragePriceStrategy instance with default parameters. instance with the default parameters.

func NewWeightedAveragePriceStrategyWith(period int) *WeightedAveragePriceStrategy

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

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

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

func (*WeightedAveragePriceStrategy) Name

func (v *WeightedAveragePriceStrategy) Name() string

Name returns the name of the example strategy.

func (*WeightedAveragePriceStrategy) Report

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

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

Generated by gomarkdoc