0
# Pattern Recognition
1
2
Candlestick pattern recognition functions that identify traditional Japanese candlestick patterns for technical analysis and trading signals. These functions analyze OHLC data to detect specific candlestick formations that may indicate potential price reversals or continuation patterns.
3
4
All pattern recognition functions return integer arrays where:
5
- **100**: Bullish pattern detected
6
- **-100**: Bearish pattern detected
7
- **0**: No pattern detected
8
9
## Capabilities
10
11
### Basic Candlestick Patterns
12
13
```python { .api }
14
def CDLDOJI(open, high, low, close):
15
"""
16
Doji - Indecision pattern where open and close are nearly equal
17
18
Parameters:
19
- open: array-like, open prices
20
- high: array-like, high prices
21
- low: array-like, low prices
22
- close: array-like, close prices
23
24
Returns:
25
numpy.ndarray[int32]: Pattern signals (100, -100, or 0)
26
"""
27
28
def CDLHAMMER(open, high, low, close):
29
"""
30
Hammer - Bullish reversal pattern with small body and long lower shadow
31
"""
32
33
def CDLHANGINGMAN(open, high, low, close):
34
"""
35
Hanging Man - Bearish reversal pattern with small body and long lower shadow
36
"""
37
38
def CDLINVERTEDHAMMER(open, high, low, close):
39
"""
40
Inverted Hammer - Bullish reversal pattern with small body and long upper shadow
41
"""
42
43
def CDLSHOOTINGSTAR(open, high, low, close):
44
"""
45
Shooting Star - Bearish reversal pattern with small body and long upper shadow
46
"""
47
```
48
49
### Doji Variations
50
51
```python { .api }
52
def CDLDOJISTAR(open, high, low, close):
53
"""
54
Doji Star - Doji that gaps away from previous candle
55
"""
56
57
def CDLDRAGONFLYDOJI(open, high, low, close):
58
"""
59
Dragonfly Doji - Doji with long lower shadow, no upper shadow
60
"""
61
62
def CDLGRAVESTONEDOJI(open, high, low, close):
63
"""
64
Gravestone Doji - Doji with long upper shadow, no lower shadow
65
"""
66
67
def CDLLONGLEGGEDDOJI(open, high, low, close):
68
"""
69
Long Legged Doji - Doji with both long upper and lower shadows
70
"""
71
```
72
73
### Engulfing Patterns
74
75
```python { .api }
76
def CDLENGULFING(open, high, low, close):
77
"""
78
Engulfing Pattern - Large candle completely engulfs previous candle
79
"""
80
```
81
82
### Star Patterns
83
84
```python { .api }
85
def CDLMORNINGSTAR(open, high, low, close, penetration=0):
86
"""
87
Morning Star - Three-candle bullish reversal pattern
88
89
Parameters:
90
- penetration: float, penetration threshold (default: 0)
91
"""
92
93
def CDLEVENINGSTAR(open, high, low, close, penetration=0):
94
"""
95
Evening Star - Three-candle bearish reversal pattern
96
"""
97
98
def CDLMORNINGDOJISTAR(open, high, low, close, penetration=0):
99
"""
100
Morning Doji Star - Morning star with doji middle candle
101
"""
102
103
def CDLEVENINGDOJISTAR(open, high, low, close, penetration=0):
104
"""
105
Evening Doji Star - Evening star with doji middle candle
106
"""
107
```
108
109
### Three-Candle Patterns
110
111
```python { .api }
112
def CDL3BLACKCROWS(open, high, low, close):
113
"""
114
Three Black Crows - Bearish reversal pattern with three consecutive black candles
115
"""
116
117
def CDL3WHITESOLDIERS(open, high, low, close):
118
"""
119
Three Advancing White Soldiers - Bullish reversal with three consecutive white candles
120
"""
121
122
def CDL3INSIDE(open, high, low, close):
123
"""
124
Three Inside Up/Down - Three-candle reversal pattern
125
"""
126
127
def CDL3OUTSIDE(open, high, low, close):
128
"""
129
Three Outside Up/Down - Three-candle reversal pattern
130
"""
131
132
def CDL3LINESTRIKE(open, high, low, close):
133
"""
134
Three-Line Strike - Four-candle continuation pattern
135
"""
136
137
def CDLIDENTICAL3CROWS(open, high, low, close):
138
"""
139
Identical Three Crows - Bearish pattern with three identical black candles
140
"""
141
142
def CDL3STARSINSOUTH(open, high, low, close):
143
"""
144
Three Stars In The South - Bullish reversal pattern
145
"""
146
```
147
148
### Harami Patterns
149
150
```python { .api }
151
def CDLHARAMI(open, high, low, close):
152
"""
153
Harami Pattern - Small candle contained within large candle's body
154
"""
155
156
def CDLHARAMICROSS(open, high, low, close):
157
"""
158
Harami Cross Pattern - Harami with doji as second candle
159
"""
160
```
161
162
### Gap Patterns
163
164
```python { .api }
165
def CDLGAPSIDESIDEWHITE(open, high, low, close):
166
"""
167
Up/Down-gap side-by-side white lines
168
"""
169
170
def CDL2CROWS(open, high, low, close):
171
"""
172
Two Crows - Bearish reversal pattern
173
"""
174
175
def CDLUPSIDEGAP2CROWS(open, high, low, close):
176
"""
177
Upside Gap Two Crows - Bearish reversal pattern
178
"""
179
180
def CDLXSIDEGAP3METHODS(open, high, low, close):
181
"""
182
Upside/Downside Gap Three Methods - Continuation pattern
183
"""
184
```
185
186
### Complex Patterns
187
188
```python { .api }
189
def CDLDARKCLOUDCOVER(open, high, low, close, penetration=0):
190
"""
191
Dark Cloud Cover - Bearish reversal pattern
192
"""
193
194
def CDLPIERCING(open, high, low, close):
195
"""
196
Piercing Pattern - Bullish reversal pattern
197
"""
198
199
def CDLABANDONEDBABY(open, high, low, close, penetration=0):
200
"""
201
Abandoned Baby - Rare reversal pattern with gaps
202
"""
203
204
def CDLMATHOLD(open, high, low, close, penetration=0):
205
"""
206
Mat Hold - Bullish continuation pattern
207
"""
208
```
209
210
### Marubozu Patterns
211
212
```python { .api }
213
def CDLMARUBOZU(open, high, low, close):
214
"""
215
Marubozu - Candle with no shadows (open/close at high/low)
216
"""
217
218
def CDLCLOSINGMARUBOZU(open, high, low, close):
219
"""
220
Closing Marubozu - Marubozu that closes at high or low
221
"""
222
```
223
224
### Additional Patterns
225
226
```python { .api }
227
def CDLADVANCEBLOCK(open, high, low, close):
228
"""Advance Block - Bearish reversal pattern"""
229
230
def CDLBELTHOLD(open, high, low, close):
231
"""Belt-hold - Single candle reversal pattern"""
232
233
def CDLBREAKAWAY(open, high, low, close):
234
"""Breakaway - Five-candle reversal pattern"""
235
236
def CDLCONCEALBABYSWALL(open, high, low, close):
237
"""Concealing Baby Swallow - Bullish reversal pattern"""
238
239
def CDLCOUNTERATTACK(open, high, low, close):
240
"""Counterattack - Reversal pattern"""
241
242
def CDLHIGHWAVE(open, high, low, close):
243
"""High-Wave Candle - Indecision pattern with long shadows"""
244
245
def CDLHIKKAKE(open, high, low, close):
246
"""Hikkake Pattern - Inside day breakout pattern"""
247
248
def CDLHIKKAKEMOD(open, high, low, close):
249
"""Modified Hikkake Pattern - Enhanced version of Hikkake"""
250
251
def CDLHOMINGPIGEON(open, high, low, close):
252
"""Homing Pigeon - Bullish reversal pattern"""
253
254
def CDLINNECK(open, high, low, close):
255
"""In-Neck Pattern - Bearish continuation pattern"""
256
257
def CDLKICKING(open, high, low, close):
258
"""Kicking - Strong reversal pattern with gaps"""
259
260
def CDLKICKINGBYLENGTH(open, high, low, close):
261
"""Kicking - bull/bear determined by the longer marubozu"""
262
263
def CDLLADDERBOTTOM(open, high, low, close):
264
"""Ladder Bottom - Bullish reversal pattern"""
265
266
def CDLLONGLINE(open, high, low, close):
267
"""Long Line Candle - Candle with unusually long body"""
268
269
def CDLMATCHINGLOW(open, high, low, close):
270
"""Matching Low - Bullish reversal pattern"""
271
272
def CDLONNECK(open, high, low, close):
273
"""On-Neck Pattern - Bearish continuation pattern"""
274
275
def CDLRICKSHAWMAN(open, high, low, close):
276
"""Rickshaw Man - Indecision pattern similar to long-legged doji"""
277
278
def CDLRISEFALL3METHODS(open, high, low, close):
279
"""Rising/Falling Three Methods - Continuation pattern"""
280
281
def CDLSEPARATINGLINES(open, high, low, close):
282
"""Separating Lines - Continuation pattern"""
283
284
def CDLSHORTLINE(open, high, low, close):
285
"""Short Line Candle - Candle with unusually short body"""
286
287
def CDLSPINNINGTOP(open, high, low, close):
288
"""Spinning Top - Indecision pattern with small body and shadows"""
289
290
def CDLSTALLEDPATTERN(open, high, low, close):
291
"""Stalled Pattern - Bearish reversal in uptrend"""
292
293
def CDLSTICKSANDWICH(open, high, low, close):
294
"""Stick Sandwich - Bullish reversal pattern"""
295
296
def CDLTAKURI(open, high, low, close):
297
"""Takuri (Dragonfly Doji with very long lower shadow)"""
298
299
def CDLTASUKIGAP(open, high, low, close):
300
"""Tasuki Gap - Continuation pattern"""
301
302
def CDLTHRUSTING(open, high, low, close):
303
"""Thrusting Pattern - Bearish continuation pattern"""
304
305
def CDLTRISTAR(open, high, low, close):
306
"""Tristar Pattern - Rare reversal pattern with three doji"""
307
308
def CDLUNIQUE3RIVER(open, high, low, close):
309
"""Unique 3 River - Bullish reversal pattern"""
310
```
311
312
## Usage Examples
313
314
```python
315
import talib
316
import numpy as np
317
318
# Sample OHLC data
319
open_prices = np.array([100.0, 101.0, 102.0, 101.5, 103.0])
320
high_prices = np.array([100.5, 102.0, 102.5, 102.0, 103.5])
321
low_prices = np.array([99.5, 100.5, 101.0, 100.8, 102.5])
322
close_prices = np.array([100.2, 101.8, 101.2, 102.2, 103.2])
323
324
# Detect various candlestick patterns
325
doji = talib.CDLDOJI(open_prices, high_prices, low_prices, close_prices)
326
hammer = talib.CDLHAMMER(open_prices, high_prices, low_prices, close_prices)
327
engulfing = talib.CDLENGULFING(open_prices, high_prices, low_prices, close_prices)
328
329
# Check for patterns in the last period
330
if doji[-1] != 0:
331
print("Doji pattern detected")
332
if hammer[-1] == 100:
333
print("Bullish hammer detected")
334
elif hammer[-1] == -100:
335
print("Bearish hammer detected")
336
337
# Morning star with custom penetration threshold
338
morning_star = talib.CDLMORNINGSTAR(open_prices, high_prices, low_prices, close_prices, penetration=0.3)
339
```