indicator

package
v0.0.0-...-cb4139d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 15, 2023 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const DPeriod int = 3
View Source
const DefaultEMVScale float64 = 100000000.
View Source
const MaxNumOfALMA = 5_000
View Source
const MaxNumOfALMATruncateSize = 100
View Source
const MaxNumOfATR = 1000
View Source
const MaxNumOfATRTruncateSize = 500
View Source
const MaxNumOfEWMA = 1_000

These numbers should be aligned with bbgo MaxNumOfKLines and MaxNumOfKLinesTruncate

View Source
const MaxNumOfEWMATruncateSize = 500
View Source
const MaxNumOfKLines = 4_000
View Source
const MaxNumOfRMA = 1000
View Source
const MaxNumOfRMATruncateSize = 500
View Source
const MaxNumOfSMA = 5_000
View Source
const MaxNumOfSMATruncateSize = 100
View Source
const MaxNumOfStdev = 600
View Source
const MaxNumOfStdevTruncateSize = 300
View Source
const MaxNumOfVOL = 5_000
View Source
const MaxNumOfVOLTruncateSize = 100
View Source
const MaxNumOfWWMA = 5_000
View Source
const MaxNumOfWWMATruncateSize = 100

Variables

This section is empty.

Functions

func CalculateKLinesEMA

func CalculateKLinesEMA(allKLines []types.KLine, priceF KLineValueMapper, window int) float64

func KLineClosePriceMapper

func KLineClosePriceMapper(k types.KLine) float64

func KLineHighPriceMapper

func KLineHighPriceMapper(k types.KLine) float64

func KLineLowPriceMapper

func KLineLowPriceMapper(k types.KLine) float64

func KLineOpenPriceMapper

func KLineOpenPriceMapper(k types.KLine) float64

func KLinePriceVolumeMapper

func KLinePriceVolumeMapper(k types.KLine) float64

func KLineTypicalPriceMapper

func KLineTypicalPriceMapper(k types.KLine) float64

func KLineVolumeMapper

func KLineVolumeMapper(k types.KLine) float64

func MapKLinePrice

func MapKLinePrice(kLines []types.KLine, f KLineValueMapper) (prices []float64)

Types

type AD struct {
	types.SeriesBase
	types.IntervalWindow
	Values   floats.Slice
	PrePrice float64

	EndTime         time.Time
	UpdateCallbacks []func(value float64)
}

ad implements accumulation/distribution indicator

Accumulation/Distribution Indicator (A/D) - https://www.investopedia.com/terms/a/accumulationdistribution.asp

func (*AD) CalculateAndUpdate

func (inc *AD) CalculateAndUpdate(kLines []types.KLine)

func (*AD) EmitUpdate

func (inc *AD) EmitUpdate(value float64)

func (*AD) Index

func (inc *AD) Index(i int) float64

func (*AD) Last

func (inc *AD) Last(i int) float64

func (*AD) Length

func (inc *AD) Length() int

func (*AD) OnUpdate

func (inc *AD) OnUpdate(cb func(value float64))

func (*AD) Update

func (inc *AD) Update(high, low, cloze, volume float64)

type ALMA

type ALMA struct {
	types.SeriesBase
	types.IntervalWindow         // required
	Offset               float64 // required: recommend to be 0.5
	Sigma                int     // required: recommend to be 5

	Values          floats.Slice
	UpdateCallbacks []func(value float64)
	// contains filtered or unexported fields
}

Refer: Arnaud Legoux Moving Average Refer: https://capital.com/arnaud-legoux-moving-average Also check https://github.com/DaveSkender/Stock.Indicators/blob/main/src/a-d/Alma/Alma.cs

The Arnaud Legoux Moving Average (ALMA) is a technical analysis indicator that is used to smooth price data and reduce the lag associated with traditional moving averages. It was developed by Arnaud Legoux and is based on the weighted moving average, with the weighting factors determined using a Gaussian function. The ALMA is calculated by taking the weighted moving average of the input data using weighting factors that are based on the standard deviation of the data and the specified length of the moving average. This resulting average is then plotted on the price chart as a line, which can be used to make predictions about future price movements. The ALMA is typically more responsive to changes in the underlying data than a simple moving average, but may be less reliable in trending markets.

@param offset: Gaussian applied to the combo line. 1->ema, 0->sma @param sigma: the standard deviation applied to the combo line. This makes the combo line sharper

func (*ALMA) CalculateAndUpdate

func (inc *ALMA) CalculateAndUpdate(allKLines []types.KLine)

func (*ALMA) EmitUpdate

func (inc *ALMA) EmitUpdate(value float64)

func (*ALMA) Index

func (inc *ALMA) Index(i int) float64

func (*ALMA) Last

func (inc *ALMA) Last(i int) float64

func (*ALMA) Length

func (inc *ALMA) Length() int

func (*ALMA) OnUpdate

func (inc *ALMA) OnUpdate(cb func(value float64))

func (*ALMA) Update

func (inc *ALMA) Update(value float64)

type ATR

type ATR struct {
	types.SeriesBase
	types.IntervalWindow
	PercentageVolatility floats.Slice

	PreviousClose float64
	RMA           *RMA

	EndTime         time.Time
	UpdateCallbacks []func(value float64)
}

func (*ATR) Clone

func (inc *ATR) Clone() *ATR

func (*ATR) EmitUpdate

func (inc *ATR) EmitUpdate(value float64)

func (*ATR) Index

func (inc *ATR) Index(i int) float64

func (*ATR) Last

func (inc *ATR) Last(i int) float64

func (*ATR) Length

func (inc *ATR) Length() int

func (*ATR) OnUpdate

func (inc *ATR) OnUpdate(cb func(value float64))

func (*ATR) PushK

func (inc *ATR) PushK(k types.KLine)

func (*ATR) TestUpdate

func (inc *ATR) TestUpdate(high, low, cloze float64) *ATR

func (*ATR) Update

func (inc *ATR) Update(high, low, cloze float64)

type ATRP

type ATRP struct {
	types.SeriesBase
	types.IntervalWindow
	PercentageVolatility floats.Slice

	PreviousClose float64
	RMA           *RMA

	EndTime         time.Time
	UpdateCallbacks []func(value float64)
}

ATRP is the average true range percentage See also https://www.fidelity.com/learning-center/trading-investing/technical-analysis/technical-indicator-guide/atrp

The Average True Range Percentage (ATRP) is a technical analysis indicator that measures the volatility of a security's price. It is calculated by dividing the Average True Range (ATR) of the security by its closing price, and then multiplying the result by 100 to convert it to a percentage. The ATR is a measure of the range of a security's price, taking into account gaps between trading periods and any limit moves (sharp price movements that are allowed under certain exchange rules). The ATR is typically smoothed using a moving average to make it more responsive to changes in the underlying price data. The ATRP is a useful indicator for traders because it provides a way to compare the volatility of different securities, regardless of their individual prices. It can also be used to identify potential entry and exit points for trades based on changes in the security's volatility.

Calculation:

ATRP = (Average True Range / Close) * 100

func (*ATRP) Bind

func (inc *ATRP) Bind(updater KLineWindowUpdater)

func (*ATRP) CalculateAndUpdate

func (inc *ATRP) CalculateAndUpdate(kLines []types.KLine)

func (*ATRP) EmitUpdate

func (inc *ATRP) EmitUpdate(value float64)

func (*ATRP) Index

func (inc *ATRP) Index(i int) float64

func (*ATRP) Last

func (inc *ATRP) Last(i int) float64

func (*ATRP) Length

func (inc *ATRP) Length() int

func (*ATRP) OnUpdate

func (inc *ATRP) OnUpdate(cb func(value float64))

func (*ATRP) PushK

func (inc *ATRP) PushK(k types.KLine)

func (*ATRP) Update

func (inc *ATRP) Update(high, low, cloze float64)

type ATRPStream

type ATRPStream struct {
	*Float64Series
}

func ATRP2

func ATRP2(source KLineSubscription, window int) *ATRPStream

type ATRStream

type ATRStream struct {
	// embedded struct
	*RMAStream
}

func ATR2

func ATR2(source KLineSubscription, window int) *ATRStream

type BOLL

type BOLL struct {
	types.IntervalWindow

	// K is the multiplier of Std, generally it's 2
	K float64

	SMA    *SMA
	StdDev *StdDev

	UpBand   floats.Slice
	DownBand floats.Slice

	EndTime time.Time
	// contains filtered or unexported fields
}

func (*BOLL) Bind

func (inc *BOLL) Bind(updater KLineWindowUpdater)

