Documentation
¶
Overview ¶
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.
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 ¶
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
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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)
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 ¶
IdlePeriod is the initial period that A/D won't yield any results.
type Cmf ¶
type Cmf[T helper.Number] struct { // Mfv is the MFV instance. Mfv *Mfv[T] // Sum is the Moving Sum instance. Sum *trend.MovingSum[T] }
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)
func NewCmfWithPeriod ¶
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 ¶
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)
func NewEmvWithPeriod ¶
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 ¶
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)
func NewFiWithPeriod ¶
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 ¶
IdlePeriod is the initial period that FI won't yield any results.
type Mfi ¶
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] }
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)
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 ¶
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)
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 ¶
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)
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 ¶
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)
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 ¶
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)
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 ¶
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)
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 ¶
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)
func NewVwapWithPeriod ¶
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 ¶
IdlePeriod is the initial period that VWAP won't yield any results.