-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
candle.py
176 lines (136 loc) · 3.67 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
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
from decimal import Decimal
class Candle(object):
bar = None
tenkan = 0.0
kijun = 0.0
senkouA = 0.0
senkouB = 0.0
pattern_long = None
pattern_short = None
def __init__(self, bar, tenkan, kijun, senkouA, senkouB, pattern_long=None, pattern_short=None):
self.bar = bar
self.tenkan = tenkan
self.kijun = kijun
self.senkouA = senkouA
self.senkouB = senkouB
self.pattern_long = pattern_long
self.pattern_short = pattern_short
@property
def Open(self):
return self.bar.Open
@property
def High(self):
return self.bar.High
@property
def Low(self):
return self.bar.Low
@property
def Close(self):
return self.bar.Close
@property
def Time(self):
return self.bar.EndTime
@property
def Tenkan(self):
return self.tenkan
@property
def Kijun(self):
return self.kijun
@property
def SenkouA(self):
return self.senkouA
@property
def SenkouB(self):
return self.senkouB
@property
def Chikou(self):
return self.bar.Close
@property
def OC(self):
return self.bar.Close - self.bar.Open
@property
def HL(self):
return self.bar.High - self.bar.Low
@property
def Kumo(self):
return self.SenkouA - self.SenkouB
@property
def KijunSenkouA(self):
return self.Kijun - self.SenkouA
@property
def KijunSenkouB(self):
return self.Kijun - self.SenkouB
@property
def KijunTenkan(self):
return abs(self.Kijun - self.Tenkan)
@property
def KijunClose(self):
return abs(self.Kijun - self.Close)
@property
def KijunOpen(self):
return abs(self.Kijun - self.Open)
@property
def SenkouAOpen(self):
return abs(self.SenkouA - self.Open)
@property
def SenkouBOpen(self):
return abs(self.SenkouA - self.Open)
@property
def isCloseBelowTenkan(self):
return self.Close < self.Tenkan
@property
def isCloseBelowKijun(self):
return self.Close < self.Kijun
@property
def isCloseAboveTenkan(self):
return self.Close > self.Tenkan
@property
def isCloseAboveKijun(self):
return self.Close > self.Kijun
@property
def isOpenBelowTenkan(self):
return self.Open < self.Tenkan
@property
def isOpenBelowKijun(self):
return self.Open < self.Kijun
@property
def isOpenAboveTenkan(self):
return self.Open > self.Tenkan
@property
def isOpenAboveKijun(self):
return self.Open > self.Kijun
@property
def isTenkanBelowKijun(self):
return self.Tenkan < self.Kijun
@property
def isTenkanAboveKijun(self):
return self.Tenkan > self.Kijun
@property
def MiddleOfBody(self):
if (self.HL - abs(self.OC)) < (self.HL * Decimal(0.4)):
thirty = abs(self.OC) / Decimal(3)
return (self.Low + thirty), (self.High - thirty)
return None
@property
def patternLongValue(self):
if self.pattern_long:
return self.pattern_long.Current.Value
return 0
@property
def patternShortValue(self):
if self.pattern_short:
return self.pattern_short.Current.Value
return 0
@property
def isPatternDown(self):
return self.patternShortValue == -1.0 and self.OC <= 0.0
@property
def isPatternUp(self):
return self.patternLongValue == 1.0 and self.OC >= 0.0
# close and ichimoku
@property
def isDown(self):
return self.OC < 0
@property
def isUp(self):
return self.OC > 0