func (*BOLL) BindK

func (inc *BOLL) BindK(target KLineClosedEmitter, symbol string, interval types.Interval)

func (*BOLL) CalculateAndUpdate

func (inc *BOLL) CalculateAndUpdate(allKLines []types.KLine)

func (*BOLL) EmitUpdate

func (inc *BOLL) EmitUpdate(sma float64, upBand float64, downBand float64)

func (*BOLL) GetDownBand

func (inc *BOLL) GetDownBand() types.SeriesExtend

func (*BOLL) GetSMA

func (inc *BOLL) GetSMA() types.SeriesExtend

func (*BOLL) GetStdDev

func (inc *BOLL) GetStdDev() types.SeriesExtend

func (*BOLL) GetUpBand

func (inc *BOLL) GetUpBand() types.SeriesExtend

func (*BOLL) LastDownBand

func (inc *BOLL) LastDownBand() float64

func (*BOLL) LastUpBand

func (inc *BOLL) LastUpBand() float64

func (*BOLL) LoadK

func (inc *BOLL) LoadK(allKLines []types.KLine)

func (*BOLL) OnUpdate

func (inc *BOLL) OnUpdate(cb func(sma float64, upBand float64, downBand float64))

func (*BOLL) PushK

func (inc *BOLL) PushK(k types.KLine)

func (*BOLL) Update

func (inc *BOLL) Update(value float64)

type BOLLStream

type BOLLStream struct {
	// the band series
	*Float64Series

	UpBand, DownBand *Float64Series

	SMA    *SMAStream
	StdDev *StdDevStream
	// contains filtered or unexported fields
}

func BOLL2

func BOLL2(source Float64Source, window int, k float64) *BOLLStream

BOOL2 is bollinger indicator the data flow:

priceSource ->

-> calculate SMA
-> calculate stdDev -> calculate bandWidth -> get latest SMA -> upBand, downBand

func (*BOLLStream) Calculate

func (s *BOLLStream) Calculate(v float64) float64

type BandType

type BandType int

type CA

type CA struct {
	types.SeriesBase
	Interval types.Interval
	Values   floats.Slice
	// contains filtered or unexported fields
}

Refer: Cumulative Moving Average, Cumulative Average Refer: https://en.wikipedia.org/wiki/Moving_average

func (*CA) CalculateAndUpdate

func (inc *CA) CalculateAndUpdate(allKLines []types.KLine)

func (*CA) EmitUpdate

func (inc *CA) EmitUpdate(value float64)

func (*CA) Index

func (inc *CA) Index(i int) float64

func (*CA) Last

func (inc *CA) Last(i int) float64

func (*CA) Length

func (inc *CA) Length() int

func (*CA) OnUpdate

func (inc *CA) OnUpdate(cb func(value float64))

func (*CA) PushK

func (inc *CA) PushK(k types.KLine)

func (*CA) Update

func (inc *CA) Update(x float64)

type CCI

type CCI struct {
	types.SeriesBase
	types.IntervalWindow
	Input        floats.Slice
	TypicalPrice floats.Slice
	MA           floats.Slice
	Values       floats.Slice

	UpdateCallbacks []func(value float64)
}

func (*CCI) CalculateAndUpdate

func (inc *CCI) CalculateAndUpdate(allKLines []types.KLine)

func (*CCI) EmitUpdate

func (inc *CCI) EmitUpdate(value float64)

func (*CCI) Index

func (inc *CCI) Index(i int) float64

func (*CCI) Last

func (inc *CCI) Last(i int) float64

func (*CCI) Length

func (inc *CCI) Length() int

func (*CCI) OnUpdate

func (inc *CCI) OnUpdate(cb func(value float64))

func (*CCI) PushK

func (inc *CCI) PushK(k types.KLine)

func (*CCI) Update

func (inc *CCI) Update(value float64)

type CMAStream

type CMAStream struct {
	*Float64Series
}

func CMA2

func CMA2(source Float64Source) *CMAStream

func (*CMAStream) Calculate

func (s *CMAStream) Calculate(x float64) float64

func (*CMAStream) Truncate

func (s *CMAStream) Truncate()

type CrossStream

type CrossStream struct {
	*Float64Series
	// contains filtered or unexported fields
}

CrossStream subscribes 2 upstreams, and calculate the cross signal

func Cross

func Cross(a, b Float64Source) *CrossStream

Cross creates the CrossStream object:

cross := Cross(fastEWMA, slowEWMA)

type CrossType

type CrossType float64
const (
	CrossOver  CrossType = 1.0
	CrossUnder CrossType = -1.0
)

type DEMA

type DEMA struct {
	types.IntervalWindow
	types.SeriesBase
	Values floats.Slice

	UpdateCallbacks []func(value float64)
	// contains filtered or unexported fields
}

func (*DEMA) Bind

func (inc *DEMA) Bind(updater KLineWindowUpdater)

func (*DEMA) CalculateAndUpdate

func (inc *DEMA) CalculateAndUpdate(allKLines []types.KLine)

func (*DEMA) Clone

func (inc *DEMA) Clone() *DEMA

func (*DEMA) EmitUpdate

func (inc *DEMA) EmitUpdate(value float64)

func (*DEMA) Index

func (inc *DEMA) Index(i int) float64

func (*DEMA) Last

func (inc *DEMA) Last(i int) float64

func (*DEMA) Length

func (inc *DEMA) Length() int

func (*DEMA) OnUpdate

func (inc *DEMA) OnUpdate(cb func(value float64))

func (*DEMA) PushK

func (inc *DEMA) PushK(k types.KLine)

func (*DEMA) TestUpdate

func (inc *DEMA) TestUpdate(value float64) *DEMA

func (*DEMA) Update

func (inc *DEMA) Update(value float64)

type DMI

type DMI struct {
	types.IntervalWindow

	ADXSmoothing int

	DMP               types.UpdatableSeriesExtend
	DMN               types.UpdatableSeriesExtend
	DIPlus            *types.Queue
	DIMinus           *types.Queue
	ADX               types.UpdatableSeriesExtend
	PrevHigh, PrevLow float64
	// contains filtered or unexported fields
}

func (*DMI) CalculateAndUpdate

func (inc *DMI) CalculateAndUpdate(allKLines []types.KLine)

func (*DMI) EmitUpdate

func (inc *DMI) EmitUpdate(diplus float64, diminus float64, adx float64)

func (*DMI) GetADX

func (inc *DMI) GetADX() types.SeriesExtend

func (*DMI) GetDIMinus

func (inc *DMI) GetDIMinus() types.SeriesExtend

func (*DMI) GetDIPlus

func (inc *DMI) GetDIPlus() types.SeriesExtend

func (*DMI) Length

func (inc *DMI) Length() int

func (*DMI) OnUpdate

func (inc *DMI) OnUpdate(cb func(diplus float64, diminus float64, adx float64))

func (*DMI) PushK

func (inc *DMI) PushK(k types.KLine)

func (*DMI) Update

func (inc *DMI) Update(high, low, cloze float64)

type Drift

type Drift struct {
	types.SeriesBase
	types.IntervalWindow

	Values    floats.Slice
	MA        types.UpdatableSeriesExtend
	LastValue float64

	UpdateCallbacks []func(value float64)
	// contains filtered or unexported fields
}

func (*Drift) Bind

func (inc *Drift) Bind(updater KLineWindowUpdater)

func (*Drift) CalculateAndUpdate

func (inc *Drift) CalculateAndUpdate(allKLines []types.KLine)

func (*Drift) Clone

func (inc *Drift) Clone() (out *Drift)

func (*Drift) EmitUpdate

func (inc *Drift) EmitUpdate(value float64)

func (*Drift) Index

func (inc *Drift) Index(i int) float64

func (*Drift) Last

func (inc *Drift) Last(i int) float64

func (*Drift) Length

func (inc *Drift) Length() int

func (*Drift) OnUpdate

func (inc *Drift) OnUpdate(cb func(value float64))

func (*Drift) PushK

func (inc *Drift) PushK(k types.KLine)

func (*Drift) TestUpdate

func (inc *Drift) TestUpdate(value float64) *Drift

func (*Drift) Update

func (inc *Drift) Update(value float64)

func (*Drift) ZeroPoint

func (inc *Drift) ZeroPoint() float64

Assume that MA is SMA

type EMV

type EMV struct {
	types.SeriesBase
	types.IntervalWindow

	Values   *SMA
	EMVScale float64

	UpdateCallbacks []func(value float64)
	// contains filtered or unexported fields
}

