Skip to content

Commit

Permalink
Issue 41 Fixing Money Flow Index. (#42)
Browse files Browse the repository at this point in the history
* Fixing Money Flow Index Issue #41.

* New test.
  • Loading branch information
cinar authored Jan 25, 2022
1 parent b4245e5 commit cef5249
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion volume_indicators.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func MoneyFlowIndex(period int, high, low, closing []float64, volume []int64) []

moneyRatio := divide(
Sum(period, positiveMoneyFlow),
Sum(period, negativeMoneyFlow))
Sum(period, multiplyBy(negativeMoneyFlow, -1)))

moneyFlowIndex := addBy(multiplyBy(pow(addBy(moneyRatio, 1), -1), -100), 100)

Expand Down
14 changes: 13 additions & 1 deletion volume_indicators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,25 @@ func TestMoneyFlowIndex(t *testing.T) {
low := []float64{6, 7, 9, 12, 10}
closing := []float64{9, 11, 7, 10, 8}
volume := []int64{100, 110, 80, 120, 90}
expected := []float64{100, 100, 406.85, 207.69, 266.67}
expected := []float64{100, 100, 57.01, 65.85, 61.54}
period := 2

actual := roundDigitsAll(MoneyFlowIndex(period, high, low, closing, volume), 2)
testEquals(t, actual, expected)
}

func TestMoneyFlowIndex2(t *testing.T) {
high := []float64{2390.9, 2386.3, 2395.33, 2399.0, 2402.46, 2401.15, 2421.98, 2430.31, 2426.33, 2434.93, 2470.83, 2483.36, 2467.19, 2450.72}
low := []float64{2373.15, 2370.0, 2380.77, 2384.28, 2387.46, 2385.02, 2383.18, 2408.39, 2410.59, 2420.89, 2428.92, 2456.77, 2437.65, 2440.87}
closing := []float64{2373.39, 2382.47, 2394.4, 2387.51, 2395.64, 2389.47, 2410.24, 2425.37, 2422.33, 2430.29, 2465.76, 2466.27, 2440.07, 2445.85}
volume := []int64{1621, 1387, 1444, 1298, 1629, 1598, 2311, 2934, 2128, 1823, 5078, 6693, 3960, 1927}
expected := []float64{100, 53.884998, 68.888204, 53.300054, 63.645476, 52.296425, 62.119198, 70.011701, 60.826077, 54.659774, 64.728457, 72.749002, 64.185176, 60.710993}
period := 14

actual := roundDigitsAll(MoneyFlowIndex(period, high, low, closing, volume), 6)
testEquals(t, actual, expected)
}

func TestForceIndex(t *testing.T) {
closing := []float64{9, 11, 7, 10, 8}
volume := []int64{100, 110, 80, 120, 90}
Expand Down

0 comments on commit cef5249

Please sign in to comment.