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
42 changes: 21 additions & 21 deletions strategy/volume/testdata/money_flow_index_strategy.csv
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Action
0
0
0
1
0
0
0
Expand Down Expand Up @@ -89,6 +90,15 @@ Action
0
0
0
-1
-1
-1
-1
-1
-1
-1
-1
-1
0
0
0
Expand Down Expand Up @@ -124,7 +134,11 @@ Action
0
0
0
-1
-1
0
-1
-1
0
0
0
Expand Down Expand Up @@ -180,6 +194,9 @@ Action
0
0
0
-1
-1
-1
0
0
0
Expand All @@ -193,8 +210,10 @@ Action
0
0
0
1
0
0
1
0
0
0
Expand Down Expand Up @@ -228,25 +247,6 @@ Action
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
-1
-1
0
14 changes: 8 additions & 6 deletions volume/mfi.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,17 @@ func NewMfiWithPeriod[T helper.Number](period int) *Mfi[T] {

// ComputeWithContext function takes a channel of numbers and computes the MFI.
func (m *Mfi[T]) ComputeWithContext(ctx context.Context, highs, lows, closings, volumes <-chan T) <-chan T {
// Raw Money Flow = Typical Price * Volume
rawMoneyFlowSplice := helper.DuplicateWithContext(ctx, helper.MultiplyWithContext(ctx, m.TypicalPrice.ComputeWithContext(ctx, highs, lows, closings),
volumes,
),
// TP = (High + Low + Close) / 3
tpSplice := helper.DuplicateWithContext(ctx,
m.TypicalPrice.ComputeWithContext(ctx, highs, lows, closings),
2,
)

moneyFlowSplice := helper.DuplicateWithContext(ctx, helper.MultiplyWithContext(ctx, helper.SignWithContext(ctx, helper.ChangeWithContext(ctx, rawMoneyFlowSplice[0], 1)),
helper.SkipWithContext(ctx, rawMoneyFlowSplice[1], 1),
// Raw Money Flow = Typical Price * Volume
rawMoneyFlow := helper.MultiplyWithContext(ctx, tpSplice[0], volumes)

moneyFlowSplice := helper.DuplicateWithContext(ctx, helper.MultiplyWithContext(ctx, helper.SignWithContext(ctx, helper.ChangeWithContext(ctx, tpSplice[1], 1)),
helper.SkipWithContext(ctx, rawMoneyFlow, 1),
),
2,
)
Expand Down
Loading
Loading