func (*EMV) EmitUpdate

func (inc *EMV) EmitUpdate(value float64)

func (*EMV) Index

func (inc *EMV) Index(i int) float64

func (*EMV) Last

func (inc *EMV) Last(i int) float64

func (*EMV) Length

func (inc *EMV) Length() int

func (*EMV) OnUpdate

func (inc *EMV) OnUpdate(cb func(value float64))

func (*EMV) PushK

func (inc *EMV) PushK(k types.KLine)

func (*EMV) Update

func (inc *EMV) Update(high, low, vol float64)

type EWMA

type EWMA struct {
	types.IntervalWindow
	types.SeriesBase

	Values  floats.Slice
	EndTime time.Time
	// contains filtered or unexported fields
}

func (*EWMA) Clone

func (inc *EWMA) Clone() *EWMA

func (*EWMA) EmitUpdate

func (inc *EWMA) EmitUpdate(value float64)

func (*EWMA) Index

func (inc *EWMA) Index(i int) float64

func (*EWMA) Last

func (inc *EWMA) Last(i int) float64

func (*EWMA) Length

func (inc *EWMA) Length() int

func (*EWMA) OnUpdate

func (inc *EWMA) OnUpdate(cb func(value float64))

func (*EWMA) PushK

func (inc *EWMA) PushK(k types.KLine)

func (*EWMA) TestUpdate

func (inc *EWMA) TestUpdate(value float64) *EWMA

func (*EWMA) Update

func (inc *EWMA) Update(value float64)

type EWMAStream

type EWMAStream struct {
	*Float64Series
	// contains filtered or unexported fields
}

func EWMA2

func EWMA2(source Float64Source, window int) *EWMAStream

func (*EWMAStream) Calculate

func (s *EWMAStream) Calculate(v float64) float64

type FisherTransform

type FisherTransform struct {
	types.SeriesBase
	types.IntervalWindow

	Values floats.Slice

	UpdateCallbacks []func(value float64)
	// contains filtered or unexported fields
}

Fisher Transform

The Fisher Transform is a technical analysis indicator that is used to identify potential turning points in the price of a security. It is based on the idea that prices tend to be normally distributed, with most price movements being small and relatively insignificant. The Fisher Transform converts this normal distribution into a symmetrical, Gaussian distribution, with a peak at zero and a range of -1 to +1. This transformation allows for more accurate identification of price extremes, which can be used to make predictions about potential trend reversals. The Fisher Transform is calculated by taking the natural logarithm of the ratio of the security's current price to its moving average, and then double-smoothing the result. This resulting line is called the Fisher Transform line, and can be plotted on the price chart along with the security's price.

func (*FisherTransform) Clone

func (*FisherTransform) EmitUpdate

func (inc *FisherTransform) EmitUpdate(value float64)

func (*FisherTransform) Index

func (inc *FisherTransform) Index(i int) float64

func (*FisherTransform) Last

func (inc *FisherTransform) Last(i int) float64

func (*FisherTransform) Length

func (inc *FisherTransform) Length() int

func (*FisherTransform) OnUpdate

func (inc *FisherTransform) OnUpdate(cb func(value float64))

func (*FisherTransform) Update

func (inc *FisherTransform) Update(value float64)

type Float64Calculator

type Float64Calculator interface {
	Calculate(x float64) float64
	PushAndEmit(x float64)
}

type Float64Series

type Float64Series struct {
	types.SeriesBase
	Float64Updater
	// contains filtered or unexported fields
}

func NewFloat64Series

func NewFloat64Series(v ...float64) *Float64Series

func (*Float64Series) Bind

func (f *Float64Series) Bind(source Float64Source, target Float64Calculator)

Bind binds the source event to the target (Float64Calculator) A Float64Calculator should be able to calculate the float64 result from a single float64 argument input

func (*Float64Series) Index

func (f *Float64Series) Index(i int) float64

func (*Float64Series) Last

func (f *Float64Series) Last(i int) float64

func (*Float64Series) Length

func (f *Float64Series) Length() int

func (*Float64Series) PushAndEmit

func (f *Float64Series) PushAndEmit(x float64)

func (*Float64Series) Slice

func (f *Float64Series) Slice() floats.Slice

func (*Float64Series) Subscribe

func (f *Float64Series) Subscribe(source Float64Source, c func(x float64))

type Float64Source

type Float64Source interface {
	types.Series
	OnUpdate(f func(v float64))
}

type Float64Subscription

type Float64Subscription interface {
	types.Series
	AddSubscriber(f func(v float64))
}

type Float64Truncator

type Float64Truncator interface {
	Truncate()
}

type Float64Updater

type Float64Updater struct {
	// contains filtered or unexported fields
}

func (*Float64Updater) EmitUpdate

func (f *Float64Updater) EmitUpdate(v float64)

func (*Float64Updater) OnUpdate

func (f *Float64Updater) OnUpdate(cb func(v float64))

type GHFilter

type GHFilter struct {
	types.SeriesBase
	types.IntervalWindow

	Values floats.Slice

	UpdateCallbacks []func(value float64)
	// contains filtered or unexported fields
}

func (*GHFilter) EmitUpdate

func (inc *GHFilter) EmitUpdate(value float64)

func (*GHFilter) Index

func (inc *GHFilter) Index(i int) float64

func (*GHFilter) Last

func (inc *GHFilter) Last(i int) float64

func (*GHFilter) Length

func (inc *GHFilter) Length() int

func (*GHFilter) OnUpdate

func (inc *GHFilter) OnUpdate(cb func(value float64))

func (*GHFilter) PushK

func (inc *GHFilter) PushK(k types.KLine)

func (*GHFilter) Update

func (inc *GHFilter) Update(value float64)

type GMA

type GMA struct {
	types.SeriesBase
	types.IntervalWindow
	SMA             *SMA
	UpdateCallbacks []func(value float64)
}

func (*GMA) BindK

func (inc *GMA) BindK(target KLineClosedEmitter, symbol string, interval types.Interval)

func (*GMA) Clone

func (inc *GMA) Clone() (out *GMA)

func (*GMA) EmitUpdate

func (inc *GMA) EmitUpdate(value float64)

func (*GMA) Index

func (inc *GMA) Index(i int) float64

func (*GMA) Last

func (inc *GMA) Last(i int) float64

func (*GMA) Length

func (inc *GMA) Length() int

func (*GMA) LoadK

func (inc *GMA) LoadK(allKLines []types.KLine)

func (*GMA) OnUpdate

func (inc *GMA) OnUpdate(cb func(value float64))

func (*GMA) PushK

func (inc *GMA) PushK(k types.KLine)

func (*GMA) TestUpdate

func (inc *GMA) TestUpdate(value float64) *GMA

func (*GMA) Update

func (inc *GMA) Update(value float64)

type HULL

type HULL struct {
	types.SeriesBase
	types.IntervalWindow
	// contains filtered or unexported fields
}

Refer: Hull Moving Average Refer URL: https://fidelity.com/learning-center/trading-investing/technical-analysis/technical-indicator-guide/hull-moving-average

The Hull Moving Average (HMA) is a technical analysis indicator that uses a weighted moving average to reduce the lag in simple moving averages. It was developed by Alan Hull, who sought to create a moving average that was both fast and smooth. The HMA is calculated by first taking the weighted moving average of the input data using a weighting factor of W, where W is the square root of the length of the moving average. The result is then double-smoothed by taking the weighted moving average of this result using a weighting factor of W/2. This final average forms the HMA line, which can be used to make predictions about future price movements.

func (*HULL) EmitUpdate

func (inc *HULL) EmitUpdate(value float64)

func (*HULL) Index

func (inc *HULL) Index(i int) float64

func (*HULL) Last

func (inc *HULL) Last(i int) float64

func (*HULL) Length

func (inc *HULL) Length() int

func (*HULL) OnUpdate

func (inc *HULL) OnUpdate(cb func(value float64))

func (*HULL) PushK

func (inc *HULL) PushK(k types.KLine)

func (*HULL) Update

func (inc *HULL) Update(value float64)

type KLineCalculateUpdater

type KLineCalculateUpdater interface {
	CalculateAndUpdate(allKLines []types.KLine)
}

type KLineClosedBinder

type KLineClosedBinder interface {
	BindK(target KLineClosedEmitter, symbol string, interval types.Interval)
}

type KLineClosedEmitter

type KLineClosedEmitter interface {
	OnKLineClosed(func(k types.KLine))
}

KLineClosedEmitter is currently applied to the market data stream the market data stream emits the KLine closed event to the listeners.

