Skip to content

Latest commit

 

History

History
251 lines (173 loc) · 10.5 KB

File metadata and controls

251 lines (173 loc) · 10.5 KB

decorator

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

Package decorator provides illustrative example decorators demonstrating how to modify strategy signals for educational and research purposes.

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 The Indicator Authors.
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 and educational purposes and is not to be construed as investment, financial, or trading advice.

Index

CostBasisExitStrategy demonstrates an illustrative decorator that manages exit conditions based on cost basis.

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

func NewCostBasisExitStrategy(innerStrategy strategy.Strategy) *CostBasisExitStrategy

NewCostBasisExitStrategy initializes an example CostBasisExitStrategy instance with default parameters.

func NewNoLossStrategy(innerStrategy strategy.Strategy) *CostBasisExitStrategy

NewNoLossStrategy is an alias for NewCostBasisExitStrategy for backwards compatibility.

Deprecated: Use NewCostBasisExitStrategy instead.

func (*CostBasisExitStrategy) Compute

func (c *CostBasisExitStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action

Compute wraps ComputeWithContext for backwards compatibility.

Deprecated: Use ComputeWithContext instead.

func (*CostBasisExitStrategy) ComputeWithContext

func (c *CostBasisExitStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.Action

ComputeWithContext processes the provided asset snapshots and generates an illustrative stream of actions.

func (*CostBasisExitStrategy) Name

func (c *CostBasisExitStrategy) Name() string

Name returns the name of the example strategy.

func (*CostBasisExitStrategy) Report

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

Report processes the provided asset snapshots and generates an illustrative report annotated with example actions.

InverseStrategy demonstrates an illustrative decorator that inverts the actions generated by an underlying strategy.

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

func NewInverseStrategy(innerStrategy strategy.Strategy) *InverseStrategy

NewInverseStrategy initializes an example InverseStrategy instance with default parameters.

func (*InverseStrategy) Compute

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

Compute wraps ComputeWithContext for backwards compatibility.

Deprecated: Use ComputeWithContext instead.

func (*InverseStrategy) ComputeWithContext

func (i *InverseStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.Action

ComputeWithContext processes the provided asset snapshots and generates an illustrative stream of actions.

func (*InverseStrategy) Name

func (i *InverseStrategy) Name() string

Name returns the name of the example strategy.

func (*InverseStrategy) Report

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

Report processes the provided asset snapshots and generates an illustrative report annotated with example actions.

NoLossStrategy is an alias for CostBasisExitStrategy for backwards compatibility.

Deprecated: Use CostBasisExitStrategy instead.

type NoLossStrategy = CostBasisExitStrategy

StopLossStrategy demonstrates an illustrative decorator that applies stop-loss logic to an underlying strategy.

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

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

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

NewStopLossStrategy initializes an example StopLossStrategy instance with default parameters.

func (*StopLossStrategy) Compute

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

Compute wraps ComputeWithContext for backwards compatibility.

Deprecated: Use ComputeWithContext instead.

func (*StopLossStrategy) ComputeWithContext

func (s *StopLossStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.Action

ComputeWithContext processes the provided asset snapshots and generates an illustrative stream of actions.

func (*StopLossStrategy) Name

func (s *StopLossStrategy) Name() string

Name returns the name of the example strategy.

func (*StopLossStrategy) Report

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

Report processes the provided asset snapshots and generates an illustrative report annotated with example actions.

Generated by gomarkdoc