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.
Copyright (c) 2021-2026 The Indicator Authors.
The source code is provided under GNU AGPLv3 License.
https://github.com/cinar/indicator
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.
- type CostBasisExitStrategy
- func NewCostBasisExitStrategy(innerStrategy strategy.Strategy) *CostBasisExitStrategy
- func NewNoLossStrategy(innerStrategy strategy.Strategy) *CostBasisExitStrategy
- func (c *CostBasisExitStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (c *CostBasisExitStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (c *CostBasisExitStrategy) Name() string
- func (c *CostBasisExitStrategy) Report(s <-chan *asset.Snapshot) *helper.Report
- type InverseStrategy
- func NewInverseStrategy(innerStrategy strategy.Strategy) *InverseStrategy
- func (i *InverseStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (i *InverseStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (i *InverseStrategy) Name() string
- func (i *InverseStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
- type NoLossStrategy
- type StopLossStrategy
- func NewStopLossStrategy(innerStrategy strategy.Strategy, percentage float64) *StopLossStrategy
- func (s *StopLossStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (s *StopLossStrategy) ComputeWithContext(ctx context.Context, snapshots <-chan *asset.Snapshot) <-chan strategy.Action
- func (s *StopLossStrategy) Name() string
- func (s *StopLossStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
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) *CostBasisExitStrategyNewCostBasisExitStrategy initializes an example CostBasisExitStrategy instance with default parameters.
func NewNoLossStrategy
func NewNoLossStrategy(innerStrategy strategy.Strategy) *CostBasisExitStrategyNewNoLossStrategy 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.ActionCompute 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.ActionComputeWithContext processes the provided asset snapshots and generates an illustrative stream of actions.
func (*CostBasisExitStrategy) Name
func (c *CostBasisExitStrategy) Name() stringName returns the name of the example strategy.
func (*CostBasisExitStrategy) Report
func (c *CostBasisExitStrategy) Report(s <-chan *asset.Snapshot) *helper.ReportReport processes the provided asset snapshots and generates an illustrative report annotated with example actions.
type InverseStrategy
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
func NewInverseStrategy(innerStrategy strategy.Strategy) *InverseStrategyNewInverseStrategy initializes an example InverseStrategy instance with default parameters.
func (*InverseStrategy) Compute
func (i *InverseStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.ActionCompute 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.ActionComputeWithContext processes the provided asset snapshots and generates an illustrative stream of actions.
func (*InverseStrategy) Name
func (i *InverseStrategy) Name() stringName returns the name of the example strategy.
func (*InverseStrategy) Report
func (i *InverseStrategy) Report(c <-chan *asset.Snapshot) *helper.ReportReport processes the provided asset snapshots and generates an illustrative report annotated with example actions.
type NoLossStrategy
NoLossStrategy is an alias for CostBasisExitStrategy for backwards compatibility.
Deprecated: Use CostBasisExitStrategy instead.
type NoLossStrategy = CostBasisExitStrategytype StopLossStrategy
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
func NewStopLossStrategy(innerStrategy strategy.Strategy, percentage float64) *StopLossStrategyNewStopLossStrategy initializes an example StopLossStrategy instance with default parameters.
func (*StopLossStrategy) Compute
func (s *StopLossStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.ActionCompute 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.ActionComputeWithContext processes the provided asset snapshots and generates an illustrative stream of actions.
func (*StopLossStrategy) Name
func (s *StopLossStrategy) Name() stringName returns the name of the example strategy.
func (*StopLossStrategy) Report
func (s *StopLossStrategy) Report(c <-chan *asset.Snapshot) *helper.ReportReport processes the provided asset snapshots and generates an illustrative report annotated with example actions.
Generated by gomarkdoc