type KLinePusher

type KLinePusher interface {
	PushK(k types.KLine)
}

KLinePusher provides an interface for API user to push kline value to the indicator. The indicator implements its own way to calculate the value from the given kline object.

type KLineStream

type KLineStream struct {
	// contains filtered or unexported fields
}

func KLines

func KLines(source types.Stream, symbol string, interval types.Interval) *KLineStream

KLines creates a KLine stream that pushes the klines to the subscribers

func (*KLineStream) AddSubscriber

func (s *KLineStream) AddSubscriber(f func(k types.KLine))

AddSubscriber adds the subscriber function and push historical data to the subscriber

func (*KLineStream) BackFill

func (s *KLineStream) BackFill(kLines []types.KLine)

func (*KLineStream) EmitUpdate

func (s *KLineStream) EmitUpdate(k types.KLine)

func (*KLineStream) Last

func (s *KLineStream) Last(i int) *types.KLine

func (*KLineStream) Length

func (s *KLineStream) Length() int

func (*KLineStream) OnUpdate

func (s *KLineStream) OnUpdate(cb func(k types.KLine))

type KLineSubscription

type KLineSubscription interface {
	AddSubscriber(f func(k types.KLine))
	Length() int
	Last(i int) *types.KLine
}

type KLineValueMapper

type KLineValueMapper func(k types.KLine) float64

type KLineWindowUpdater

type KLineWindowUpdater interface {
	OnKLineWindowUpdate(func(interval types.Interval, window types.KLineWindow))
}

type KalmanFilter

type KalmanFilter struct {
	types.SeriesBase
	types.IntervalWindow
	AdditionalSmoothWindow uint

	Values floats.Slice

	UpdateCallbacks []func(value float64)
	// contains filtered or unexported fields
}

func (*KalmanFilter) EmitUpdate

func (inc *KalmanFilter) EmitUpdate(value float64)

func (*KalmanFilter) Index

func (inc *KalmanFilter) Index(i int) float64

func (*KalmanFilter) Last

func (inc *KalmanFilter) Last(i int) float64

func (*KalmanFilter) Length

func (inc *KalmanFilter) Length() int

func (*KalmanFilter) OnUpdate

func (inc *KalmanFilter) OnUpdate(cb func(value float64))

func (*KalmanFilter) PushK

func (inc *KalmanFilter) PushK(k types.KLine)

func (*KalmanFilter) Update

func (inc *KalmanFilter) Update(value float64)

type KlingerOscillator

type KlingerOscillator struct {
	types.SeriesBase
	types.IntervalWindow
	Fast types.UpdatableSeries
	Slow types.UpdatableSeries
	VF   VolumeForce
	// contains filtered or unexported fields
}

Refer: Klinger Oscillator Refer URL: https://www.investopedia.com/terms/k/klingeroscillator.asp Explanation: The Klinger Oscillator is a technical indicator that was developed by Stephen Klinger. It is based on the assumption that there is a relationship between money flow and price movement in the stock market. The Klinger Oscillator is calculated by taking the difference between a 34-period and 55-period moving average. Usually the indicator is using together with a 9-period or 13-period of moving average as the signal line. This indicator is often used to identify potential turning points in the market, as well as to confirm the strength of a trend.

func (*KlingerOscillator) BindK

func (inc *KlingerOscillator) BindK(target KLineClosedEmitter, symbol string, interval types.Interval)

func (*KlingerOscillator) EmitUpdate

func (inc *KlingerOscillator) EmitUpdate(value float64)

func (*KlingerOscillator) Last

func (inc *KlingerOscillator) Last(i int) float64

func (*KlingerOscillator) Length

func (inc *KlingerOscillator) Length() int

func (*KlingerOscillator) OnUpdate

func (inc *KlingerOscillator) OnUpdate(cb func(value float64))

func (*KlingerOscillator) PushK

func (inc *KlingerOscillator) PushK(k types.KLine)

func (*KlingerOscillator) Update

func (inc *KlingerOscillator) Update(high, low, cloze, volume float64)

type LinReg

type LinReg struct {
	types.SeriesBase
	types.IntervalWindow

	// Values are the slopes of linear regression baseline
	Values floats.Slice
	// ValueRatios are the ratio of slope to the price
	ValueRatios floats.Slice

	EndTime         time.Time
	UpdateCallbacks []func(value float64)
	// contains filtered or unexported fields
}

LinReg is Linear Regression baseline

func (*LinReg) BindK

func (lr *LinReg) BindK(target KLineClosedEmitter, symbol string, interval types.Interval)

func (*LinReg) EmitUpdate

func (lr *LinReg) EmitUpdate(value float64)

func (*LinReg) Index

func (lr *LinReg) Index(i int) float64

Index returns the slope of specified index

func (*LinReg) IndexRatio

func (lr *LinReg) IndexRatio(i int) float64

IndexRatio returns the slope ratio

func (*LinReg) Last

func (lr *LinReg) Last(i int) float64

Last slope of linear regression baseline

func (*LinReg) LastRatio

func (lr *LinReg) LastRatio() float64

LastRatio of slope to price

func (*LinReg) Length

func (lr *LinReg) Length() int

Length of the slope values

func (*LinReg) LengthRatio

func (lr *LinReg) LengthRatio() int

LengthRatio of the slope ratio values

func (*LinReg) LoadK

func (lr *LinReg) LoadK(allKLines []types.KLine)

func (*LinReg) OnUpdate

func (lr *LinReg) OnUpdate(cb func(value float64))

func (*LinReg) PushK

func (lr *LinReg) PushK(k types.KLine)

func (*LinReg) Update

func (lr *LinReg) Update(kline types.KLine)

Update Linear Regression baseline slope

type Line

type Line struct {
	types.SeriesBase
	types.IntervalWindow

	Interval types.Interval
	// contains filtered or unexported fields
}

Line indicator is a utility that helps to simulate either the 1. trend 2. support 3. resistance of the market data, defined with series interface

func NewLine

func NewLine(startIndex int, startValue float64, endIndex int, endValue float64, interval types.Interval) *Line

func (*Line) Bind

func (l *Line) Bind(updater KLineWindowUpdater)

func (*Line) Index

func (l *Line) Index(i int) float64

func (*Line) Last

func (l *Line) Last(i int) float64

func (*Line) Length

func (l *Line) Length() int

func (*Line) SetXY1

func (l *Line) SetXY1(index int, value float64)

func (*Line) SetXY2

func (l *Line) SetXY2(index int, value float64)

type MACDConfig

type MACDConfig struct {
	types.IntervalWindow // 9

	// ShortPeriod is the short term period EMA, usually 12
	ShortPeriod int `json:"short"`
	// LongPeriod is the long term period EMA, usually 26
	LongPeriod int `json:"long"`
}

type MACDLegacy

type MACDLegacy struct {
	MACDConfig

	Values floats.Slice `json:"-"`

	Histogram floats.Slice `json:"-"`

	EndTime time.Time
	// contains filtered or unexported fields
}

func (*MACDLegacy) EmitUpdate

func (inc *MACDLegacy) EmitUpdate(macd float64, signal float64, histogram float64)

func (*MACDLegacy) Last

func (inc *MACDLegacy) Last(i int) float64

func (*MACDLegacy) Length

func (inc *MACDLegacy) Length() int

func (*MACDLegacy) MACD

func (inc *MACDLegacy) MACD() types.SeriesExtend

func (*MACDLegacy) OnUpdate

func (inc *MACDLegacy) OnUpdate(cb func(macd float64, signal float64, histogram float64))

func (*MACDLegacy) PushK

func (inc *MACDLegacy) PushK(k types.KLine)

func (*MACDLegacy) Singals

func (inc *MACDLegacy) Singals() types.SeriesExtend

func (*MACDLegacy) Update

func (inc *MACDLegacy) Update(x float64)

type MACDStream

type MACDStream struct {
	*SubtractStream

	FastEWMA, SlowEWMA, Signal *EWMAStream
	Histogram                  *SubtractStream
	// contains filtered or unexported fields
}

func MACD2

func MACD2(source Float64Source, shortWindow, longWindow, signalWindow int) *MACDStream

type MACDValues

type MACDValues struct {
	types.SeriesBase
	*MACDLegacy
}

func (*MACDValues) Index

func (inc *MACDValues) Index(i int) float64

func (*MACDValues) Last

func (inc *MACDValues) Last(i int) float64

func (*MACDValues) Length

func (inc *MACDValues) Length() int

type MultiplyStream

type MultiplyStream struct {
	*Float64Series
	// contains filtered or unexported fields
}

