-
Notifications
You must be signed in to change notification settings - Fork 0
/
strategies.go
160 lines (146 loc) · 3.95 KB
/
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package quota
// ScoreByAbove scores candles by checking if candles are above source.
func (q *Quota) ScoreByAbove(source Source, score float64) {
// loop through quote
for _, candle := range *q {
if candle.IsAbove(source) {
candle.Score += score
}
}
}
// ScoreByTouchUp scores candles by checking if candles are touching up source.
func (q *Quota) ScoreByTouchUp(source Source, score float64) {
// loop through quote
for _, candle := range *q {
if candle.TouchedUp(source) {
candle.Score += score
}
}
}
// ScoreByMiddle scores candles by checking if candles are middle of the source.
func (q *Quota) ScoreByMiddle(source Source, score float64) {
// loop through quote
for _, candle := range *q {
if candle.IsMiddle(source) {
candle.Score += score
}
}
}
// ScoreByTouchDown scores candles by checking if candles are touching down source.
func (q *Quota) ScoreByTouchDown(source Source, score float64) {
// loop through quote
for _, candle := range *q {
if candle.TouchedDown(source) {
candle.Score += score
}
}
}
// ScoreByBelow scores candles by checking if candles are below source.
func (q *Quota) ScoreByBelow(source Source, score float64) {
// loop through quote
for _, candle := range *q {
if candle.IsBelow(source) {
candle.Score += score
}
}
}
// ScoreByCrossOver scores candles by checking sources cross over condition on each of them.
func (q *Quota) ScoreByCrossOver(fastSource, slowSource Source, score float64) {
// loop through quote
for _, candle := range *q {
if candle.CrossedOver(fastSource, slowSource) {
candle.Score += score
}
}
}
// ScoreByCrossUnder scores candles by checking sources cross under condition on each of them.
func (q *Quota) ScoreByCrossUnder(fastSource, slowSource Source, score float64) {
// loop through quote
for _, candle := range *q {
if candle.CrossedUnder(fastSource, slowSource) {
candle.Score += score
}
}
}
// ScoreByCross scores candles by checking sources both crosses over and under condition on each of them.
func (q *Quota) ScoreByCross(fastSource, slowSource Source, score float64) {
// loop through quote
for _, candle := range *q {
if candle.CrossedOver(fastSource, slowSource) {
candle.Score += score
}
if candle.CrossedUnder(fastSource, slowSource) {
candle.Score -= score
}
}
}
// ScoreByBearish scores candles by if candle is bearish
func (q *Quota) ScoreByBearish(score float64) {
// loop through quote
for _, candle := range *q {
if candle.IsBearish() {
candle.Score += score
}
}
}
// ScoreByBullish scores candles by checking if candles are bullish.
func (q *Quota) ScoreByBullish(score float64) {
// loop through quote
for _, candle := range *q {
if candle.IsBullish() {
candle.Score += score
}
}
}
// ScoreBySupportResistance scores candles by checking support/resistance line reaction.
func (q *Quota) ScoreBySupportResistance(source Source, score float64) {
// loop through quote
for _, candle := range *q {
checker := func(c *Candle) float64 {
if c.IsBearish() {
score *= -1
}
if c.TouchedDown(source) || c.IsMiddle(source) || c.IsMiddle(source) {
return score
}
return 0
}
result := checker(candle)
if result != 0 {
candle.Score += result
}
if candle.Previous == nil {
continue
}
prevResult := checker(candle.Previous)
if prevResult*-1 == result {
candle.Score += result
}
}
}
// ScoreByBands scores candles by checking touching and turning back into the band.
func (q *Quota) ScoreByBands(source Source, score float64) {
// loop through quote
for _, candle := range *q {
checker := func(c *Candle) float64 {
if c.IsBearish() {
score *= -1
}
if c.TouchedDown(source) || c.IsMiddle(source) || c.IsMiddle(source) {
return score
}
return 0
}
result := checker(candle)
if result != 0 {
candle.Score += result
}
if candle.Previous == nil {
continue
}
prevResult := checker(candle.Previous)
if prevResult*-1 == result {
candle.Score += result
}
}
}