forked from cinar/indicator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
momentum_strategies.go
76 lines (61 loc) · 1.59 KB
/
momentum_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
// Copyright (c) 2021 Onur Cinar. All Rights Reserved.
// The source code is provided under MIT License.
//
// https://github.com/cinar/indicator
package indicator
// Awesome oscillator strategy function.
func AwesomeOscillatorStrategy(asset Asset) []Action {
actions := make([]Action, len(asset.Date))
ao := AwesomeOscillator(asset.Low, asset.High)
for i := 0; i < len(actions); i++ {
if ao[i] > 0 {
actions[i] = BUY
} else if ao[i] < 0 {
actions[i] = SELL
} else {
actions[i] = HOLD
}
}
return actions
}
// RSI strategy. Sells above sell at, buys below buy at.
func RsiStrategy(asset Asset, sellAt, buyAt float64) []Action {
actions := make([]Action, len(asset.Date))
_, rsi := Rsi(asset.Closing)
for i := 0; i < len(actions); i++ {
if rsi[i] <= buyAt {
actions[i] = BUY
} else if rsi[i] >= sellAt {
actions[i] = SELL
} else {
actions[i] = HOLD
}
}
return actions
}
// Default RSI strategy function. It buys
// below 30 and sells above 70.
func DefaultRsiStrategy(asset Asset) []Action {
return RsiStrategy(asset, 70, 30)
}
// Make RSI strategy function.
func MakeRsiStrategy(sellAt, buyAt float64) StrategyFunction {
return func(asset Asset) []Action {
return RsiStrategy(asset, sellAt, buyAt)
}
}
// Williams R strategy function.
func WilliamsRStrategy(asset Asset) []Action {
actions := make([]Action, len(asset.Date))
wr := WilliamsR(asset.Low, asset.High, asset.Closing)
for i := 0; i < len(actions); i++ {
if wr[i] < -20 {
actions[i] = SELL
} else if wr[i] > -80 {
actions[i] = BUY
} else {
actions[i] = HOLD
}
}
return actions
}