Skip to content

Commit

Permalink
True Strength Index (TSI) strategy is added.
Browse files Browse the repository at this point in the history
  • Loading branch information
cinar committed Jun 10, 2024
1 parent 29f5bf6 commit df36456
Show file tree
Hide file tree
Showing 6 changed files with 547 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ The following list of strategies are currently supported by this package:
- [Triangular Moving Average (TRIMA) Strategy](strategy/trend/README.md#type-trimastrategy)
- [Triple Exponential Average (TRIX) Strategy](strategy/trend/README.md#type-trixstrategy)
- [Triple Moving Average Crossover Strategy](strategy/trend/README.md#type-triplemovingaveragecrossoverstrategy)
- [True Strength Index (TSI) Strategy](strategy/trend/README.md#type-tsistrategy)
- [Volume Weighted Moving Average (VWMA) Strategy](strategy/trend/README.md#type-vwmastrategy)

### 🚀 Momentum Strategies
Expand Down
91 changes: 91 additions & 0 deletions strategy/trend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ The information provided on this project is strictly for informational purposes
- [func \(t \*TrixStrategy\) Compute\(snapshots \<\-chan \*asset.Snapshot\) \<\-chan strategy.Action](<#TrixStrategy.Compute>)
- [func \(\*TrixStrategy\) Name\(\) string](<#TrixStrategy.Name>)
- [func \(t \*TrixStrategy\) Report\(c \<\-chan \*asset.Snapshot\) \*helper.Report](<#TrixStrategy.Report>)
- [type TsiStrategy](<#TsiStrategy>)
- [func NewTsiStrategy\(\) \*TsiStrategy](<#NewTsiStrategy>)
- [func NewTsiStrategyWith\(firstSmoothingPeriod, secondSmoothingPeriod, signalPeriod int\) \*TsiStrategy](<#NewTsiStrategyWith>)
- [func \(t \*TsiStrategy\) Compute\(snapshots \<\-chan \*asset.Snapshot\) \<\-chan strategy.Action](<#TsiStrategy.Compute>)
- [func \(t \*TsiStrategy\) IdlePeriod\(\) int](<#TsiStrategy.IdlePeriod>)
- [func \(t \*TsiStrategy\) Name\(\) string](<#TsiStrategy.Name>)
- [func \(t \*TsiStrategy\) Report\(c \<\-chan \*asset.Snapshot\) \*helper.Report](<#TsiStrategy.Report>)
- [type VwmaStrategy](<#VwmaStrategy>)
- [func NewVwmaStrategy\(\) \*VwmaStrategy](<#NewVwmaStrategy>)
- [func \(v \*VwmaStrategy\) Compute\(c \<\-chan \*asset.Snapshot\) \<\-chan strategy.Action](<#VwmaStrategy.Compute>)
Expand Down Expand Up @@ -155,6 +162,15 @@ const (
)
```

<a name="DefaultTsiStrategySignalPeriod"></a>

```go
const (
// DefaultTsiStrategySignalPeriod is the default signal line period of 12.
DefaultTsiStrategySignalPeriod = 12
)
```

<a name="DefaultVwmaStrategyPeriod"></a>

```go
Expand Down Expand Up @@ -875,6 +891,81 @@ func (t *TrixStrategy) Report(c <-chan *asset.Snapshot) *helper.Report

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

<a name="TsiStrategy"></a>
## type [TsiStrategy](<https://github.com/cinar/indicator/blob/master/strategy/trend/tsi_strategy.go#L28-L34>)

TsiStrategy represents the configuration parameters for calculating the TSI strategy. When the TSI is above zero and crossing above the signal line suggests a bullish trend, while TSI being below zero and crossing below the signal line indicates a bearish trend.

```
Signal Line = Ema(12, TSI)
When TSI > 0, TSI > Signal Line, Buy.
When TSI < 0, TSI < Signal Line, Sell.const
```

```go
type TsiStrategy struct {
// Tsi represents the configuration parameters for calculating the True Strength Index (TSI).
Tsi *trend.Tsi[float64]

// Signal line is the moving average of the TSI.
Signal trend.Ma[float64]
}
```

<a name="NewTsiStrategy"></a>
### func [NewTsiStrategy](<https://github.com/cinar/indicator/blob/master/strategy/trend/tsi_strategy.go#L37>)

```go
func NewTsiStrategy() *TsiStrategy
```

NewTsiStrategy function initializes a new TSI strategy instance.

<a name="NewTsiStrategyWith"></a>
### func [NewTsiStrategyWith](<https://github.com/cinar/indicator/blob/master/strategy/trend/tsi_strategy.go#L46>)

```go
func NewTsiStrategyWith(firstSmoothingPeriod, secondSmoothingPeriod, signalPeriod int) *TsiStrategy
```

NewTsiStrategyWith function initializes a new TSI strategy instance with the given parameters.

<a name="TsiStrategy.Compute"></a>
### func \(\*TsiStrategy\) [Compute](<https://github.com/cinar/indicator/blob/master/strategy/trend/tsi_strategy.go#L66>)

```go
func (t *TsiStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action
```

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

<a name="TsiStrategy.IdlePeriod"></a>
### func \(\*TsiStrategy\) [IdlePeriod](<https://github.com/cinar/indicator/blob/master/strategy/trend/tsi_strategy.go#L144>)

```go
func (t *TsiStrategy) IdlePeriod() int
```

IdlePeriod is the initial period that TSI strategy yield any results.

<a name="TsiStrategy.Name"></a>
### func \(\*TsiStrategy\) [Name](<https://github.com/cinar/indicator/blob/master/strategy/trend/tsi_strategy.go#L58>)

```go
func (t *TsiStrategy) Name() string
```

Name returns the name of the strategy.

<a name="TsiStrategy.Report"></a>
### func \(\*TsiStrategy\) [Report](<https://github.com/cinar/indicator/blob/master/strategy/trend/tsi_strategy.go#L96>)

```go
func (t *TsiStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
```

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

<a name="VwmaStrategy"></a>
## type [VwmaStrategy](<https://github.com/cinar/indicator/blob/master/strategy/trend/vwma_strategy.go#L22-L30>)

Expand Down
252 changes: 252 additions & 0 deletions strategy/trend/testdata/tsi_strategy.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
Action
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
-1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
-1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
1 change: 1 addition & 0 deletions strategy/trend/trend.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func AllStrategies() []strategy.Strategy {
NewQstickStrategy(),
NewTrimaStrategy(),
NewTripleMovingAverageCrossoverStrategy(),
NewTsiStrategy(),
NewVwmaStrategy(),
}
}
Loading

0 comments on commit df36456

Please sign in to comment.