func Multiply

func Multiply(a, b Float64Source) *MultiplyStream

type OBV

type OBV struct {
	types.SeriesBase
	types.IntervalWindow
	Values   floats.Slice
	PrePrice float64
	EndTime  time.Time
	// contains filtered or unexported fields
}

obv implements on-balance volume indicator

On-Balance Volume (OBV) Definition - https://www.investopedia.com/terms/o/onbalancevolume.asp

On-Balance Volume (OBV) is a technical analysis indicator that uses volume information to predict changes in stock price. The idea behind OBV is that volume precedes price: when the OBV is rising, it means that buyers are becoming more aggressive and that the stock price is likely to follow suit. When the OBV is falling, it indicates that sellers are becoming more aggressive and that the stock price is likely to decrease. OBV is calculated by adding the volume on days when the stock price closes higher and subtracting the volume on days when the stock price closes lower. This running total forms the OBV line, which can then be used to make predictions about future stock price movements.

func (*OBV) Bind

func (inc *OBV) Bind(updater KLineWindowUpdater)

func (*OBV) CalculateAndUpdate

func (inc *OBV) CalculateAndUpdate(kLines []types.KLine)

func (*OBV) EmitUpdate

func (inc *OBV) EmitUpdate(value float64)

func (*OBV) Index

func (inc *OBV) Index(i int) float64

func (*OBV) Last

func (inc *OBV) Last(i int) float64

func (*OBV) OnUpdate

func (inc *OBV) OnUpdate(cb func(value float64))

func (*OBV) PushK

func (inc *OBV) PushK(k types.KLine)

func (*OBV) Update

func (inc *OBV) Update(price, volume float64)

type PSAR

type PSAR struct {
	types.SeriesBase
	types.IntervalWindow
	High    *types.Queue
	Low     *types.Queue
	Values  floats.Slice // Stop and Reverse
	AF      float64      // Acceleration Factor
	EP      float64
	Falling bool

	EndTime         time.Time
	UpdateCallbacks []func(value float64)
}

func (*PSAR) BindK

func (inc *PSAR) BindK(target KLineClosedEmitter, symbol string, interval types.Interval)

func (*PSAR) EmitUpdate

func (inc *PSAR) EmitUpdate(value float64)

func (*PSAR) Last

func (inc *PSAR) Last(i int) float64

func (*PSAR) Length

func (inc *PSAR) Length() int

func (*PSAR) OnUpdate

func (inc *PSAR) OnUpdate(cb func(value float64))

func (*PSAR) PushK

func (inc *PSAR) PushK(k types.KLine)

func (*PSAR) Update

func (inc *PSAR) Update(high, low float64)

type Pivot

type Pivot struct {
	types.IntervalWindow

	// Values
	Lows  floats.Slice // higher low
	Highs floats.Slice // lower high

	EndTime time.Time
	// contains filtered or unexported fields
}

func (*Pivot) Bind

func (inc *Pivot) Bind(updater KLineWindowUpdater)

func (*Pivot) CalculateAndUpdate

func (inc *Pivot) CalculateAndUpdate(klines []types.KLine)

func (*Pivot) EmitUpdate

func (inc *Pivot) EmitUpdate(valueLow float64, valueHigh float64)

func (*Pivot) LastHigh

func (inc *Pivot) LastHigh() float64

func (*Pivot) LastLow

func (inc *Pivot) LastLow() float64

func (*Pivot) OnUpdate

func (inc *Pivot) OnUpdate(cb func(valueLow float64, valueHigh float64))

type PivotHigh

type PivotHigh struct {
	types.SeriesBase

	types.IntervalWindow

	Highs   floats.Slice
	Values  floats.Slice
	EndTime time.Time
	// contains filtered or unexported fields
}

func (*PivotHigh) EmitUpdate

func (inc *PivotHigh) EmitUpdate(value float64)

func (*PivotHigh) Last

func (inc *PivotHigh) Last(i int) float64

func (*PivotHigh) Length

func (inc *PivotHigh) Length() int

func (*PivotHigh) OnUpdate

func (inc *PivotHigh) OnUpdate(cb func(value float64))

func (*PivotHigh) PushK

func (inc *PivotHigh) PushK(k types.KLine)

func (*PivotHigh) Update

func (inc *PivotHigh) Update(value float64)

type PivotHighStream

type PivotHighStream struct {
	*Float64Series
	// contains filtered or unexported fields
}

func PivotHigh2

func PivotHigh2(source Float64Source, window, rightWindow int) *PivotHighStream

type PivotLow

type PivotLow struct {
	types.SeriesBase

	types.IntervalWindow

	Lows    floats.Slice
	Values  floats.Slice
	EndTime time.Time
	// contains filtered or unexported fields
}

func (*PivotLow) EmitUpdate

func (inc *PivotLow) EmitUpdate(value float64)

func (*PivotLow) Last

func (inc *PivotLow) Last(i int) float64

func (*PivotLow) Length

func (inc *PivotLow) Length() int

func (*PivotLow) OnUpdate

func (inc *PivotLow) OnUpdate(cb func(value float64))

func (*PivotLow) PushK

func (inc *PivotLow) PushK(k types.KLine)

func (*PivotLow) Update

func (inc *PivotLow) Update(value float64)

type PivotLowStream

type PivotLowStream struct {
	*Float64Series
	// contains filtered or unexported fields
}

func PivotLow2

func PivotLow2(source Float64Source, window, rightWindow int) *PivotLowStream

type PivotSupertrend

type PivotSupertrend struct {
	types.SeriesBase
	types.IntervalWindow
	ATRMultiplier float64 `json:"atrMultiplier"`
	PivotWindow   int     `json:"pivotWindow"`

	AverageTrueRange *ATR // Value must be set when initialized in strategy

	PivotLow  *PivotLow  // Value must be set when initialized in strategy
	PivotHigh *PivotHigh // Value must be set when initialized in strategy

	EndTime         time.Time
	UpdateCallbacks []func(value float64)
	// contains filtered or unexported fields
}

func (*PivotSupertrend) BindK

func (inc *PivotSupertrend) BindK(target KLineClosedEmitter, symbol string, interval types.Interval)

func (*PivotSupertrend) Direction

func (inc *PivotSupertrend) Direction() types.Direction

GetDirection return the current trend

func (*PivotSupertrend) EmitUpdate

func (inc *PivotSupertrend) EmitUpdate(value float64)

func (*PivotSupertrend) GetSignal

func (inc *PivotSupertrend) GetSignal() types.Direction

GetSignal returns signal (Down, None or Up)

func (*PivotSupertrend) Index

func (inc *PivotSupertrend) Index(i int) float64

func (*PivotSupertrend) Last

func (inc *PivotSupertrend) Last(i int) float64

func (*PivotSupertrend) LastSupertrendResistance

func (inc *PivotSupertrend) LastSupertrendResistance() float64

LastSupertrendResistance return the current supertrend resistance value

func (*PivotSupertrend) LastSupertrendSupport

func (inc *PivotSupertrend) LastSupertrendSupport() float64

LastSupertrendSupport return the current supertrend support value

func (*PivotSupertrend) Length

func (inc *PivotSupertrend) Length() int

func (*PivotSupertrend) LoadK

func (inc *PivotSupertrend) LoadK(allKLines []types.KLine)

func (*PivotSupertrend) OnUpdate

func (inc *PivotSupertrend) OnUpdate(cb func(value float64))

func (*PivotSupertrend) PushK

func (inc *PivotSupertrend) PushK(k types.KLine)

func (*PivotSupertrend) Update

func (inc *PivotSupertrend) Update(highPrice, lowPrice, closePrice float64)

type PriceStream

type PriceStream struct {
	*Float64Series
	// contains filtered or unexported fields
}

func ClosePrices

func ClosePrices(source KLineSubscription) *PriceStream

func HighPrices

func HighPrices(source KLineSubscription) *PriceStream

func LowPrices

func LowPrices(source KLineSubscription) *PriceStream

func OpenPrices

func OpenPrices(source KLineSubscription) *PriceStream

func Price

func Price(source KLineSubscription, mapper KLineValueMapper) *PriceStream

func Volumes

func Volumes(source KLineSubscription) *PriceStream

func (*PriceStream) AddSubscriber

func (s *PriceStream) AddSubscriber(f func(v float64))

AddSubscriber adds the subscriber function and push historical data to the subscriber

func (*PriceStream) PushAndEmit

func (s *PriceStream) PushAndEmit(v float64)

type RMA

