From 920be6d7d2e8a4a3343919ca85ec36a0d9a7b266 Mon Sep 17 00:00:00 2001 From: Onur Cinar Date: Tue, 2 Jan 2024 07:06:06 -0800 Subject: [PATCH] Bollinger Bands strategy moved to operate3. --- strategy/volatility/README.md | 2 +- .../volatility/bollinger_bands_strategy.go | 21 ++++--------------- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/strategy/volatility/README.md b/strategy/volatility/README.md index 10ea811..3204ed9 100644 --- a/strategy/volatility/README.md +++ b/strategy/volatility/README.md @@ -83,7 +83,7 @@ func (*BollingerBandsStrategy) Name() string Name returns the name of the strategy. -### func \(\*BollingerBandsStrategy\) [Report]() +### func \(\*BollingerBandsStrategy\) [Report]() ```go func (b *BollingerBandsStrategy) Report(c <-chan *asset.Snapshot) *helper.Report diff --git a/strategy/volatility/bollinger_bands_strategy.go b/strategy/volatility/bollinger_bands_strategy.go index 06a3fba..fb2b75f 100644 --- a/strategy/volatility/bollinger_bands_strategy.go +++ b/strategy/volatility/bollinger_bands_strategy.go @@ -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 }