-
Notifications
You must be signed in to change notification settings - Fork 1
/
candle.go
66 lines (56 loc) · 1.07 KB
/
candle.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
package candlePrintGo
type Candle interface {
Open() float64
High() float64
Low() float64
Close() float64
// Top returns what is the top of the candle either Open or Close
Top() float64
// Bottom returns what is the bottom of the candle either Open or Close
Bottom() float64
// IsBullish check the tendency of the candle
IsBullish() bool
}
type CandleBar struct {
isBullish bool
open float64
high float64
low float64
close float64
}
func NewCandleBar(o, h, l, c float64) *CandleBar {
return &CandleBar{
isBullish: c > o,
open: o,
high: h,
low: l,
close: c,
}
}
func (c CandleBar) Open() float64 {
return c.open
}
func (c CandleBar) High() float64 {
return c.high
}
func (c CandleBar) Low() float64 {
return c.low
}
func (c CandleBar) Close() float64 {
return c.close
}
func (c CandleBar) IsBullish() bool {
return c.isBullish
}
func (c CandleBar) Top() float64 {
if c.IsBullish() {
return c.close
}
return c.open
}
func (c CandleBar) Bottom() float64 {
if c.IsBullish() {
return c.open
}
return c.close
}