type RMA struct {
	types.SeriesBase
	types.IntervalWindow

	Values  floats.Slice
	EndTime time.Time

	Adjust bool
	// contains filtered or unexported fields
}

func (*RMA) Bind

func (inc *RMA) Bind(updater KLineWindowUpdater)

func (*RMA) CalculateAndUpdate

func (inc *RMA) CalculateAndUpdate(kLines []types.KLine)

func (*RMA) Clone

func (inc *RMA) Clone() types.UpdatableSeriesExtend

func (*RMA) EmitUpdate

func (inc *RMA) EmitUpdate(value float64)

func (*RMA) Index

func (inc *RMA) Index(i int) float64

func (*RMA) Last

func (inc *RMA) Last(i int) float64

func (*RMA) Length

func (inc *RMA) Length() int

func (*RMA) OnUpdate

func (inc *RMA) OnUpdate(cb func(value float64))

func (*RMA) PushK

func (inc *RMA) PushK(k types.KLine)

func (*RMA) Update

func (inc *RMA) Update(x float64)

type RMAStream

type RMAStream struct {
	// embedded structs
	*Float64Series

	// config fields
	Adjust bool
	// contains filtered or unexported fields
}

func RMA2

func RMA2(source Float64Source, window int, adjust bool) *RMAStream

func (*RMAStream) Calculate

func (s *RMAStream) Calculate(x float64) float64

func (*RMAStream) Truncate

func (s *RMAStream) Truncate()

type RSI

type RSI struct {
	types.SeriesBase
	types.IntervalWindow
	Values          floats.Slice
	Prices          floats.Slice
	PreviousAvgLoss float64
	PreviousAvgGain float64

	EndTime time.Time
	// contains filtered or unexported fields
}

func (*RSI) Bind

func (inc *RSI) Bind(updater KLineWindowUpdater)

func (*RSI) CalculateAndUpdate

func (inc *RSI) CalculateAndUpdate(kLines []types.KLine)

func (*RSI) EmitUpdate

func (inc *RSI) EmitUpdate(value float64)

func (*RSI) Index

func (inc *RSI) Index(i int) float64

func (*RSI) Last

func (inc *RSI) Last(i int) float64

func (*RSI) Length

func (inc *RSI) Length() int

func (*RSI) OnUpdate

func (inc *RSI) OnUpdate(cb func(value float64))

func (*RSI) PushK

func (inc *RSI) PushK(k types.KLine)

func (*RSI) Update

func (inc *RSI) Update(price float64)

type RSIStream

type RSIStream struct {
	// embedded structs
	*Float64Series
	// contains filtered or unexported fields
}

func RSI2

func RSI2(source Float64Source, window int) *RSIStream

func (*RSIStream) Calculate

func (s *RSIStream) Calculate(_ float64) float64

type SMA

type SMA struct {
	types.SeriesBase
	types.IntervalWindow
	Values floats.Slice

	EndTime time.Time

	UpdateCallbacks []func(value float64)
	// contains filtered or unexported fields
}

func (*SMA) BindK

func (inc *SMA) BindK(target KLineClosedEmitter, symbol string, interval types.Interval)

func (*SMA) Clone

func (inc *SMA) Clone() types.UpdatableSeriesExtend

func (*SMA) EmitUpdate

func (inc *SMA) EmitUpdate(value float64)

func (*SMA) Index

func (inc *SMA) Index(i int) float64

func (*SMA) Last

func (inc *SMA) Last(i int) float64

func (*SMA) Length

func (inc *SMA) Length() int

func (*SMA) LoadK

func (inc *SMA) LoadK(allKLines []types.KLine)

func (*SMA) OnUpdate

func (inc *SMA) OnUpdate(cb func(value float64))

func (*SMA) PushK

func (inc *SMA) PushK(k types.KLine)

func (*SMA) Update

func (inc *SMA) Update(value float64)

type SMAStream

type SMAStream struct {
	*Float64Series
	// contains filtered or unexported fields
}

func SMA2

func SMA2(source Float64Source, window int) *SMAStream

func (*SMAStream) Calculate

func (s *SMAStream) Calculate(v float64) float64

func (*SMAStream) Truncate

func (s *SMAStream) Truncate()

type SSF

type SSF struct {
	types.SeriesBase
	types.IntervalWindow
	Poles int

	Values floats.Slice

	UpdateCallbacks []func(value float64)
	// contains filtered or unexported fields
}

Refer: https://easylanguagemastery.com/indicators/predictive-indicators/ Refer: https://github.com/twopirllc/pandas-ta/blob/main/pandas_ta/overlap/ssf.py Ehler's Super Smoother Filter

John F. Ehlers's solution to reduce lag and remove aliasing noise with his research in aerospace analog filter design. This indicator comes with two versions determined by the keyword poles. By default, it uses two poles but there is an option for three poles. Since SSF is a (Resursive) Digital Filter, the number of poles determine how many prior recursive SSF bars to include in the design of the filter. So two poles uses two prior SSF bars and three poles uses three prior SSF bars for their filter calculations.

func (*SSF) CalculateAndUpdate

func (inc *SSF) CalculateAndUpdate(allKLines []types.KLine)

func (*SSF) EmitUpdate

func (inc *SSF) EmitUpdate(value float64)

func (*SSF) Index

func (inc *SSF) Index(i int) float64

func (*SSF) Last

func (inc *SSF) Last(i int) float64

func (*SSF) Length

func (inc *SSF) Length() int

func (*SSF) OnUpdate

func (inc *SSF) OnUpdate(cb func(value float64))

func (*SSF) PushK

func (inc *SSF) PushK(k types.KLine)

func (*SSF) Update

func (inc *SSF) Update(value float64)

type STOCH

type STOCH struct {
	types.IntervalWindow
	K floats.Slice
	D floats.Slice

	HighValues floats.Slice
	LowValues  floats.Slice

	EndTime         time.Time
	UpdateCallbacks []func(k float64, d float64)
}

func (*STOCH) EmitUpdate

func (inc *STOCH) EmitUpdate(k float64, d float64)

func (*STOCH) GetD

func (inc *STOCH) GetD() types.Series

func (*STOCH) GetK

func (inc *STOCH) GetK() types.Series

func (*STOCH) LastD

func (inc *STOCH) LastD() float64

func (*STOCH) LastK

func (inc *STOCH) LastK() float64

func (*STOCH) OnUpdate

func (inc *STOCH) OnUpdate(cb func(k float64, d float64))

func (*STOCH) PushK

func (inc *STOCH) PushK(k types.KLine)

func (*STOCH) Update

func (inc *STOCH) Update(high, low, cloze float64)

type Simple

type Simple interface {
	KLinePusher
	Last(int) float64
	OnUpdate(f func(value float64))
}

Simple is the simple indicator that only returns one float64 value

type StdDev

type StdDev struct {
	types.SeriesBase
	types.IntervalWindow
	Values floats.Slice

	EndTime time.Time
	// contains filtered or unexported fields
}

func (*StdDev) EmitUpdate

func (inc *StdDev) EmitUpdate(value float64)

func (*StdDev) Index

func (inc *StdDev) Index(i int) float64

func (*StdDev) Last

func (inc *StdDev) Last(i int) float64

func (*StdDev) Length

func (inc *StdDev) Length() int

func (*StdDev) OnUpdate

func (inc *StdDev) OnUpdate(cb func(value float64))

func (*StdDev) PushK

func (inc *StdDev) PushK(k types.KLine)

func (*StdDev) Update

func (inc *StdDev) Update(value float64)

type StdDevStream

type StdDevStream struct {
	*Float64Series
	// contains filtered or unexported fields
}

func StdDev2

func StdDev2(source Float64Source, window int) *StdDevStream

func (*StdDevStream) Calculate

func (s *StdDevStream) Calculate(x float64) float64

type StochStream

type StochStream struct {
	types.SeriesBase

	K, D floats.Slice
	// contains filtered or unexported fields
}

func Stoch2

func Stoch2(source KLineSubscription, window, dPeriod int) *StochStream

Stochastic Oscillator

func (*StochStream) EmitUpdate

func (S *StochStream) EmitUpdate(k float64, d float64)

func (*StochStream) OnUpdate

func (S *StochStream) OnUpdate(cb func(k float64, d float64))

type SubtractStream

type SubtractStream struct {
	*Float64Series
	// contains filtered or unexported fields
}

SubtractStream subscribes 2 upstream data, and then subtract these 2 values

func Subtract

func Subtract(a, b Float64Source) *SubtractStream

