Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/talibcompat/talibcompat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ var testCases = []testCase{
go helper.Drain(lagging)
return outs(conversion, base, spanA, spanB)
}},
{name: "InternalBarStrength", columns: []string{"IBS"}, skip: "https://github.com/cinar/indicator/issues/532", compute: func(b *bars) []<-chan float64 {
{name: "InternalBarStrength", columns: []string{"IBS"}, compute: func(b *bars) []<-chan float64 {
return outs(momentum.NewInternalBarStrength[float64]().Compute(in(b.high), in(b.low), in(b.close)))
}},
{name: "Ppo", columns: []string{"PPO", "PPO_SIGNAL", "PPO_HIST"}, compute: func(b *bars) []<-chan float64 {
Expand Down
2 changes: 1 addition & 1 deletion momentum/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@ String is the string representation of the Ichimoku Cloud.
<a name="InternalBarStrength"></a>
## type [InternalBarStrength](<https://github.com/cinar/indicator/blob/master/momentum/ibs.go#L23>)

InternalBarStrength represents the parameters for calculating the Internal Bar Strength \(IBS\). It tracks price location within a daily high\-low range.
InternalBarStrength represents the parameters for calculating the Internal Bar Strength \(IBS\). It tracks price location within a daily high\-low range. Bars with no range return the neutral midpoint, 0.5.

```
IBS = (Close - Low) / (High - Low)
Expand Down
4 changes: 2 additions & 2 deletions momentum/ibs.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

// InternalBarStrength represents the parameters for calculating the
// Internal Bar Strength (IBS). It tracks price location within a daily
// high-low range.
// high-low range. Bars with no range return the neutral midpoint, 0.5.
//
// IBS = (Close - Low) / (High - Low)
//
Expand All @@ -31,7 +31,7 @@ func NewInternalBarStrength[T helper.Float]() *InternalBarStrength[T] {
func (ibs *InternalBarStrength[T]) ComputeWithContext(ctx context.Context, highs, lows, closings <-chan T) <-chan T {
return helper.Operate3WithContext(ctx, highs, lows, closings, func(high, low, closing T) T {
denom := high - low
return helper.SafeDivide(closing-low, denom, T(0))
return helper.SafeDivide(closing-low, denom, T(0.5))
})
}

Expand Down
17 changes: 15 additions & 2 deletions momentum/ibs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package momentum_test

import (
"context"
"testing"

"github.com/cinar/indicator/v2/helper"
Expand Down Expand Up @@ -68,7 +69,19 @@ func TestInternalBarStrengthZeroDenom(t *testing.T) {
actual := ibs.Compute(highs, lows, closings)

val := <-actual
if val != 0.0 {
t.Fatalf("expected 0.0 when high == low, got %f", val)
if val != 0.5 {
t.Fatalf("expected neutral 0.5 when high == low, got %f", val)
}
}

func TestInternalBarStrengthFlatBarsFloat32(t *testing.T) {
ibs := momentum.NewInternalBarStrength[float32]()
actual := ibs.ComputeWithContext(context.Background(),
helper.SliceToChan([]float32{100, 102, 100, 104}),
helper.SliceToChan([]float32{100, 100, 100, 100}),
helper.SliceToChan([]float32{100, 100, 100, 104}))
expected := helper.SliceToChan([]float32{0.5, 0, 0.5, 1})
if err := helper.CheckEquals(actual, expected); err != nil {
t.Fatal(err)
}
}
14 changes: 7 additions & 7 deletions volume/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ func (m *Mfi[T]) String() string
String is the string representation of the MFI.

<a name="Mfm"></a>
## type [Mfm](<https://github.com/cinar/indicator/blob/master/volume/mfm.go#L33>)
## type [Mfm](<https://github.com/cinar/indicator/blob/master/volume/mfm.go#L32>)

Mfm holds configuration parameters for calculating the Money Flow Multiplier \(MFM\), which adjusts volume based on the closing price's position within the high\-low range:

Expand All @@ -670,7 +670,7 @@ MFM = ((Closing - Low) - (High - Closing)) / (High - Low)

\- Positive MFM: Close in upper half of range, indicating buying pressure. \- Negative MFM: Close in lower half of range, indicating selling pressure. \- MFM of 1: Close equals high, strongest buying pressure. \- MFM of \-1: Close equals low, strongest selling pressure.

On a flat bar \(High == Low\), the close's position within the range is undefined \(0/0\). MFM returns 0, the neutral point of its \[\-1, 1\] scale, matching the InternalBarStrength precedent for the identical High\-Low denominator. Since MFM feeds Mfv, Ad, and Cmf, a neutral 0 flows through as "zero contribution" to all of them.
On a flat bar \(High == Low\), the close's position within the range is undefined \(0/0\). MFM returns 0, the neutral point of its \[\-1, 1\] scale. Since MFM feeds Mfv, Ad, and Cmf, a neutral 0 flows through as "zero contribution" to all of them.

Example:

Expand All @@ -684,7 +684,7 @@ type Mfm[T helper.Float] struct{}
```

<a name="NewMfm"></a>
### func [NewMfm](<https://github.com/cinar/indicator/blob/master/volume/mfm.go#L36>)
### func [NewMfm](<https://github.com/cinar/indicator/blob/master/volume/mfm.go#L35>)

```go
func NewMfm[T helper.Float]() *Mfm[T]
Expand All @@ -693,7 +693,7 @@ func NewMfm[T helper.Float]() *Mfm[T]
NewMfm function initializes a new MFM instance with the default parameters.

<a name="Mfm[T].Compute"></a>
### func \(\*Mfm\[T\]\) [Compute](<https://github.com/cinar/indicator/blob/master/volume/mfm.go#L61>)
### func \(\*Mfm\[T\]\) [Compute](<https://github.com/cinar/indicator/blob/master/volume/mfm.go#L60>)

```go
func (i *Mfm[T]) Compute(highs, lows, closings <-chan T) <-chan T
Expand All @@ -704,7 +704,7 @@ Compute wraps ComputeWithContext for backwards compatibility.
Deprecated: Use ComputeWithContext instead.

<a name="Mfm[T].ComputeWithContext"></a>
### func \(\*Mfm\[T\]\) [ComputeWithContext](<https://github.com/cinar/indicator/blob/master/volume/mfm.go#L41>)
### func \(\*Mfm\[T\]\) [ComputeWithContext](<https://github.com/cinar/indicator/blob/master/volume/mfm.go#L40>)

```go
func (i *Mfm[T]) ComputeWithContext(ctx context.Context, highs, lows, closings <-chan T) <-chan T
Expand All @@ -713,7 +713,7 @@ func (i *Mfm[T]) ComputeWithContext(ctx context.Context, highs, lows, closings <
ComputeWithContext function takes a channel of numbers and computes the MFM.

<a name="Mfm[T].IdlePeriod"></a>
### func \(\*Mfm\[T\]\) [IdlePeriod](<https://github.com/cinar/indicator/blob/master/volume/mfm.go#L49>)
### func \(\*Mfm\[T\]\) [IdlePeriod](<https://github.com/cinar/indicator/blob/master/volume/mfm.go#L48>)

```go
func (*Mfm[T]) IdlePeriod() int
Expand All @@ -722,7 +722,7 @@ func (*Mfm[T]) IdlePeriod() int
IdlePeriod is the initial period that MFM won't yield any results.

<a name="Mfm[T].String"></a>
### func \(\*Mfm\[T\]\) [String](<https://github.com/cinar/indicator/blob/master/volume/mfm.go#L54>)
### func \(\*Mfm\[T\]\) [String](<https://github.com/cinar/indicator/blob/master/volume/mfm.go#L53>)

```go
func (*Mfm[T]) String() string
Expand Down
7 changes: 3 additions & 4 deletions volume/mfm.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ import (
// - MFM of -1: Close equals low, strongest selling pressure.
//
// On a flat bar (High == Low), the close's position within the range is undefined
// (0/0). MFM returns 0, the neutral point of its [-1, 1] scale, matching the
// InternalBarStrength precedent for the identical High-Low denominator. Since MFM
// feeds Mfv, Ad, and Cmf, a neutral 0 flows through as "zero contribution" to all
// of them.
// (0/0). MFM returns 0, the neutral point of its [-1, 1] scale. Since MFM feeds
// Mfv, Ad, and Cmf, a neutral 0 flows through as "zero contribution" to all of
// them.
//
// Example:
//
Expand Down
Loading