import "github.com/cinar/indicator/v2/volume"
Package volume contains the volume indicator 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.
Copyright (c) 2021-2024 Onur Cinar.
The source code is provided under GNU AGPLv3 License.
https://github.com/cinar/indicator
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.
- Constants
- type Ad
- type Cmf
- type Emv
- type Fi
- type Mfi
- type Mfm
- type Mfv
- type Nvi
- type Obv
- type Vpt
- type Vwap
const (
// DefaultCmfPeriod is the default period of CMF.
DefaultCmfPeriod = 20
)
const (
// DefaultEmvPeriod is the default period for the EMV.
DefaultEmvPeriod = 14
)
const (
// DefaultFiPeriod is the default period for the FI.
DefaultFiPeriod = 13
)
const (
// DefaultMfiPeriod is the default period of the MFI.
DefaultMfiPeriod = 14
)
const (
// DefaultNviInitial is the default initial for the NVI.
DefaultNviInitial = 1000
)
const (
// DefaultVwapPeriod is the default period for the VWAP.
DefaultVwapPeriod = 14
)
type Ad
Ad holds configuration parameters for calculating Accumulation/Distribution (A/D). It is a cumulative indicator that uses volume and price to assess whether an asset is being accumulated or distributed.
MFM = ((Closing - Low) - (High - Closing)) / (High - Low)
MFV = MFM * Period Volume
AD = Previous AD + CMFV
Example:
ad := volume.NewAd[float64]()
result := ad.Compute(highs, lows, closings, volumes)
type Ad[T helper.Number] struct {
// Mfv is the MFV instance.
Mfv *Mfv[T]
}
func NewAd
func NewAd[T helper.Number]() *Ad[T]
NewAd function initializes a new A/D instance with the default parameters.
func (*Ad[T]) Compute
func (a *Ad[T]) Compute(highs, lows, closings, volumes <-chan T) <-chan T
Compute function takes a channel of numbers and computes the A/D.
func (*Ad[T]) IdlePeriod
func (*Ad[T]) IdlePeriod() int
IdlePeriod is the initial period that A/D won't yield any results.
type Cmf
Cmf holds configuration parameters for calculating the Chaikin Money Flow (CMF). It measures the amount of money flow volume over a given period.
MFM = ((Closing - Low) - (High - Closing)) / (High - Low)
MFV = MFM * Volume
CMF = Sum(20, Money Flow Volume) / Sum(20, Volume)
Example:
cmf := volume.NewCmf[float64]()
result := cmf.Compute(highs, lows, closings, volumes)
type Cmf[T helper.Number] struct {
// Mfv is the MFV instance.
Mfv *Mfv[T]
// Sum is the Moving Sum instance.
Sum *trend.MovingSum[T]
}
func NewCmf
func NewCmf[T helper.Number]() *Cmf[T]
NewCmf function initializes a new CMF instance with the default parameters.
func NewCmfWithPeriod
func NewCmfWithPeriod[T helper.Number](period int) *Cmf[T]
NewCmfWithPeriod function initializes a new CMF instance with the given period.
func (*Cmf[T]) Compute
func (c *Cmf[T]) Compute(highs, lows, closings, volumes <-chan T) <-chan T
Compute function takes a channel of numbers and computes the CMF.
func (*Cmf[T]) IdlePeriod
func (c *Cmf[T]) IdlePeriod() int
IdlePeriod is the initial period that MFV won't yield any results.
type Emv
Emv holds configuration parameters for calculating the Ease of Movement (EMV). It is a volume based oscillator measuring the ease of price movement.
Distance Moved = ((High + Low) / 2) - ((Priod High + Prior Low) /2)
Box Ratio = ((Volume / 100000000) / (High - Low))
EMV(1) = Distance Moved / Box Ratio
EMV(14) = SMA(14, EMV(1))
Example:
emv := volume.NewEmv[float64]()
result := emv.Compute(highs, lows, volumes)
type Emv[T helper.Number] struct {
// Sma is the SMA instance.
Sma *trend.Sma[T]
}
func NewEmv
func NewEmv[T helper.Number]() *Emv[T]
NewEmv function initializes a new EMV instance with the default parameters.
func NewEmvWithPeriod
func NewEmvWithPeriod[T helper.Number](period int) *Emv[T]
NewEmvWithPeriod function initializes a new EMV instance with the given period.
func (*Emv[T]) Compute
func (e *Emv[T]) Compute(highs, lows, volumes <-chan T) <-chan T
Compute function takes a channel of numbers and computes the EMV.
func (*Emv[T]) IdlePeriod
func (e *Emv[T]) IdlePeriod() int
IdlePeriod is the initial period that EMV won't yield any results.
type Fi
Fi holds configuration parameters for calculating the Force Index (FI). It uses the closing price and the volume to assess the power behind a move and identify turning points.
FI = EMA(period, (Current - Previous) * Volume)
Example:
fi := volume.NewFi[float64]()
result := fi.Compute(closings, volumes)
type Fi[T helper.Number] struct {
// Ema is the EMA instance.
Ema *trend.Ema[T]
}
func NewFi
func NewFi[T helper.Number]() *Fi[T]
NewFi function initializes a new FI instance with the default parameters.
func NewFiWithPeriod
func NewFiWithPeriod[T helper.Number](period int) *Fi[T]
NewFiWithPeriod function initializes a new FI instance with the given period.
func (*Fi[T]) Compute
func (f *Fi[T]) Compute(closings, volumes <-chan T) <-chan T
Compute function takes a channel of numbers and computes the FI.
func (*Fi[T]) IdlePeriod
func (f *Fi[T]) IdlePeriod() int
IdlePeriod is the initial period that FI won't yield any results.
type Mfi
Mfi holds configuration parameters for calculating the Money Flow Index (MFI). It analyzes both the closing price and the volume to measure to identify overbought and oversold states. It is similar to the Relative Strength Index (RSI), but it also uses the volume.
Raw Money Flow = Typical Price * Volume
Money Ratio = Positive Money Flow / Negative Money Flow
Money Flow Index = 100 - (100 / (1 + Money Ratio))
Example:
mfi := volume.NewMfi[float64]()
result := mfi.Compute(highs, lows, closings, volumes)
type Mfi[T helper.Number] struct {
// TypicalPrice is the Typical Price instance.
TypicalPrice *trend.TypicalPrice[T]
// Sum is the Moving Sum instance.
Sum *trend.MovingSum[T]
}
func NewMfi
func NewMfi[T helper.Number]() *Mfi[T]
NewMfi function initializes a new MFI instance with the default parameters.
func (*Mfi[T]) Compute
func (m *Mfi[T]) Compute(highs, lows, closings, volumes <-chan T) <-chan T
Compute function takes a channel of numbers and computes the MFI.
func (*Mfi[T]) IdlePeriod
func (m *Mfi[T]) IdlePeriod() int
IdlePeriod is the initial period that MFI won't yield any results.
type Mfm
Mfm holds configuration parameters for calculating the Money Flow Multiplier (MFM), which adjusts volume based on the closing price's position within the high-low range:
MFM = ((Closing - Low) - (High - Closing)) / (High - Low)
- Positive MFM: Close in upper half of range, indicating buying pressure. - Negative MFM: Close in lower half of range, indicating selling pressure. - MFM of 1: Close equals high, strongest buying pressure. - MFM of -1: Close equals low, strongest selling pressure.
Example:
mfm := volume.NewMfm[float64]()
result := mfm.Compute(highs, lows, closings)
type Mfm[T helper.Number] struct{}
func NewMfm
func NewMfm[T helper.Number]() *Mfm[T]
NewMfm function initializes a new MFM instance with the default parameters.
func (*Mfm[T]) Compute
func (*Mfm[T]) Compute(highs, lows, closings <-chan T) <-chan T
Compute function takes a channel of numbers and computes the MFM.
func (*Mfm[T]) IdlePeriod
func (*Mfm[T]) IdlePeriod() int
IdlePeriod is the initial period that MFM won't yield any results.
type Mfv
Mfv holds configuration parameters for calculating Money Flow Volume (MFV), a volume-based indicator that incorporates the Money Flow Multiplier (MFM) to gauge the intensity of buying and selling pressure. MFV reflects the cumulative volume adjusted by MFM, with higher values indicating stronger buying pressure and lower values suggesting selling dominance. MFV highlights periods of significant volume-driven price action, offering insights into potential trend strength and reversals.
MFV = MFM * Volume
Example:
mfv := volume.NewMfv[float64]()
result := mfv.Compute(highs, lows, closings, volumes)
type Mfv[T helper.Number] struct {
// Mfm is the MFM instance.
Mfm *Mfm[T]
}
func NewMfv
func NewMfv[T helper.Number]() *Mfv[T]
NewMfv function initializes a new MFV instance with the default parameters.
func (*Mfv[T]) Compute
func (m *Mfv[T]) Compute(highs, lows, closings, volumes <-chan T) <-chan T
Compute function takes a channel of numbers and computes the MFV.
func (*Mfv[T]) IdlePeriod
func (*Mfv[T]) IdlePeriod() int
IdlePeriod is the initial period that MFV won't yield any results.
type Nvi
Nvi holds configuration parameters for calculating the Negative Volume Index (NVI). It is a cumulative indicator using the change in volume to decide when the smart money is active.
If Volume is greather than Previous Volume:
NVI = Previous NVI
Otherwise:
NVI = Previous NVI + (((Closing - Previous Closing) / Previous Closing) * Previous NVI)
Example:
nvi := volume.NewNvi[float64]()
result := nvi.Compute(closings, volumes)
type Nvi[T helper.Number] struct {
// Initial is the initial NVI value.
Initial T
}
func NewNvi
func NewNvi[T helper.Number]() *Nvi[T]
NewNvi function initializes a new NVI instance with the default parameters.
func (*Nvi[T]) Compute
func (n *Nvi[T]) Compute(closings, volumes <-chan T) <-chan T
Compute function takes a channel of numbers and computes the NVI.
func (*Nvi[T]) IdlePeriod
func (*Nvi[T]) IdlePeriod() int
IdlePeriod is the initial period that NVI won't yield any results.
type Obv
Obv holds configuration parameters for calculating the On-Balance Volume (OBV). It is a technical trading momentum indicator that uses volume flow to predict changes in asset price.
Foreach Closing:
If Closing[i] > Closing[i-1], OBV[i] = OBV[i-1] + Volume[i]
If Closing[i] = Closing[i-1], OBV[i] = OBV[i-1]
If Closing[i] < Closing[i-1], OBV[i] = OBV[i-1] - Volume[i]
Example:
obv := volume.NewObv[float64]()
result := obv.Compute(closings, volumes)
type Obv[T helper.Number] struct{}
func NewObv
func NewObv[T helper.Number]() *Obv[T]
NewObv function initializes a new OBV instance with the default parameters.
func (*Obv[T]) Compute
func (*Obv[T]) Compute(closings, volumes <-chan T) <-chan T
Compute function takes a channel of numbers and computes the OBV.
func (*Obv[T]) IdlePeriod
func (*Obv[T]) IdlePeriod() int
IdlePeriod is the initial period that OBV won't yield any results.
type Vpt
Vpt holds configuration parameters for calculating the Volume Price Trend (VPT). It provides a correlation between the volume and the price.
VPT = Previous VPT + (Volume * (Current Closing - Previous Closing) / Previous Closing)
Example:
vpt := volume.NewVpt[float64]()
result := vpt.Compute(closings, volumes)
type Vpt[T helper.Number] struct{}
func NewVpt
func NewVpt[T helper.Number]() *Vpt[T]
NewVpt function initializes a new VPT instance with the default parameters.
func (*Vpt[T]) Compute
func (*Vpt[T]) Compute(closings, volumes <-chan T) <-chan T
Compute function takes a channel of numbers and computes the VPT.
func (*Vpt[T]) IdlePeriod
func (*Vpt[T]) IdlePeriod() int
IdlePeriod is the initial period that VPT won't yield any results.
type Vwap
Vwap holds configuration parameters for calculating the Volume Weighted Average Price (VWAP). It provides the average price the asset has traded.
VWAP = Sum(Closing * Volume) / Sum(Volume)
Example:
vwap := volume.NewVwap[float64]()
result := vwap.Compute(closings, volumes)
type Vwap[T helper.Number] struct {
// Sum is the Moving Sum instance.
Sum *trend.MovingSum[T]
}
func NewVwap
func NewVwap[T helper.Number]() *Vwap[T]
NewVwap function initializes a new VWAP instance with the default parameters.
func NewVwapWithPeriod
func NewVwapWithPeriod[T helper.Number](period int) *Vwap[T]
NewVwapWithPeriod function initializes a new VWAP instance with the given period.
func (*Vwap[T]) Compute
func (v *Vwap[T]) Compute(closings, volumes <-chan T) <-chan T
Compute function takes a channel of numbers and computes the VWAP.
func (*Vwap[T]) IdlePeriod
func (v *Vwap[T]) IdlePeriod() int
IdlePeriod is the initial period that VWAP won't yield any results.
Generated by gomarkdoc