-
Notifications
You must be signed in to change notification settings - Fork 1
/
candle.py
99 lines (73 loc) · 2.68 KB
/
candle.py
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
import configuration as config
class Candle:
def __init__(self, args):
self.id = args['id']
self.at = args['at']
self._from = args['from']
self.to = args['to']
self.open = args['open']
self.close = args['close']
self.max = args['max']
self.min = args['min']
self.volume = args['volume']
@property
def direction(self):
if self.open == self.close:
return 0
return -1 if self.open > self.close else 1
@property
def body_size(self):
return abs(self.force)
@property
def top(self):
return max(self.open, self.close)
@property
def bottom(self):
return min(self.open, self.close)
@property
def wick(self):
return self.max - self.top
@property
def shadow(self):
return self.bottom - self.min
@property
def force(self):
return ((self.close * 1000000) - (self.open * 1000000)) / 1000000
def is_high(self) -> bool:
return self.force > 0
def is_low(self) -> bool:
return self.force < 0
def volume_difference(self, average_volume) -> float:
return self.volume - average_volume
def volume_indication(self, average_volume) -> float:
return self.volume / average_volume
def body_size_difference(self, average_body_size) -> float:
return self.body_size - average_body_size
def body_size_indication(self, average_body_size) -> float:
return self.body_size / average_body_size
def is_shot(self, average_body_size) -> bool:
return self.body_size_indication(average_body_size) < config.SHORT_CANDLE
def is_long(self, average_body_size) -> bool:
return self.body_size_indication(average_body_size) > config.LONG_CANDLE
def top_invasion(self, candle) -> bool:
return candle.open > self.bottom and candle.open < self.top
def botton_invasion(self, candle) -> bool:
return candle.open > self.bottom and candle.close < self.top
def check_body_invasion(self, candle) -> bool:
return self.top_invasion(candle) or self.botton_invasion(candle)
def check_body_inclusion(self, candle) -> bool:
return self.top_invasion(candle) and self.botton_invasion(candle)
def is_hammer(self):
return (
self.body_size != 0 and
(self.shadow / self.body_size) > 2 and
(self.wick / self.body_size) < .5
)
def is_inverted_hammer(self):
return (
self.body_size != 0 and
(self.wick / self.body_size) > 2 and
(self.shadow / self.body_size) < .5
)
def is_doji(self):
return self.force == 0