forked from cinar/indicator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
volume_strategies.go
127 lines (102 loc) · 2.5 KB
/
volume_strategies.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Copyright (c) 2021 Onur Cinar. All Rights Reserved.
// The source code is provided under MIT License.
//
// https://github.com/cinar/indicator
package indicator
// Money flow index strategy.
func MoneyFlowIndexStrategy(asset Asset) []Action {
actions := make([]Action, len(asset.Date))
moneyFlowIndex := DefaultMoneyFlowIndex(
asset.High,
asset.Low,
asset.Closing,
asset.Volume)
for i := 0; i < len(actions); i++ {
if moneyFlowIndex[i] >= 80 {
actions[i] = SELL
} else {
actions[i] = BUY
}
}
return actions
}
// Force index strategy function.
func ForceIndexStrategy(asset Asset) []Action {
actions := make([]Action, len(asset.Date))
forceIndex := DefaultForceIndex(asset.Closing, asset.Volume)
for i := 0; i < len(actions); i++ {
if forceIndex[i] > 0 {
actions[i] = BUY
} else if forceIndex[i] < 0 {
actions[i] = SELL
} else {
actions[i] = HOLD
}
}
return actions
}
// Ease of movement strategy.
func EaseOfMovementStrategy(asset Asset) []Action {
actions := make([]Action, len(asset.Date))
emv := DefaultEaseOfMovement(asset.High, asset.Low, asset.Volume)
for i := 0; i < len(actions); i++ {
if emv[i] > 0 {
actions[i] = BUY
} else if emv[i] < 0 {
actions[i] = SELL
} else {
actions[i] = HOLD
}
}
return actions
}
// Volume weighted average price strategy function.
func VolumeWeightedAveragePriceStrategy(asset Asset) []Action {
actions := make([]Action, len(asset.Date))
vwap := DefaultVolumeWeightedAveragePrice(asset.Closing, asset.Volume)
for i := 0; i < len(actions); i++ {
if vwap[i] > asset.Closing[i] {
actions[i] = BUY
} else if vwap[i] < asset.Closing[i] {
actions[i] = SELL
} else {
actions[i] = HOLD
}
}
return actions
}
// Negative volume index strategy.
func NegativeVolumeIndexStrategy(asset Asset) []Action {
actions := make([]Action, len(asset.Date))
nvi := NegativeVolumeIndex(asset.Closing, asset.Volume)
nvi255 := Ema(255, nvi)
for i := 0; i < len(actions); i++ {
if nvi[i] < nvi255[i] {
actions[i] = BUY
} else if nvi[i] > nvi255[i] {
actions[i] = SELL
} else {
actions[i] = HOLD
}
}
return actions
}
// Chaikin money flow strategy.
func ChaikinMoneyFlowStrategy(asset Asset) []Action {
actions := make([]Action, len(asset.Date))
cmf := ChaikinMoneyFlow(
asset.High,
asset.Low,
asset.Closing,
asset.Volume)
for i := 0; i < len(actions); i++ {
if cmf[i] < 0 {
actions[i] = BUY
} else if cmf[i] > 0 {
actions[i] = SELL
} else {
actions[i] = HOLD
}
}
return actions
}