-
Notifications
You must be signed in to change notification settings - Fork 0
/
candle_type.py
17 lines (15 loc) · 961 Bytes
/
candle_type.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
def candle_type(o, h, l, c):
diff = abs(c - o) # body size
o1, c1 = np.roll(o, 1), np.roll(c, 1) # previous day open and close
min_oc = np.where(o < c, o, c) # smallest of open and close is used .
max_oc = np.where(o > c, o, c) # greatest of open and close is used .
pattern = np.where(
np.logical_and( min_oc - l > diff, h - max_oc < diff), ' Hammer',
np.where(np.logical_and( h - max_oc > diff, min_oc - l < diff),
' Inverted Hammer', np.where(np.logical_and(np.logical_and(c > o, c1 < o1), np.logical_and(c > o1, o < c1)),
' Bullish Engulfing', np.where( min_oc - l > diff, ' Hanging Man',
np.where(np.logical_and( h - max_oc > diff,
min_oc - l < diff),
' Shooting Star', np.where(np.logical_and(np.logical_and(c > o, c1 < o1), np.logical_and(c > o1, o < c1)),
' Bearish Engulfing', ' None'))))))
return pattern