trend

package
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: May 27, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package trend offers classic trend following algos.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeApexBotFromConfig

func MakeApexBotFromConfig(config map[string]any) (trader.Bot, error)

MakeApexBotFromConfig returns a bot configured with an ApexPredicter.

func MakeCrossBotFromConfig

func MakeCrossBotFromConfig(config map[string]any) (trader.Bot, error)

MakeCrossBotFromConfig returns a bot configured with a CrossPredicter and sensible defaults if config is missing.

Types

type ApexPredicter

type ApexPredicter struct {
	// PriceSelector is the kline component to use for price. Close by default.
	PriceSelector ta.PriceSelector

	// MA is the smoothed price series to evaluate for a peak or valley.
	MA ta.Indicator[float64]

	// MMI is the trend filter.
	MMI ta.Indicator[float64]
	// contains filtered or unexported fields
}

ApexPredicter predicts price direction based on trend turning points with a market meaness index filter. Peak signals the start of a downward price trend. Valley signal the start of an upward price trend.

func NewApexPredicter

func NewApexPredicter(ma, mmi ta.Indicator[float64]) *ApexPredicter

NewApexPredicter creates a new predicter with Close quote price selector.

func (*ApexPredicter) Predict

func (p *ApexPredicter) Predict() float64

Predict returns a score to indicate confidence of price direction.

1.0 = Valley with MMI confluence.

0.9 = Valley (no MMI confluence).

-0.9 = Peak (no MMI confluence).

-1.0 = Peak with MMI confluence.

[0.0, 0.1] = Flat trend.

func (*ApexPredicter) ReceivePrice

func (p *ApexPredicter) ReceivePrice(ctx context.Context, price market.Kline) error

ReceivePrice updates the prediction algo with the next market price. Call Predict() to get the resulting score.

func (*ApexPredicter) Valid

func (p *ApexPredicter) Valid() bool

Valid returns true if MA and MMI indicators are valid.

type Bot

type Bot struct {
	Asset market.Asset

	EnterLong float64
	ExitLong  float64

	EnterShort float64
	ExitShort  float64

	Predicter trader.Predicter
	Risker    risk.Risker
	Sizer     money.Sizer
	// contains filtered or unexported fields
}

Bot will open and/or close a single market position based on the score from the the given trader.Predicter and the associated EnterLong et al params. Stop loss and position size is determined by the given risk.Risker and money.Sizer.

func NewBot

func NewBot() *Bot

NewBot sets default enter and exit scores and basic Risker and Sizer implementations. Post creation of the bot the Predicter and Asset field must be set and a call made to SetDealer().

func (*Bot) Close

func (b *Bot) Close(ctx context.Context) error

Close exits all open positions at current market price.

func (*Bot) ReceivePrice

func (b *Bot) ReceivePrice(ctx context.Context, price market.Kline) error

ReceivePrice updates the algo with latest market price potentially triggering buy and/or sell orders.

func (*Bot) SetDealer

func (b *Bot) SetDealer(dealer broker.Dealer)

SetDealer sets the broker used for placing orders.

func (*Bot) Warmup

func (b *Bot) Warmup(ctx context.Context, prices []market.Kline) error

Warmup seeds the Predicter and Risker with historical price data.

type CrossPredicter

type CrossPredicter struct {
	// PriceSelector is the kline component to use for price. Close by default.
	PriceSelector ta.PriceSelector

	// Osc is the moving average oscillator to use for entery and exit signals.
	Osc ta.Indicator[float64]

	// MMI is the signal filter.
	MMI ta.Indicator[float64]
	// contains filtered or unexported fields
}

CrossPredicter predicts price direction based on a moving average cross with a market meaness index filter.

func NewCrossPredicter

func NewCrossPredicter(osc, mmi ta.Indicator[float64]) *CrossPredicter

NewCrossPredicter creates a new predicter with Close quote price selector.

func (*CrossPredicter) Predict

func (p *CrossPredicter) Predict() float64

Predict returns a score to indicate confidence of price direction.

1.0 = Long trend cross over with MMI in confluence.

0.9 = Long trend cross over (no MMI confluence).

-0.9 = Short trend cross over (no MMI confluence).

-1.0 = Short trend with MMI confluence.

[0.0, 0.1] = Flat trend.

func (*CrossPredicter) ReceivePrice

func (p *CrossPredicter) ReceivePrice(ctx context.Context, price market.Kline) error

ReceivePrice updates the prediction algo with the next market price. Call Predict() to get the resulting score.

func (*CrossPredicter) Valid

func (p *CrossPredicter) Valid() bool

Valid returns true if Osc and MMI indicators are valid.

Jump to

Keyboard shortcuts

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