@@ -41,6 +41,7 @@ The information provided on this project is strictly for informational purposes
41
41
- [ func \( b \* BollingerBandWidth\[ T\]\) IdlePeriod\(\) int] ( < #BollingerBandWidth[T].IdlePeriod > )
42
42
- [ type BollingerBands] ( < #BollingerBands > )
43
43
- [ func NewBollingerBands\[ T helper.Number\]\(\) \* BollingerBands\[ T\] ] ( < #NewBollingerBands > )
44
+ - [ func NewBollingerBandsWithPeriod\[ T helper.Number\]\( period int\) \* BollingerBands\[ T\] ] ( < #NewBollingerBandsWithPeriod > )
44
45
- [ func \( b \* BollingerBands\[ T\]\) Compute\( c \<\- chan T\) \(\<\- chan T, \<\- chan T, \<\- chan T\) ] ( < #BollingerBands[T].Compute > )
45
46
- [ func \( b \* BollingerBands\[ T\]\) IdlePeriod\(\) int] ( < #BollingerBands[T].IdlePeriod > )
46
47
- [ type ChandelierExit] ( < #ChandelierExit > )
@@ -62,6 +63,12 @@ The information provided on this project is strictly for informational purposes
62
63
- [ func NewMovingStdWithPeriod\[ T helper.Number\]\( period int\) \* MovingStd\[ T\] ] ( < #NewMovingStdWithPeriod > )
63
64
- [ func \( m \* MovingStd\[ T\]\) Compute\( c \<\- chan T\) \<\- chan T] ( < #MovingStd[T].Compute > )
64
65
- [ func \( m \* MovingStd\[ T\]\) IdlePeriod\(\) int] ( < #MovingStd[T].IdlePeriod > )
66
+ - [ type PercentB] ( < #PercentB > )
67
+ - [ func NewPercentB\[ T helper.Number\]\(\) \* PercentB\[ T\] ] ( < #NewPercentB > )
68
+ - [ func NewPercentBWithPeriod\[ T helper.Number\]\( period int\) \* PercentB\[ T\] ] ( < #NewPercentBWithPeriod > )
69
+ - [ func \( p \* PercentB\[ T\]\) Compute\( closings \<\- chan T\) \<\- chan T] ( < #PercentB[T].Compute > )
70
+ - [ func \( p \* PercentB\[ T\]\) IdlePeriod\(\) int] ( < #PercentB[T].IdlePeriod > )
71
+ - [ func \( p \* PercentB\[ T\]\) String\(\) string] ( < #PercentB[T].String > )
65
72
- [ type Po] ( < #Po > )
66
73
- [ func NewPo\[ T helper.Number\]\(\) \* Po\[ T\] ] ( < #NewPo > )
67
74
- [ func NewPoWithPeriod\[ T helper.Number\]\( period int\) \* Po\[ T\] ] ( < #NewPoWithPeriod > )
@@ -386,8 +393,17 @@ func NewBollingerBands[T helper.Number]() *BollingerBands[T]
386
393
387
394
NewBollingerBands function initializes a new Bollinger Bands instance with the default parameters.
388
395
396
+ <a name =" NewBollingerBandsWithPeriod " ></a >
397
+ ### func [ NewBollingerBandsWithPeriod] ( < https://github.com/cinar/indicator/blob/master/volatility/bollinger_bands.go#L40 > )
398
+
399
+ ``` go
400
+ func NewBollingerBandsWithPeriod [T helper.Number ](period int ) *BollingerBands[T]
401
+ ```
402
+
403
+ NewBollingerBandsWithPeriod function initializes a new Bollinger Bands instance with the given period.
404
+
389
405
<a name =" BollingerBands[T].Compute " ></a >
390
- ### func \(\* BollingerBands\[ T\]\) [ Compute] ( < https://github.com/cinar/indicator/blob/master/volatility/bollinger_bands.go#L42 > )
406
+ ### func \(\* BollingerBands\[ T\]\) [ Compute] ( < https://github.com/cinar/indicator/blob/master/volatility/bollinger_bands.go#L47 > )
391
407
392
408
``` go
393
409
func (b *BollingerBands [T ]) Compute (c <-chan T ) (<-chan T , <-chan T , <-chan T )
@@ -396,7 +412,7 @@ func (b *BollingerBands[T]) Compute(c <-chan T) (<-chan T, <-chan T, <-chan T)
396
412
Compute function takes a channel of numbers and computes the Bollinger Bands over the specified period.
397
413
398
414
<a name="BollingerBands[T].IdlePeriod"></a>
399
- ### func \(\*BollingerBands\[T\]\) [IdlePeriod](<https:// github.com/cinar/indicator/blob/master/volatility/bollinger_bands.go#L74 >)
415
+ ### func \(\*BollingerBands\[T\]\) [IdlePeriod](<https:// github.com/cinar/indicator/blob/master/volatility/bollinger_bands.go#L79 >)
400
416
401
417
```go
402
418
func (b *BollingerBands[T]) IdlePeriod() int
@@ -638,6 +654,113 @@ func (m *MovingStd[T]) IdlePeriod() int
638
654
639
655
IdlePeriod is the initial period that Moving Standard Deviation won't yield any results.
640
656
657
+ <a name="PercentB"></a>
658
+ ## type [PercentB](<https:// github.com/cinar/indicator/blob/master/volatility/percent_b.go#L16-L19>)
659
+
660
+ PercentB represents the parameters for calculating the %B indicator.
661
+
662
+ ```
663
+ %B = (Close - Lower Band) / (Upper Band - Lower Band)
664
+ ```
665
+
666
+ ```go
667
+ type PercentB[T helper.Number] struct {
668
+ // BollingerBands is the underlying Bollinger Bands indicator used for calculations.
669
+ BollingerBands *BollingerBands[T]
670
+ }
671
+ ```
672
+
673
+ <details ><summary >Example</summary >
674
+ <p >
675
+
676
+
677
+
678
+ ``` go
679
+ package main
680
+
681
+ import (
682
+ " fmt"
683
+
684
+ " github.com/cinar/indicator/v2/helper"
685
+ " github.com/cinar/indicator/v2/volatility"
686
+ )
687
+
688
+ func main () {
689
+ // Closing prices
690
+ closes := helper.SliceToChan ([]float64 {
691
+ 318.600006 , 315.839996 , 316.149994 , 310.570007 , 307.779999 ,
692
+ 305.820007 , 305.98999 , 306.390015 , 311.450012 , 312.329987 ,
693
+ 309.290009 , 301.910004 , 300 , 300.029999 , 302 ,
694
+ 307.820007 , 302.690002 , 306.48999 , 305.549988 , 303.429993 ,
695
+ })
696
+
697
+ // Initialize the %B indicator
698
+ percentB := volatility.NewPercentB [float64 ]()
699
+
700
+ // Compute %B
701
+ result := percentB.Compute (closes)
702
+
703
+ // Round digits
704
+ result = helper.RoundDigits (result, 2 )
705
+
706
+ fmt.Println (helper.ChanToSlice (result))
707
+ }
708
+ ```
709
+
710
+ #### Output
711
+
712
+ ```
713
+ [0.3]
714
+ ```
715
+
716
+ </p >
717
+ </details >
718
+
719
+ <a name =" NewPercentB " ></a >
720
+ ### func [ NewPercentB] ( < https://github.com/cinar/indicator/blob/master/volatility/percent_b.go#L22 > )
721
+
722
+ ``` go
723
+ func NewPercentB [T helper.Number ]() *PercentB[T]
724
+ ```
725
+
726
+ NewPercentB function initializes a new %B instance with the default parameters.
727
+
728
+ <a name =" NewPercentBWithPeriod " ></a >
729
+ ### func [ NewPercentBWithPeriod] ( < https://github.com/cinar/indicator/blob/master/volatility/percent_b.go#L27 > )
730
+
731
+ ``` go
732
+ func NewPercentBWithPeriod [T helper.Number ](period int ) *PercentB[T]
733
+ ```
734
+
735
+ NewPercentBWithPeriod function initializes a new %B instance with the given period.
736
+
737
+ <a name =" PercentB[T].Compute " ></a >
738
+ ### func \(\* PercentB\[ T\]\) [ Compute] ( < https://github.com/cinar/indicator/blob/master/volatility/percent_b.go#L34 > )
739
+
740
+ ``` go
741
+ func (p *PercentB [T ]) Compute (closings <-chan T ) <-chan T
742
+ ```
743
+
744
+ Compute function takes a channel of numbers and computes the %B over the specified period.
745
+
746
+ <a name="PercentB[T].IdlePeriod"></a>
747
+ ### func \(\*PercentB\[T\]\) [IdlePeriod](<https:// github.com/cinar/indicator/blob/master/volatility/percent_b.go#L53>)
748
+
749
+ ```go
750
+ func (p *PercentB[T]) IdlePeriod() int
751
+ ```
752
+
753
+ IdlePeriod is the initial period that %B yield any results.
754
+
755
+ <a name="PercentB[T].String"></a>
756
+ ### func \(\*PercentB\[T\]\) [String](<https:// github.com/cinar/indicator/blob/master/volatility/percent_b.go#L58>)
757
+
758
+ ```go
759
+ func (p *PercentB[T]) String() string
760
+ ```
761
+
762
+ String is the string representation of the %B.
763
+
641
764
<a name="Po"></a>
642
765
## type [Po](<https:// github.com/cinar/indicator/blob/master/volatility/po.go#L28-L37>)
643
766
0 commit comments