Subtract creates the SubtractStream object subtract := Subtract(longEWMA, shortEWMA)

type Supertrend

type Supertrend struct {
	types.SeriesBase
	types.IntervalWindow
	ATRMultiplier float64 `json:"atrMultiplier"`

	AverageTrueRange *ATR

	EndTime         time.Time
	UpdateCallbacks []func(value float64)
	// contains filtered or unexported fields
}

func (*Supertrend) Bind

func (inc *Supertrend) Bind(updater KLineWindowUpdater)

func (*Supertrend) BindK

func (inc *Supertrend) BindK(target KLineClosedEmitter, symbol string, interval types.Interval)

func (*Supertrend) CalculateAndUpdate

func (inc *Supertrend) CalculateAndUpdate(kLines []types.KLine)

func (*Supertrend) Direction

func (inc *Supertrend) Direction() types.Direction

GetDirection return the current trend

func (*Supertrend) EmitUpdate

func (inc *Supertrend) EmitUpdate(value float64)

func (*Supertrend) GetSignal

func (inc *Supertrend) GetSignal() types.Direction

func (*Supertrend) Index

func (inc *Supertrend) Index(i int) float64

func (*Supertrend) Last

func (inc *Supertrend) Last(i int) float64

func (*Supertrend) LastSupertrendResistance

func (inc *Supertrend) LastSupertrendResistance() float64

LastSupertrendResistance return the current supertrend resistance

func (*Supertrend) LastSupertrendSupport

func (inc *Supertrend) LastSupertrendSupport() float64

LastSupertrendSupport return the current supertrend support

func (*Supertrend) Length

func (inc *Supertrend) Length() int

func (*Supertrend) LoadK

func (inc *Supertrend) LoadK(allKLines []types.KLine)

func (*Supertrend) OnUpdate

func (inc *Supertrend) OnUpdate(cb func(value float64))

func (*Supertrend) PushK

func (inc *Supertrend) PushK(k types.KLine)

func (*Supertrend) Update

func (inc *Supertrend) Update(highPrice, lowPrice, closePrice float64)

type TEMA

type TEMA struct {
	types.SeriesBase
	types.IntervalWindow
	Values floats.Slice
	A1     *EWMA
	A2     *EWMA
	A3     *EWMA

	UpdateCallbacks []func(value float64)
}

func (*TEMA) Bind

func (inc *TEMA) Bind(updater KLineWindowUpdater)

func (*TEMA) CalculateAndUpdate

func (inc *TEMA) CalculateAndUpdate(allKLines []types.KLine)

func (*TEMA) EmitUpdate

func (inc *TEMA) EmitUpdate(value float64)

func (*TEMA) Index

func (inc *TEMA) Index(i int) float64

func (*TEMA) Last

func (inc *TEMA) Last(i int) float64

func (*TEMA) Length

func (inc *TEMA) Length() int

func (*TEMA) OnUpdate

func (inc *TEMA) OnUpdate(cb func(value float64))

func (*TEMA) PushK

func (inc *TEMA) PushK(k types.KLine)

func (*TEMA) Update

func (inc *TEMA) Update(value float64)

type TILL

type TILL struct {
	types.SeriesBase
	types.IntervalWindow
	VolumeFactor float64
	// contains filtered or unexported fields
}

func (*TILL) Bind

func (inc *TILL) Bind(updater KLineWindowUpdater)

func (*TILL) BindK

func (inc *TILL) BindK(target KLineClosedEmitter, symbol string, interval types.Interval)

func (*TILL) CalculateAndUpdate

func (inc *TILL) CalculateAndUpdate(allKLines []types.KLine)

func (*TILL) EmitUpdate

func (inc *TILL) EmitUpdate(value float64)

func (*TILL) Index

func (inc *TILL) Index(i int) float64

func (*TILL) Last

func (inc *TILL) Last(i int) float64

func (*TILL) Length

func (inc *TILL) Length() int

func (*TILL) LoadK

func (inc *TILL) LoadK(allKLines []types.KLine)

func (*TILL) OnUpdate

func (inc *TILL) OnUpdate(cb func(value float64))

func (*TILL) PushK

func (inc *TILL) PushK(k types.KLine)

func (*TILL) Update

func (inc *TILL) Update(value float64)

type TMA

type TMA struct {
	types.SeriesBase
	types.IntervalWindow

	UpdateCallbacks []func(value float64)
	// contains filtered or unexported fields
}

Refer: Triangular Moving Average Refer URL: https://ja.wikipedia.org/wiki/移動平均

func (*TMA) EmitUpdate

func (inc *TMA) EmitUpdate(value float64)

func (*TMA) Index

func (inc *TMA) Index(i int) float64

func (*TMA) Last

func (inc *TMA) Last(i int) float64

func (*TMA) Length

func (inc *TMA) Length() int

func (*TMA) OnUpdate

func (inc *TMA) OnUpdate(cb func(value float64))

func (*TMA) PushK

func (inc *TMA) PushK(k types.KLine)

func (*TMA) Update

func (inc *TMA) Update(value float64)

type TRStream

type TRStream struct {
	// embedded struct
	*Float64Series
	// contains filtered or unexported fields
}

This TRStream calculates the ATR first

func TR2

func TR2(source KLineSubscription) *TRStream

type TSI

type TSI struct {
	types.SeriesBase
	types.Interval
	FastWindow int
	SlowWindow int
	PrevValue  float64
	Values     floats.Slice
	Pcs        *EWMA
	Pcds       *EWMA
	Apcs       *EWMA
	Apcds      *EWMA
	// contains filtered or unexported fields
}

Refer: True Strength Index Refer URL: https://www.investopedia.com/terms/t/tsi.asp

func (*TSI) BindK

func (inc *TSI) BindK(target KLineClosedEmitter, symbol string, interval types.Interval)

func (*TSI) EmitUpdate

func (inc *TSI) EmitUpdate(value float64)

func (*TSI) Index

func (inc *TSI) Index(i int) float64

func (*TSI) Last

func (inc *TSI) Last(i int) float64

func (*TSI) Length

func (inc *TSI) Length() int

func (*TSI) OnUpdate

func (inc *TSI) OnUpdate(cb func(value float64))

func (*TSI) PushK

func (inc *TSI) PushK(k types.KLine)

func (*TSI) Update

func (inc *TSI) Update(value float64)

type UtBotAlert

type UtBotAlert struct {
	types.IntervalWindow
	KeyValue float64 `json:"keyValue"` // Should be ATRMultiplier

	Values []types.Direction

	AverageTrueRange *ATR // Value must be set when initialized in strategy

	EndTime         time.Time
	UpdateCallbacks []func(value types.Direction)
	// contains filtered or unexported fields
}

func NewUtBotAlert

func NewUtBotAlert(iw types.IntervalWindow, keyValue float64) *UtBotAlert

func (*UtBotAlert) BindK

func (inc *UtBotAlert) BindK(target KLineClosedEmitter, symbol string, interval types.Interval)

func (*UtBotAlert) EmitUpdate

func (inc *UtBotAlert) EmitUpdate(value types.Direction)

func (*UtBotAlert) GetSignal

func (inc *UtBotAlert) GetSignal() types.Direction

GetSignal returns signal (down, none or up)

func (*UtBotAlert) Index

func (inc *UtBotAlert) Index(i int) types.Direction

func (*UtBotAlert) Last

func (inc *UtBotAlert) Last() types.Direction

func (*UtBotAlert) Length

func (inc *UtBotAlert) Length() int

func (*UtBotAlert) LoadK

func (inc *UtBotAlert) LoadK(allKLines []types.KLine)

LoadK calculates the initial values

func (*UtBotAlert) OnUpdate

func (inc *UtBotAlert) OnUpdate(cb func(value types.Direction))

func (*UtBotAlert) PushK

func (inc *UtBotAlert) PushK(k types.KLine)

func (*UtBotAlert) Update

func (inc *UtBotAlert) Update(highPrice, lowPrice, closePrice float64)

type VIDYA

type VIDYA struct {
	types.SeriesBase
	types.IntervalWindow
	Values floats.Slice
	// contains filtered or unexported fields
}

func (*VIDYA) Bind

func (inc *VIDYA) Bind(updater KLineWindowUpdater)

func (*VIDYA) CalculateAndUpdate

func (inc *VIDYA) CalculateAndUpdate(allKLines []types.KLine)

func (*VIDYA) EmitUpdate

func (inc *VIDYA) EmitUpdate(value float64)

func (*VIDYA) Index

func (inc *VIDYA) Index(i int) float64

func (*VIDYA) Last

