decorator

package
v2.1.29 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

README

decorator

import "github.com/cinar/indicator/v2/strategy/decorator"

Package decorator contains the decorator strategy 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-2026 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

type InverseStrategy

InverseStrategy reverses the advice of another strategy. For example, if the original strategy suggests buying an asset, InverseStrategy would recommend selling it.

type InverseStrategy struct {
    // InnerStrategy is the inner strategy.
    InnerStrategy strategy.Strategy
}

func NewInverseStrategy
func NewInverseStrategy(innerStrategy strategy.Strategy) *InverseStrategy

NewInverseStrategy function initializes a new inverse strategy instance.

func (*InverseStrategy) Compute
func (i *InverseStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action

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

func (*InverseStrategy) Name
func (i *InverseStrategy) Name() string

Name returns the name of the strategy.

func (*InverseStrategy) Report
func (i *InverseStrategy) Report(c <-chan *asset.Snapshot) *helper.Report

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

type NoLossStrategy

NoLossStrategy prevents selling an asset at a loss. It modifies the recommendations of another strategy to ensure that the asset is only sold if its value is at or above the original purchase price.

type NoLossStrategy struct {
    // InnertStrategy is the inner strategy.
    InnertStrategy strategy.Strategy
}

func NewNoLossStrategy
func NewNoLossStrategy(innerStrategy strategy.Strategy) *NoLossStrategy

NewNoLossStrategy function initializes a new no loss strategy instance.

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

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

func (*NoLossStrategy) Name
func (n *NoLossStrategy) Name() string

Name returns the name of the strategy.

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

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

type StopLossStrategy

StopLossStrategy prevents a loss by recommending a sell action when the assets drop below the given threshold.

type StopLossStrategy struct {
    // InnertStrategy is the inner strategy.
    InnertStrategy strategy.Strategy

    // Percentage is the loss threshold in percentage.
    Percentage float64
}

func NewStopLossStrategy
func NewStopLossStrategy(innerStrategy strategy.Strategy, percentage float64) *StopLossStrategy

NewStopLossStrategy function initializes a new stop loss strategy instance.

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

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

func (*StopLossStrategy) Name
func (s *StopLossStrategy) Name() string

Name returns the name of the strategy.

func (*StopLossStrategy) Report
func (s *StopLossStrategy) Report(c <-chan *asset.Snapshot) *helper.Report

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

Generated by gomarkdoc

Documentation

Overview

Package decorator contains the decorator strategy 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-2026 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

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type InverseStrategy

type InverseStrategy struct {
	// InnerStrategy is the inner strategy.
	InnerStrategy strategy.Strategy
}

InverseStrategy reverses the advice of another strategy. For example, if the original strategy suggests buying an asset, InverseStrategy would recommend selling it.

func NewInverseStrategy

func NewInverseStrategy(innerStrategy strategy.Strategy) *InverseStrategy

NewInverseStrategy function initializes a new inverse strategy instance.

func (*InverseStrategy) Compute

func (i *InverseStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action

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

func (*InverseStrategy) Name

func (i *InverseStrategy) Name() string

Name returns the name of the strategy.

func (*InverseStrategy) Report

func (i *InverseStrategy) Report(c <-chan *asset.Snapshot) *helper.Report

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

type NoLossStrategy

type NoLossStrategy struct {
	// InnertStrategy is the inner strategy.
	InnertStrategy strategy.Strategy
}

NoLossStrategy prevents selling an asset at a loss. It modifies the recommendations of another strategy to ensure that the asset is only sold if its value is at or above the original purchase price.

func NewNoLossStrategy

func NewNoLossStrategy(innerStrategy strategy.Strategy) *NoLossStrategy

NewNoLossStrategy function initializes a new no loss strategy instance.

func (*NoLossStrategy) Compute

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

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

func (*NoLossStrategy) Name

func (n *NoLossStrategy) Name() string

Name returns the name of the strategy.

func (*NoLossStrategy) Report

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

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

type StopLossStrategy added in v2.1.2

type StopLossStrategy struct {
	// InnertStrategy is the inner strategy.
	InnertStrategy strategy.Strategy

	// Percentage is the loss threshold in percentage.
	Percentage float64
}

StopLossStrategy prevents a loss by recommending a sell action when the assets drop below the given threshold.

func NewStopLossStrategy added in v2.1.2

func NewStopLossStrategy(innerStrategy strategy.Strategy, percentage float64) *StopLossStrategy

NewStopLossStrategy function initializes a new stop loss strategy instance.

func (*StopLossStrategy) Compute added in v2.1.2

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

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

func (*StopLossStrategy) Name added in v2.1.2

func (s *StopLossStrategy) Name() string

Name returns the name of the strategy.

func (*StopLossStrategy) Report added in v2.1.2

func (s *StopLossStrategy) Report(c <-chan *asset.Snapshot) *helper.Report

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

Jump to

Keyboard shortcuts

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