-
Notifications
You must be signed in to change notification settings - Fork 0
/
conditions.go
125 lines (107 loc) · 2.82 KB
/
conditions.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
package quota
// IsAbove checks if candle is above of the source.
//
// O,H,L,C > source
func (c *Candle) IsAbove(source Source) bool {
value, _ := c.Get(source)
return c.Open > value && c.High > value && c.Low > value && c.Close > value
}
// IsBelow checks if candle is below of the source.
//
// O,H,L,C < source
func (c *Candle) IsBelow(source Source) bool {
value, _ := c.Get(source)
return c.Open < value && c.High < value && c.Low < value && c.Close < value
}
// IsMiddle checks if source is passed through middle of the candle.
//
// O >= source
// H > source
// L < source
// C <= source
func (c *Candle) IsMiddle(source Source) bool {
value, _ := c.Get(source)
return c.Open >= value && c.High > value && c.Low < value && c.Close <= value
}
// TouchedDown checks if candle closed above the source but the Low shadow touched the source.
//
// O,H,C > source
// L <= source
func (c *Candle) TouchedDown(source Source) bool {
value, _ := c.Get(source)
return c.Open > value && c.High > value && c.Low <= value && c.Close > value
}
// TouchedUp checks if candle close above the source but the High shadow touched the source.
//
// H >= source
// O,L,C < source
func (c *Candle) TouchedUp(source Source) bool {
value, _ := c.Get(source)
return c.Open < value && c.High >= value && c.Low < value && c.Close < value
}
// CrossedOver checks if fast source crossed over the slow source.
//
// fastSource > slowSource
// prevFastSource <= prevSlowSource
func (c *Candle) CrossedOver(fastSource, slowSource Source) bool {
previousCandle := c.Previous
if previousCandle == nil {
return false
}
fastValue, ok := c.Get(fastSource)
if !ok {
return false
}
slowValue, ok := c.Get(slowSource)
if !ok {
return false
}
previousFastValue, ok := previousCandle.Get(fastSource)
if !ok {
return false
}
previousSlowValue, ok := previousCandle.Get(slowSource)
if !ok {
return false
}
return fastValue > slowValue && previousFastValue <= previousSlowValue
}
// CrossedUnder checks if fast source crossed under the slow source.
//
// fastSource < slowSource
// prevFastSource >= prevSlowSource
func (c *Candle) CrossedUnder(fastSource, slowSource Source) bool {
previousCandle := c.Previous
if previousCandle == nil {
return false
}
fastValue, ok := c.Get(fastSource)
if !ok {
return false
}
slowValue, ok := c.Get(slowSource)
if !ok {
return false
}
previousFastValue, ok := previousCandle.Get(fastSource)
if !ok {
return false
}
previousSlowValue, ok := previousCandle.Get(slowSource)
if !ok {
return false
}
return fastValue < slowValue && previousFastValue >= previousSlowValue
}
// IsBearish checks if candle is bearish.
//
// O < C,
func (c *Candle) IsBearish() bool {
return c.Open < c.Close
}
// IsBullish checks if candle is bullish.
//
// O > C,
func (c *Candle) IsBullish() bool {
return c.Open > c.Close
}