Skip to content

Commit

Permalink
Bollinger Bands strategy moved to operate3.
Browse files Browse the repository at this point in the history
  • Loading branch information
cinar committed Jan 2, 2024
1 parent 9dd5e4b commit 920be6d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 18 deletions.
2 changes: 1 addition & 1 deletion strategy/volatility/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (*BollingerBandsStrategy) Name() string
Name returns the name of the strategy.

<a name="BollingerBandsStrategy.Report"></a>
### func \(\*BollingerBandsStrategy\) [Report](<https://github.com/cinar/indicator/blob/v2/strategy/volatility/bollinger_bands_strategy.go#L82>)
### func \(\*BollingerBandsStrategy\) [Report](<https://github.com/cinar/indicator/blob/v2/strategy/volatility/bollinger_bands_strategy.go#L69>)

```go
func (b *BollingerBandsStrategy) Report(c <-chan *asset.Snapshot) *helper.Report
Expand Down
21 changes: 4 additions & 17 deletions strategy/volatility/bollinger_bands_strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,33 +37,20 @@ func (*BollingerBandsStrategy) Name() string {
func (b *BollingerBandsStrategy) Compute(snapshots <-chan *asset.Snapshot) <-chan strategy.Action {
closings := helper.Duplicate(
asset.SnapshotsAsClosings(snapshots),
3,
2,
)

uppers, middles, lowers := b.BollingerBands.Compute(closings[0])

go helper.Drain(middles)

closings[1] = helper.Skip(closings[1], b.BollingerBands.IdlePeriod())

aboveUppers := helper.Subtract(
closings[1],
uppers,
)

closings[2] = helper.Skip(closings[2], b.BollingerBands.IdlePeriod())

belowLowers := helper.Subtract(
closings[2],
lowers,
)

actions := helper.Operate(aboveUppers, belowLowers, func(aboveUpper, belowLower float64) strategy.Action {
if aboveUpper > 0 {
actions := helper.Operate3(uppers, lowers, closings[1], func(upper, lower, closing float64) strategy.Action {
if closing > upper {
return strategy.Buy
}

if belowLower < 0 {
if lower > closing {
return strategy.Sell
}

Expand Down

0 comments on commit 920be6d

Please sign in to comment.