func (inc *VIDYA) Last(i int) float64

func (*VIDYA) Length

func (inc *VIDYA) Length() int

func (*VIDYA) OnUpdate

func (inc *VIDYA) OnUpdate(cb func(value float64))

func (*VIDYA) PushK

func (inc *VIDYA) PushK(k types.KLine)

func (*VIDYA) Update

func (inc *VIDYA) Update(value float64)

type VWAP

type VWAP struct {
	types.SeriesBase
	types.IntervalWindow
	Values      floats.Slice
	Prices      floats.Slice
	Volumes     floats.Slice
	WeightedSum float64
	VolumeSum   float64

	EndTime         time.Time
	UpdateCallbacks []func(value float64)
}

func (*VWAP) Bind

func (inc *VWAP) Bind(updater KLineWindowUpdater)

func (*VWAP) CalculateAndUpdate

func (inc *VWAP) CalculateAndUpdate(allKLines []types.KLine)

func (*VWAP) EmitUpdate

func (inc *VWAP) EmitUpdate(value float64)

func (*VWAP) Index

func (inc *VWAP) Index(i int) float64

func (*VWAP) Last

func (inc *VWAP) Last(i int) float64

func (*VWAP) Length

func (inc *VWAP) Length() int

func (*VWAP) OnUpdate

func (inc *VWAP) OnUpdate(cb func(value float64))

func (*VWAP) PushK

func (inc *VWAP) PushK(k types.KLine)

func (*VWAP) Update

func (inc *VWAP) Update(price, volume float64)

type VWMA

type VWMA struct {
	types.SeriesBase
	types.IntervalWindow

	Values         floats.Slice
	PriceVolumeSMA *SMA
	VolumeSMA      *SMA

	EndTime time.Time
	// contains filtered or unexported fields
}

func (*VWMA) Bind

func (inc *VWMA) Bind(updater KLineWindowUpdater)

func (*VWMA) CalculateAndUpdate

func (inc *VWMA) CalculateAndUpdate(allKLines []types.KLine)

func (*VWMA) EmitUpdate

func (inc *VWMA) EmitUpdate(value float64)

func (*VWMA) Index

func (inc *VWMA) Index(i int) float64

func (*VWMA) Last

func (inc *VWMA) Last(i int) float64

func (*VWMA) Length

func (inc *VWMA) Length() int

func (*VWMA) OnUpdate

func (inc *VWMA) OnUpdate(cb func(value float64))

func (*VWMA) PushK

func (inc *VWMA) PushK(k types.KLine)

func (*VWMA) Update

func (inc *VWMA) Update(price, volume float64)

type Volatility

type Volatility struct {
	types.SeriesBase
	types.IntervalWindow
	Values  floats.Slice
	EndTime time.Time

	UpdateCallbacks []func(value float64)
}

func (*Volatility) Bind

func (inc *Volatility) Bind(updater KLineWindowUpdater)

func (*Volatility) CalculateAndUpdate

func (inc *Volatility) CalculateAndUpdate(allKLines []types.KLine)

func (*Volatility) EmitUpdate

func (inc *Volatility) EmitUpdate(value float64)

func (*Volatility) Index

func (inc *Volatility) Index(i int) float64

func (*Volatility) Last

func (inc *Volatility) Last(i int) float64

func (*Volatility) Length

func (inc *Volatility) Length() int

func (*Volatility) OnUpdate

func (inc *Volatility) OnUpdate(cb func(value float64))

type VolumeForce

type VolumeForce struct {
	Value float64
	// contains filtered or unexported fields
}

Utility to hold the state of calculation

func (*VolumeForce) Update

func (inc *VolumeForce) Update(high, low, cloze, volume float64)

type VolumeProfile

type VolumeProfile struct {
	types.IntervalWindow
	Delta float64
	// contains filtered or unexported fields
}

The Volume Profile is a technical analysis tool that is used to visualize the distribution of trading volume at different price levels in a security. It is typically plotted as a histogram or heatmap on the price chart, with the x-axis representing the price levels and the y-axis representing the trading volume. The Volume Profile can be used to identify areas of support and resistance, as well as potential entry and exit points for trades.

func (*VolumeProfile) PointOfControlAboveEqual

func (inc *VolumeProfile) PointOfControlAboveEqual(price float64, limit ...float64) (resultPrice float64, vol float64)

Get Resistence Level by finding PoC

func (*VolumeProfile) PointOfControlBelowEqual

func (inc *VolumeProfile) PointOfControlBelowEqual(price float64, limit ...float64) (resultPrice float64, vol float64)

Get Support Level by finding PoC

func (*VolumeProfile) Update

func (inc *VolumeProfile) Update(price, volume float64, timestamp types.Time)

type WWMA

type WWMA struct {
	types.SeriesBase
	types.IntervalWindow
	Values       floats.Slice
	LastOpenTime time.Time

	UpdateCallbacks []func(value float64)
}

func (*WWMA) Bind

func (inc *WWMA) Bind(updater KLineWindowUpdater)

func (*WWMA) CalculateAndUpdate

func (inc *WWMA) CalculateAndUpdate(allKLines []types.KLine)

func (*WWMA) EmitUpdate

func (inc *WWMA) EmitUpdate(value float64)

func (*WWMA) Index

func (inc *WWMA) Index(i int) float64

func (*WWMA) Last

func (inc *WWMA) Last(i int) float64

func (*WWMA) Length

func (inc *WWMA) Length() int

func (*WWMA) OnUpdate

func (inc *WWMA) OnUpdate(cb func(value float64))

func (*WWMA) PushK

func (inc *WWMA) PushK(k types.KLine)

func (*WWMA) Update

func (inc *WWMA) Update(value float64)

type WeightedDrift

type WeightedDrift struct {
	types.SeriesBase
	types.IntervalWindow

	Values          floats.Slice
	MA              types.UpdatableSeriesExtend
	Weight          *types.Queue
	LastValue       float64
	UpdateCallbacks []func(value float64)
	// contains filtered or unexported fields
}

Refer: https://tradingview.com/script/aDymGrFx-Drift-Study-Inspired-by-Monte-Carlo-Simulations-with-BM-KL/ Brownian Motion's drift factor could be used in Monte Carlo Simulations

func (*WeightedDrift) Bind

func (inc *WeightedDrift) Bind(updater KLineWindowUpdater)

func (*WeightedDrift) CalculateAndUpdate

func (inc *WeightedDrift) CalculateAndUpdate(allKLines []types.KLine)

func (*WeightedDrift) Clone

func (inc *WeightedDrift) Clone() (out *WeightedDrift)

func (*WeightedDrift) EmitUpdate

func (inc *WeightedDrift) EmitUpdate(value float64)

func (*WeightedDrift) Index

func (inc *WeightedDrift) Index(i int) float64

func (*WeightedDrift) Last

func (inc *WeightedDrift) Last(i int) float64

func (*WeightedDrift) Length

func (inc *WeightedDrift) Length() int

func (*WeightedDrift) OnUpdate

func (inc *WeightedDrift) OnUpdate(cb func(value float64))

func (*WeightedDrift) PushK

func (inc *WeightedDrift) PushK(k types.KLine)

func (*WeightedDrift) TestUpdate

func (inc *WeightedDrift) TestUpdate(value float64, weight float64) *WeightedDrift

func (*WeightedDrift) Update

func (inc *WeightedDrift) Update(value float64, weight float64)

func (*WeightedDrift) ZeroPoint

func (inc *WeightedDrift) ZeroPoint() float64

Assume that MA is SMA

type ZLEMA

type ZLEMA struct {
	types.SeriesBase
	types.IntervalWindow
	// contains filtered or unexported fields
}

func (*ZLEMA) Bind

func (inc *ZLEMA) Bind(updater KLineWindowUpdater)

func (*ZLEMA) CalculateAndUpdate

func (inc *ZLEMA) CalculateAndUpdate(allKLines []types.KLine)

func (*ZLEMA) EmitUpdate

func (inc *ZLEMA) EmitUpdate(value float64)

func (*ZLEMA) Index

func (inc *ZLEMA) Index(i int) float64

func (*ZLEMA) Last

func (inc *ZLEMA) Last(i int) float64

func (*ZLEMA) Length

func (inc *ZLEMA) Length() int

func (*ZLEMA) OnUpdate

func (inc *ZLEMA) OnUpdate(cb func(value float64))

func (*ZLEMA) PushK

func (inc *ZLEMA) PushK(k types.KLine)

func (*ZLEMA) Update

func (inc *ZLEMA) Update(value float64)

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL