-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCandlestickPatterns.pinescript
More file actions
704 lines (582 loc) · 57.9 KB
/
CandlestickPatterns.pinescript
File metadata and controls
704 lines (582 loc) · 57.9 KB
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
//@version=5
//=============================================================================================
// Creator: Woverine
//
// Source Code: https://github.com/RyKaj/PineScript/tree/main
//
// Purpose:
// Woverine - Candelstick Patterns
//
//=============================================================================================
indicator('Woverine - Candlestick Patterns', shorttitle='CS', overlay=true)
//-------------------------------------------------------------------------------------------------------------------------
// Plot colors
// https://chir.ag/projects/name-that-color/#6195ED
// https://kodify.net/tradingview/colours/basic-colours/
//-------------------------------------------------------------------------------------------------------------------------
// color colorAquaIsland = #B2DFDB
// color colorAzureRadiance = #0094ff
// color colorBlack = #363A45
// color colorBlazeOrange = #ff6a00
// color colorBlue = #2196F3
// color colorBlueChill = #088A8D
// color colorBlushPink = #fd7fe6
// color colorBurntSienna = #EF5350
// color colorCandelLight = #FCD917
// color colorCoral = #FF7F50
// color colorCyan = #17FFFF
// color colorDeathCross = #e32636
// color colorFreshEggplant = #800080
// color colorFruitSalad = #4CAF50
// color colorGoldenCross = #61ed77
color colorGray = #787B86
// color colorJapaneseLaurel = #008000
color colorGreen = #4CAF50
// color colorJungleGreen = #39ff14
// color colorKeyLimePie = #BCBB26
// color colorLilacBush = #9575cd
// color colorLime = #00E676
// color colorOrange = #FF9800
// color colorParsley = #0E4813
// color colorPastelPink = #FFCDD2
// color colorPurple = #9C27B0
color colorRed = #FF5252
// color colorRobinEggBlue = #00C9C9
// color colorRoseBudCherry = #880e4f
// color colorRusticRed = #4E0404
// color colorSaratoga = #505010
// color colorSpringGreen = #00E676
// color colorStarship = #F2F131
// color colorTamarillo = #991515
// color colorTeal = #00897B
// color colorTealBlue = #055355
// color colorTrendyGreen = #86851b
color colorWhite = #FFFFFF
string trendRule1 = "SMA50"
string trendRule2 = "SMA50, SMA200"
bool C_DownTrend = true
bool C_UpTrend = true
int C_Len = 14 // ema depth for bodyAvg
float C_ShadowPercent = 5.0 // size of shadows
float C_ShadowEqualsPercent = 100.0
float C_DojiBodyPercent = 5.0
float C_Factor = 2.0 // shows the number of times the shadow dominates the candlestick body
string ENGLISH = "English"
string BULLISH = "Bullish"
string BEARISH = "Bearish"
string NEUTRAL = "Neutral"
float patternLabelPosLow = low - ta.atr( 30 ) * 0.6
float patternLabelPosHigh = high + ta.atr( 30 ) * 0.6
//-------------------------------------------------------------------------------------------------------------------------
// Functions
//-------------------------------------------------------------------------------------------------------------------------
setPatternIndicatorLabel( lblValue, tooltip, lblColor, lblStyle, txtColor, lblLocation ) =>
label.new(x = bar_index , y = lblLocation , text = lblValue, xloc = xloc.bar_index, yloc = yloc.price, color = color.new(color = lblColor , transp = 0), style = lblStyle , textcolor = color.new(color = txtColor , transp = 0), size = size.normal, textalign = text.align_center, tooltip = tooltip )
getLabel( name ) =>
name == 'none' ? label.style_none : name == 'xcross' ? label.style_xcross : name == 'cross' ? label.style_cross : name == 'triangle up' ? label.style_triangleup : name == 'triangle down' ? label.style_triangledown : name == 'flag' ? label.style_flag : name == 'circle' ? label.style_circle : name == 'arrow up' ? label.style_arrowup : name == 'arrow down' ? label.style_arrowdown : name == 'label up' ? label.style_label_up : name == 'label down' ? label.style_label_down : name == 'square' ? label.style_square : label.style_diamond
//-------------------------------------------------------------------------------------------------------------------------
// Inputs
//-------------------------------------------------------------------------------------------------------------------------
string sCandleType = input.string( defval="All", title="Pattern Type", options=[ BULLISH, BEARISH, NEUTRAL, "All", "Except Neutral"], tooltip = "", inline = "", group = "" , confirm = false )
string trendRule = input.string( defval=trendRule1, title="Detect Trend Based On", options=[ trendRule1, trendRule2, "No detection" ], tooltip = "", inline = "", group = "" , confirm = false )
float source = input.source( defval = close, title = "Source", tooltip = "", inline = "", group = "Channel" )
// ------------------------- Bullish -------------------------
MarubozuWhiteInput = input.bool( defval=true, title = "Marubozu White", tooltip = "", inline = "", group = BULLISH , confirm = false )
HammerInput = input.bool( defval=true, title="Hammer", tooltip = "", inline = "", group = BULLISH , confirm = false )
InvertedHammerInput = input.bool( defval=true, title="Inverted Hammer", tooltip = "", inline = "", group = BULLISH , confirm = false )
LongLowerShadowInput = input.bool( defval=true, title="Long Lower Shadow", tooltip = "", inline = "", group = BULLISH , confirm = false )
UpsideTasukiGapInput = input.bool( defval=true, title="Upside Tasuki Gap", tooltip = "", inline = "", group = BULLISH , confirm = false )
RisingWindowInput = input.bool( defval=true, title="Rising Window", tooltip = "", inline = "", group = BULLISH , confirm = false )
PiercingInput = input.bool( defval=true, title="Piercing", tooltip = "", inline = "", group = BULLISH , confirm = false )
BullishEngulfingInput = input.bool( defval=true, title="Engulfing", tooltip = "", inline = "", group = BULLISH , confirm = false )
TweezerBottomInput = input.bool( defval=true, title="Tweezer Bottom", tooltip = "", inline = "", group = BULLISH , confirm = false )
BullishAbandonedBabyInput = input.bool( defval=true, title="Abandoned Baby", tooltip = "", inline = "", group = BULLISH , confirm = false )
MorningStarInput = input.bool( defval=true, title="Morning Star", tooltip = "", inline = "", group = BULLISH , confirm = false )
MorningDojiStarInput = input.bool( defval=true, title="Morning Doji Star", tooltip = "", inline = "", group = BULLISH , confirm = false )
DragonflyDojiInput = input.bool( defval=true, title="Dragonfly Doji", tooltip = "", inline = "", group = BULLISH , confirm = false )
ThreeWhiteSoldiersInput = input.bool( defval=true, title="Three White Soldiers", tooltip = "", inline = "", group = BULLISH , confirm = false )
RisingThreeMethodsInput = input.bool( defval=true, title="Rising Three Methods", tooltip = "", inline = "", group = BULLISH , confirm = false )
TriStarInput = input.bool( defval=true, title="Tri-Star", tooltip = "", inline = "", group = BULLISH , confirm = false )
// ------------------------- Bearish -------------------------
MarubozuBlackInput = input.bool( defval=true, title="Marubozu Black", tooltip = "", inline = "", group = BEARISH , confirm = false )
GravestoneDojiInput = input.bool( defval=true, title="Gravestone Doji", tooltip = "", inline = "", group = BEARISH , confirm = false )
HangingManInput = input.bool( defval=true, title="Hanging Man", tooltip = "", inline = "", group = BEARISH , confirm = false )
LongUpperShadowInput = input.bool( defval=true, title="Long Upper Shadow", tooltip = "", inline = "", group = BEARISH , confirm = false )
DownsideTasukiGapInput = input.bool( defval=true, title="Downside Tasuki Gap", tooltip = "", inline = "", group = BEARISH , confirm = false )
FallingWindowInput = input.bool( defval=true, title="Falling Window", tooltip = "", inline = "", group = BEARISH , confirm = false )
DarkCloudCoverInput = input.bool( defval=true, title="Dark Cloud Cover", tooltip = "", inline = "", group = BEARISH , confirm = false )
BearishEngulfingInput = input.bool( defval=true, title="Engulfing", tooltip = "", inline = "", group = BEARISH , confirm = false )
TweezerTopInput = input.bool( defval=true, title="Tweezer Top", tooltip = "", inline = "", group = BEARISH , confirm = false )
AbandonedBabyInput = input.bool( defval=true, title="Abandoned Baby", tooltip = "", inline = "", group = BEARISH , confirm = false )
EveningDojiStarInput = input.bool( defval=true, title="Evening Doji Star", tooltip = "", inline = "", group = BEARISH , confirm = false )
EveningStarInput = input.bool( defval=true, title="Evening Star", tooltip = "", inline = "", group = BEARISH , confirm = false )
ThreeBlackCrowsInput = input.bool( defval=true, title="Three Black Crows", tooltip = "", inline = "", group = BEARISH , confirm = false )
FallingThreeMethodsInput = input.bool( defval=true, title="Falling Three Methods", tooltip = "", inline = "", group = BEARISH , confirm = false )
ShootingStarInput = input.bool( defval=true, title="Shooting Star", tooltip = "", inline = "", group = BEARISH , confirm = false )
BearishTriStarInput = input.bool( defval=true, title="Tri-Star", tooltip = "", inline = "", group = BEARISH , confirm = false )
// ------------------------- Neutral -------------------------
DojiInput = input.bool( defval=true, title="Doji", tooltip = "", inline = "", group = NEUTRAL , confirm = false )
DojiStarInput = input.bool( defval=true, title="Doji Star", tooltip = "", inline = "", group = NEUTRAL , confirm = false )
SpinningTopBlackInput = input.bool( defval=true, title="Spinning Top Black", tooltip = "", inline = "", group = NEUTRAL , confirm = false )
SpinningTopWhiteInput = input.bool( defval=true, title="Spinning Top White", tooltip = "", inline = "", group = NEUTRAL , confirm = false )
HaramiCrossInput = input.bool( defval=true, title="Harami Cross", tooltip = "", inline = "", group = NEUTRAL , confirm = false )
HaramiInput = input.bool( defval=true, title="Harami", tooltip = "", inline = "", group = NEUTRAL , confirm = false )
KickingInput = input.bool( defval=true, title="Kicking", tooltip = "", inline = "", group = NEUTRAL , confirm = false )
OnNeckInput = input.bool( defval=true, title="On Neck", tooltip = "", inline = "", group = NEUTRAL , confirm = false )
// ------------------------- Color -------------------------
color bullishColor = input.color( defval = colorGreen , title = "Bullish Color", tooltip = "", inline = "", group = "Color" , confirm = false )
color bearishColor = input.color( defval = colorRed , title = "Bearish Color", tooltip = "", inline = "", group = "Color" , confirm = false )
color neutralColor = input.color( defval = colorGray , title = "Neutral Color", tooltip = "", inline = "", group = "Color" , confirm = false )
color textColor = input.color( defval = colorWhite , title = "Text Color", tooltip = "", inline = "", group = "Color" , confirm = false )
// ------------------------- Label -------------------------
string bullishLabel = getLabel( input.string( defval='label up', title='Bullish Label', options=['none', 'xcross', 'cross', 'triangle up', 'triangle down', 'flag', 'circle', 'arrow up', 'arrow down', 'label up', 'label down', 'square', 'diamond'], tooltip = "", inline = "", group = "Lables" , confirm = false ) )
string bearishLabel = getLabel( input.string( defval='label down', title='Bearish Label', options=['none', 'xcross', 'cross', 'triangle up', 'triangle down', 'flag', 'circle', 'arrow up', 'arrow down', 'label up', 'label down', 'square', 'diamond'], tooltip = "", inline = "", group = "Lables" , confirm = false ) )
string neutralLabel = getLabel( input.string( defval='label up', title='Neutral Label', options=['none', 'xcross', 'cross', 'triangle up', 'triangle down', 'flag', 'circle', 'arrow up', 'arrow down', 'label up', 'label down', 'square', 'diamond'], tooltip = "", inline = "", group = "Lables" , confirm = false ) )
bool showBearishSignal = sCandleType == 'Bearish' or sCandleType == 'All' or sCandleType == 'Except Neutral'
bool showBullishSignal = sCandleType == 'Bullish' or sCandleType == 'All' or sCandleType == 'Except Neutral'
bool showNeutralSignal = sCandleType == 'Neutral' or sCandleType == 'All'
if trendRule == trendRule1
priceAvg = ta.sma( source, 50)
C_DownTrend := source < priceAvg
C_UpTrend := source > priceAvg
C_UpTrend
if trendRule == trendRule2
sma200 = ta.sma( source, 200)
sma50 = ta.sma( source, 50)
C_DownTrend := source < sma50 and sma50 < sma200
C_UpTrend := source > sma50 and sma50 > sma200
C_UpTrend
// length and height
C_BodyHi = math.max( source, open )
C_BodyLo = math.min( source, open )
C_Body = C_BodyHi - C_BodyLo
C_BodyMiddle = C_Body / 2 + C_BodyLo
C_BodyAvg = ta.ema( C_Body, C_Len )
C_UpShadow = high - C_BodyHi
C_DnShadow = C_BodyLo - low
C_Range = high - low
// bool
C_SmallBody = C_Body < C_BodyAvg
C_LongBody = C_Body > C_BodyAvg
C_HasUpShadow = C_UpShadow > C_ShadowPercent / 100 * C_Body
C_HasDnShadow = C_DnShadow > C_ShadowPercent / 100 * C_Body
C_WhiteBody = open < source
C_BlackBody = open > source
C_IsInsideBar = C_BodyHi[1] > C_BodyHi and C_BodyLo[1] < C_BodyLo
C_ShadowEquals = C_UpShadow == C_DnShadow or math.abs( C_UpShadow - C_DnShadow ) / C_DnShadow * 100 < C_ShadowEqualsPercent and math.abs( C_DnShadow - C_UpShadow ) / C_UpShadow * 100 < C_ShadowEqualsPercent
C_IsDojiBody = C_Range > 0 and C_Body <= C_Range * C_DojiBodyPercent / 100
C_Doji = C_IsDojiBody and C_ShadowEquals
C_OnNeckBearishNumberOfCandles = 2
C_OnNeckBearish = false
if C_DownTrend and C_BlackBody[1] and C_LongBody[1] and C_WhiteBody and open < close[1] and C_SmallBody and C_Range != 0 and math.abs(close - low[1]) <= C_BodyAvg * 0.05
C_OnNeckBearish := true
C_OnNeckBearish
alertcondition(C_OnNeckBearish, title='On Neck', message='New On Neck - Bearish pattern detected.')
if C_OnNeckBearish and OnNeckInput and showBearishSignal
string sMsg = 'On Neck\nOn Neck is a two-line continuation pattern found in a downtrend. The first candle is long and red, the second candle is short and has a green body. The closing price of the second candle is close or equal to the first candle\'s low price. The pattern hints at a continuation of a downtrend, and penetrating the low of the green candlestick is sometimes considered a confirmation. '
string sLabel = 'ON'
setPatternIndicatorLabel( lblValue = sLabel, tooltip = sMsg, lblColor = bearishColor, lblStyle = bearishLabel, txtColor = textColor, lblLocation = patternLabelPosHigh )
C_RisingWindowBullishNumberOfCandles = 2
C_RisingWindowBullish = false
if C_UpTrend[1] and C_Range != 0 and C_Range[1] != 0 and low > high[1]
C_RisingWindowBullish := true
C_RisingWindowBullish
alertcondition(C_RisingWindowBullish, title='Rising Window', message='New Rising Window - Bullish pattern detected.')
if C_RisingWindowBullish and RisingWindowInput and showBullishSignal
string sMsg = 'Rising Window\nRising Window is a two-candle bullish continuation pattern that forms during an uptrend. Both candles in the pattern can be of any type with the exception of the Four-Price Doji. The most important characteristic of the pattern is a price gap between the first candle\'s high and the second candle\'s low. That gap (window) between two bars signifies support against the selling pressure.'
string sLabel = 'RW'
setPatternIndicatorLabel( lblValue = sLabel, tooltip = sMsg, lblColor = bullishColor, lblStyle = bullishLabel, txtColor = textColor, lblLocation = patternLabelPosLow )
C_FallingWindowBearishNumberOfCandles = 2
C_FallingWindowBearish = false
if C_DownTrend[1] and C_Range != 0 and C_Range[1] != 0 and high < low[1]
C_FallingWindowBearish := true
C_FallingWindowBearish
alertcondition(C_FallingWindowBearish, title='Falling Window', message='New Falling Window - Bearish pattern detected.')
if C_FallingWindowBearish and FallingWindowInput and showBearishSignal
string sMsg = 'Falling Window\nFalling Window is a two-candle bearish continuation pattern that forms during a downtrend. Both candles in the pattern can be of any type, with the exception of the Four-Price Doji. The most important characteristic of the pattern is a price gap between the first candle\'s low and the second candle\'s high. The existence of this gap (window) means that the bearish trend is expected to continue.'
string sLabel = 'FW'
setPatternIndicatorLabel( lblValue = sLabel, tooltip = sMsg, lblColor = bearishColor, lblStyle = bearishLabel, txtColor = textColor, lblLocation = patternLabelPosHigh )
C_FallingThreeMethodsBearishNumberOfCandles = 5
C_FallingThreeMethodsBearish = false
if C_DownTrend[4] and C_LongBody[4] and C_BlackBody[4] and C_SmallBody[3] and C_WhiteBody[3] and open[3] > low[4] and close[3] < high[4] and C_SmallBody[2] and C_WhiteBody[2] and open[2] > low[4] and close[2] < high[4] and C_SmallBody[1] and C_WhiteBody[1] and open[1] > low[4] and close[1] < high[4] and C_LongBody and C_BlackBody and close < close[4]
C_FallingThreeMethodsBearish := true
C_FallingThreeMethodsBearish
alertcondition(C_FallingThreeMethodsBearish, title='Falling Three Methods', message='New Falling Three Methods - Bearish pattern detected.')
if C_FallingThreeMethodsBearish and FallingThreeMethodsInput and showBearishSignal
string sMsg = 'Falling Three Methods\nFalling Three Methods is a five-candle bearish pattern that signifies a continuation of an existing downtrend. The first candle is long and red, followed by three short green candles with bodies inside the range of the first candle. The last candle is also red and long and it closes below the close of the first candle. This decisive fifth strongly bearish candle hints that bulls could not reverse the prior downtrend and that bears have regained control of the market.'
string sLabel = 'FTM'
setPatternIndicatorLabel( lblValue = sLabel, tooltip = sMsg, lblColor = bearishColor, lblStyle = bearishLabel, txtColor = textColor, lblLocation = patternLabelPosHigh )
C_RisingThreeMethodsBullishNumberOfCandles = 5
C_RisingThreeMethodsBullish = false
if C_UpTrend[4] and C_LongBody[4] and C_WhiteBody[4] and C_SmallBody[3] and C_BlackBody[3] and open[3] < high[4] and close[3] > low[4] and C_SmallBody[2] and C_BlackBody[2] and open[2] < high[4] and close[2] > low[4] and C_SmallBody[1] and C_BlackBody[1] and open[1] < high[4] and close[1] > low[4] and C_LongBody and C_WhiteBody and close > close[4]
C_RisingThreeMethodsBullish := true
C_RisingThreeMethodsBullish
alertcondition(C_RisingThreeMethodsBullish, title='Rising Three Methods', message='New Rising Three Methods - Bullish pattern detected.')
if C_RisingThreeMethodsBullish and RisingThreeMethodsInput and showBullishSignal
string sMsg = 'Rising Three Methods\nRising Three Methods is a five-candle bullish pattern that signifies a continuation of an existing uptrend. The first candle is long and green, followed by three short red candles with bodies inside the range of the first candle. The last candle is also green and long and it closes above the close of the first candle. This decisive fifth strongly bullish candle hints that bears could not reverse the prior uptrend and that bulls have regained control of the market.'
string sLabel = 'RTM'
setPatternIndicatorLabel( lblValue = sLabel, tooltip = sMsg, lblColor = bullishColor, lblStyle = bullishLabel, txtColor = textColor, lblLocation = patternLabelPosLow )
C_TweezerTopBearishNumberOfCandles = 2
C_TweezerTopBearish = false
if C_UpTrend[1] and (not C_IsDojiBody or C_HasUpShadow and C_HasDnShadow) and math.abs(high - high[1]) <= C_BodyAvg * 0.05 and C_WhiteBody[1] and C_BlackBody and C_LongBody[1]
C_TweezerTopBearish := true
C_TweezerTopBearish
alertcondition(C_TweezerTopBearish, title='Tweezer Top', message='New Tweezer Top - Bearish pattern detected.')
if C_TweezerTopBearish and TweezerTopInput and showBearishSignal
string sMsg = 'Tweezer Top\nTweezer Top is a two-candle pattern that signifies a potential bearish reversal. The pattern is found during an uptrend. The first candle is long and green, the second candle is red, and its high is nearly identical to the high of the previous candle. The virtually identical highs, together with the inverted directions, hint that bears might be taking over the market.'
string sLabel = 'TT'
setPatternIndicatorLabel( lblValue = sLabel, tooltip = sMsg, lblColor = bearishColor, lblStyle = bearishLabel, txtColor = textColor, lblLocation = patternLabelPosHigh )
C_TweezerBottomBullishNumberOfCandles = 2
C_TweezerBottomBullish = false
if C_UpTrend[1] and (not C_IsDojiBody or C_HasUpShadow and C_HasDnShadow) and math.abs(low - low[1]) <= C_BodyAvg * 0.05 and C_BlackBody[1] and C_WhiteBody and C_LongBody[1]
C_TweezerBottomBullish := true
C_TweezerBottomBullish
alertcondition(C_TweezerBottomBullish, title='Tweezer Bottom', message='New Tweezer Bottom - Bullish pattern detected.')
if C_TweezerBottomBullish and TweezerBottomInput and showBullishSignal
string sMsg = 'Tweezer Bottom\nTweezer Bottom is a two-candle pattern that signifies a potential bullish reversal. The pattern is found during a downtrend. The first candle is long and red, the second candle is green, its lows nearly identical to the low of the previous candle. The virtually identical lows together with the inverted directions hint that bulls might be taking over the market.'
string sLabel = 'TB'
setPatternIndicatorLabel( lblValue = sLabel, tooltip = sMsg, lblColor = bullishColor, lblStyle = bullishLabel, txtColor = textColor, lblLocation = patternLabelPosLow )
C_DarkCloudCoverBearishNumberOfCandles = 2
C_DarkCloudCoverBearish = false
if C_UpTrend[1] and C_WhiteBody[1] and C_LongBody[1] and C_BlackBody and open >= high[1] and close < C_BodyMiddle[1] and close > open[1]
C_DarkCloudCoverBearish := true
C_DarkCloudCoverBearish
alertcondition(C_DarkCloudCoverBearish, title='Dark Cloud Cover', message='New Dark Cloud Cover - Bearish pattern detected.')
if C_DarkCloudCoverBearish and DarkCloudCoverInput and showBearishSignal
string sMsg = 'Dark Cloud Cover\nDark Cloud Cover is a two-candle bearish reversal candlestick pattern found in an uptrend. The first candle is green and has a larger than average body. The second candle is red and opens above the high of the prior candle, creating a gap, and then closes below the midpoint of the first candle. The pattern shows a possible shift in the momentum from the upside to the downside, indicating that a reversal might happen soon.'
string sLabel = 'DCC'
setPatternIndicatorLabel( lblValue = sLabel, tooltip = sMsg, lblColor = bearishColor, lblStyle = bearishLabel, txtColor = textColor, lblLocation = patternLabelPosHigh )
C_DownsideTasukiGapBearishNumberOfCandles = 3
C_DownsideTasukiGapBearish = false
if C_LongBody[2] and C_SmallBody[1] and C_DownTrend and C_BlackBody[2] and C_BodyHi[1] < C_BodyLo[2] and C_BlackBody[1] and C_WhiteBody and C_BodyHi <= C_BodyLo[2] and C_BodyHi >= C_BodyHi[1]
C_DownsideTasukiGapBearish := true
C_DownsideTasukiGapBearish
alertcondition(C_DownsideTasukiGapBearish, title='Downside Tasuki Gap', message='New Downside Tasuki Gap - Bearish pattern detected.')
if C_DownsideTasukiGapBearish and DownsideTasukiGapInput and showBearishSignal
string sMsg = 'Downside Tasuki Gap\nDownside Tasuki Gap is a three-candle pattern found in a downtrend that usually hints at the continuation of the downtrend. The first candle is long and red, followed by a smaller red candle with its opening price that gaps below the body of the previous candle. The third candle is green and it closes inside the gap created by the first two candles, unable to close it fully. The bull’s inability to close that gap hints that the downtrend might continue.'
string sLabel = 'DTG'
setPatternIndicatorLabel( lblValue = sLabel, tooltip = sMsg, lblColor = bearishColor, lblStyle = bearishLabel, txtColor = textColor, lblLocation = patternLabelPosHigh )
C_UpsideTasukiGapBullishNumberOfCandles = 3
C_UpsideTasukiGapBullish = false
if C_LongBody[2] and C_SmallBody[1] and C_UpTrend and C_WhiteBody[2] and C_BodyLo[1] > C_BodyHi[2] and C_WhiteBody[1] and C_BlackBody and C_BodyLo >= C_BodyHi[2] and C_BodyLo <= C_BodyLo[1]
C_UpsideTasukiGapBullish := true
C_UpsideTasukiGapBullish
alertcondition(C_UpsideTasukiGapBullish, title='Upside Tasuki Gap', message='New Upside Tasuki Gap - Bullish pattern detected.')
if C_UpsideTasukiGapBullish and UpsideTasukiGapInput and showBullishSignal
string sMsg = 'Upside Tasuki Gap\nUpside Tasuki Gap is a three-candle pattern found in an uptrend that usually hints at the continuation of the uptrend. The first candle is long and green, followed by a smaller green candle with its opening price that gaps above the body of the previous candle. The third candle is red and it closes inside the gap created by the first two candles, unable to close it fully. The bear’s inability to close the gap hints that the uptrend might continue.'
string sLabel = 'UTG'
setPatternIndicatorLabel( lblValue = sLabel, tooltip = sMsg, lblColor = bullishColor, lblStyle = bullishLabel, txtColor = textColor, lblLocation = patternLabelPosLow )
C_EveningDojiStarBearishNumberOfCandles = 3
C_EveningDojiStarBearish = false
if C_LongBody[2] and C_IsDojiBody[1] and C_LongBody and C_UpTrend and C_WhiteBody[2] and C_BodyLo[1] > C_BodyHi[2] and C_BlackBody and C_BodyLo <= C_BodyMiddle[2] and C_BodyLo > C_BodyLo[2] and C_BodyLo[1] > C_BodyHi
C_EveningDojiStarBearish := true
C_EveningDojiStarBearish
alertcondition(C_EveningDojiStarBearish, title='Evening Doji Star', message='New Evening Doji Star - Bearish pattern detected.')
if C_EveningDojiStarBearish and EveningDojiStarInput and showBearishSignal
string sMsg = 'Evening Doji Star\nThis candlestick pattern is a variation of the Evening Star pattern. It is bearish and continues an uptrend with a long-bodied, green candle day. It is then followed by a gap and a Doji candle and concludes with a downward close. The close would be below the first day’s midpoint. It is more bearish than the regular evening star pattern because of the existence of the Doji.'
string sLabel = 'EDS'
setPatternIndicatorLabel( lblValue = sLabel, tooltip = sMsg, lblColor = bearishColor, lblStyle = bearishLabel, txtColor = textColor, lblLocation = patternLabelPosHigh )
C_DojiStarBearishNumberOfCandles = 2
C_DojiStarBearish = false
if C_UpTrend and C_WhiteBody[1] and C_LongBody[1] and C_IsDojiBody and C_BodyLo > C_BodyHi[1]
C_DojiStarBearish := true
C_DojiStarBearish
alertcondition(C_DojiStarBearish, title='Doji Star', message='New Doji Star - Bearish pattern detected.')
if C_DojiStarBearish and DojiStarInput and showBearishSignal
string sMsg = 'Doji Star\nThis is a bearish reversal candlestick pattern that is found in an uptrend and consists of two candles. First comes a long green candle, followed by a Doji candle (except 4-Price Doji) that opens above the body of the first one, creating a gap. It is considered a reversal signal with confirmation during the next trading day.'
string sLabel = 'DS'
setPatternIndicatorLabel( lblValue = sLabel, tooltip = sMsg, lblColor = bearishColor, lblStyle = bearishLabel, txtColor = textColor, lblLocation = patternLabelPosHigh )
C_DojiStarBullishNumberOfCandles = 2
C_DojiStarBullish = false
if C_DownTrend and C_BlackBody[1] and C_LongBody[1] and C_IsDojiBody and C_BodyHi < C_BodyLo[1]
C_DojiStarBullish := true
C_DojiStarBullish
alertcondition(C_DojiStarBullish, title='Doji Star', message='New Doji Star - Bullish pattern detected.')
if C_DojiStarBullish and DojiStarInput and showBullishSignal
string sMsg = 'Doji Star\nThis is a bullish reversal candlestick pattern that is found in a downtrend and consists of two candles. First comes a long red candle, followed by a Doji candle (except 4-Price Doji) that opens below the body of the first one, creating a gap. It is considered a reversal signal with confirmation during the next trading day.'
string sLabel = 'DS'
setPatternIndicatorLabel( lblValue = sLabel, tooltip = sMsg, lblColor = bullishColor, lblStyle = bullishLabel, txtColor = textColor, lblLocation = patternLabelPosLow )
C_MorningDojiStarBullishNumberOfCandles = 3
C_MorningDojiStarBullish = false
if C_LongBody[2] and C_IsDojiBody[1] and C_LongBody and C_DownTrend and C_BlackBody[2] and C_BodyHi[1] < C_BodyLo[2] and C_WhiteBody and C_BodyHi >= C_BodyMiddle[2] and C_BodyHi < C_BodyHi[2] and C_BodyHi[1] < C_BodyLo
C_MorningDojiStarBullish := true
C_MorningDojiStarBullish
alertcondition(C_MorningDojiStarBullish, title='Morning Doji Star', message='New Morning Doji Star - Bullish pattern detected.')
if C_MorningDojiStarBullish and MorningDojiStarInput and showBullishSignal
string sMsg = 'Morning Doji Star\nThis candlestick pattern is a variation of the Morning Star pattern. A three-day bullish reversal pattern, which consists of three candlesticks will look something like this: The first being a long-bodied red candle that extends the current downtrend. Next comes a Doji that gaps down on the open. After that comes a long-bodied green candle, which gaps up on the open and closes above the midpoint of the body of the first day. It is more bullish than the regular morning star pattern because of the existence of the Doji.'
string sLabel = 'MDS'
setPatternIndicatorLabel( lblValue = sLabel, tooltip = sMsg, lblColor = bullishColor, lblStyle = bullishLabel, txtColor = textColor, lblLocation = patternLabelPosLow )
C_PiercingBullishNumberOfCandles = 2
C_PiercingBullish = false
if C_DownTrend[1] and C_BlackBody[1] and C_LongBody[1] and C_WhiteBody and open <= low[1] and close > C_BodyMiddle[1] and close < open[1]
C_PiercingBullish := true
C_PiercingBullish
alertcondition(C_PiercingBullish, title='Piercing', message='New Piercing - Bullish pattern detected.')
if C_PiercingBullish and PiercingInput and showBullishSignal
string sMsg = 'Piercing\nPiercing is a two-candle bullish reversal candlestick pattern found in a downtrend. The first candle is red and has a larger than average body. The second candle is green and opens below the low of the prior candle, creating a gap, and then closes above the midpoint of the first candle. The pattern shows a possible shift in the momentum from the downside to the upside, indicating that a reversal might happen soon.'
string sLabel = 'P'
setPatternIndicatorLabel( lblValue = sLabel, tooltip = sMsg, lblColor = bullishColor, lblStyle = bullishLabel, txtColor = textColor, lblLocation = patternLabelPosLow )
C_HammerBullishNumberOfCandles = 1
C_HammerBullish = false
if C_SmallBody and C_Body > 0 and C_BodyLo > hl2 and C_DnShadow >= C_Factor * C_Body and not C_HasUpShadow
if C_DownTrend
C_HammerBullish := true
C_HammerBullish
alertcondition(C_HammerBullish, title='Hammer', message='New Hammer - Bullish pattern detected.')
if C_HammerBullish and HammerInput and showBullishSignal
string sMsg = 'Hammer\nHammer candlesticks form when a security moves lower after the open, but continues to rally into close above the intraday low. The candlestick that you are left with will look like a square attached to a long stick-like figure. This candlestick is called a Hammer if it happens to form during a decline.'
string sLabel = 'H'
setPatternIndicatorLabel( lblValue = sLabel, tooltip = sMsg, lblColor = bullishColor, lblStyle = bullishLabel, txtColor = textColor, lblLocation = patternLabelPosLow )
C_HangingManBearishNumberOfCandles = 1
C_HangingManBearish = false
if C_SmallBody and C_Body > 0 and C_BodyLo > hl2 and C_DnShadow >= C_Factor * C_Body and not C_HasUpShadow
if C_UpTrend
C_HangingManBearish := true
C_HangingManBearish
alertcondition(C_HangingManBearish, title='Hanging Man', message='New Hanging Man - Bearish pattern detected.')
if C_HangingManBearish and HangingManInput and showBearishSignal
string sMsg = 'Hanging Man\nWhen a specified security notably moves lower after the open, but continues to rally to close above the intraday low, a Hanging Man candlestick will form. The candlestick will resemble a square, attached to a long stick-like figure. It is referred to as a Hanging Man if the candlestick forms during an advance.'
string sLabel = 'HM'
setPatternIndicatorLabel( lblValue = sLabel, tooltip = sMsg, lblColor = bearishColor, lblStyle = bearishLabel, txtColor = textColor, lblLocation = patternLabelPosHigh )
C_ShootingStarBearishNumberOfCandles = 1
C_ShootingStarBearish = false
if C_SmallBody and C_Body > 0 and C_BodyHi < hl2 and C_UpShadow >= C_Factor * C_Body and not C_HasDnShadow
if C_UpTrend
C_ShootingStarBearish := true
C_ShootingStarBearish
alertcondition(C_ShootingStarBearish, title='Shooting Star', message='New Shooting Star - Bearish pattern detected.')
if C_ShootingStarBearish and ShootingStarInput and showBearishSignal
string sMsg = 'Shooting Star\nThis single day pattern can appear during an uptrend and opens high, while it closes near its open. It trades much higher as well. It is bearish in nature, but looks like an Inverted Hammer.'
string sLabel = 'SS'
setPatternIndicatorLabel( lblValue = sLabel, tooltip = sMsg, lblColor = bearishColor, lblStyle = bearishLabel, txtColor = textColor, lblLocation = patternLabelPosHigh )
C_InvertedHammerBullishNumberOfCandles = 1
C_InvertedHammerBullish = false
if C_SmallBody and C_Body > 0 and C_BodyHi < hl2 and C_UpShadow >= C_Factor * C_Body and not C_HasDnShadow
if C_DownTrend
C_InvertedHammerBullish := true
C_InvertedHammerBullish
alertcondition(C_InvertedHammerBullish, title='Inverted Hammer', message='New Inverted Hammer - Bullish pattern detected.')
if C_InvertedHammerBullish and InvertedHammerInput and showBullishSignal
string sMsg = 'Inverted Hammer\nIf in a downtrend, then the open is lower. When it eventually trades higher, but closes near its open, it will look like an inverted version of the Hammer Candlestick. This is a one-day bullish reversal pattern.'
string sLabel = 'IH'
setPatternIndicatorLabel( lblValue = sLabel, tooltip = sMsg, lblColor = bullishColor, lblStyle = bullishLabel, txtColor = textColor, lblLocation = patternLabelPosLow )
C_MorningStarBullishNumberOfCandles = 3
C_MorningStarBullish = false
if C_LongBody[2] and C_SmallBody[1] and C_LongBody
if C_DownTrend and C_BlackBody[2] and C_BodyHi[1] < C_BodyLo[2] and C_WhiteBody and C_BodyHi >= C_BodyMiddle[2] and C_BodyHi < C_BodyHi[2] and C_BodyHi[1] < C_BodyLo
C_MorningStarBullish := true
C_MorningStarBullish
alertcondition(C_MorningStarBullish, title='Morning Star', message='New Morning Star - Bullish pattern detected.')
if C_MorningStarBullish and MorningStarInput and showBullishSignal
var sMsg = 'Morning Star\nA three-day bullish reversal pattern, which consists of three candlesticks will look something like this: The first being a long-bodied red candle that extends the current downtrend. Next comes a short, middle candle that gaps down on the open. After comes a long-bodied green candle, which gaps up on the open and closes above the midpoint of the body of the first day.'
var sLabel = 'MS'
setPatternIndicatorLabel( lblValue = sLabel, tooltip = sMsg, lblColor = bullishColor, lblStyle = bullishLabel, txtColor = textColor, lblLocation = patternLabelPosLow )
C_EveningStarBearishNumberOfCandles = 3
C_EveningStarBearish = false
if C_LongBody[2] and C_SmallBody[1] and C_LongBody
if C_UpTrend and C_WhiteBody[2] and C_BodyLo[1] > C_BodyHi[2] and C_BlackBody and C_BodyLo <= C_BodyMiddle[2] and C_BodyLo > C_BodyLo[2] and C_BodyLo[1] > C_BodyHi
C_EveningStarBearish := true
C_EveningStarBearish
alertcondition(C_EveningStarBearish, title='Evening Star', message='New Evening Star - Bearish pattern detected.')
if C_EveningStarBearish and EveningStarInput and showBearishSignal
string sMsg = 'Evening Star\nThis candlestick pattern is bearish and continues an uptrend with a long-bodied, green candle day. It is then followed by a gapped and small-bodied candle day, and concludes with a downward close. The close would be below the first day’s midpoint.'
string sLabel = 'ES'
setPatternIndicatorLabel( lblValue = sLabel, tooltip = sMsg, lblColor = bearishColor, lblStyle = bearishLabel, txtColor = textColor, lblLocation = patternLabelPosHigh )
C_MarubozuWhiteBullishNumberOfCandles = 1
C_MarubozuShadowPercentWhite = 5.0
C_MarubozuWhiteBullish = C_WhiteBody and C_LongBody and C_UpShadow <= C_MarubozuShadowPercentWhite / 100 * C_Body and C_DnShadow <= C_MarubozuShadowPercentWhite / 100 * C_Body and C_WhiteBody
alertcondition(C_MarubozuWhiteBullish, title='Marubozu White 光头光脚阳线', message='New Marubozu White - Bullish pattern detected.')
if C_MarubozuWhiteBullish and MarubozuWhiteInput and showBullishSignal
string sMsg = 'Marubozu White\nA Marubozu White Candle is a candlestick that does not have a shadow that extends from its candle body at either the open or the close. Marubozu is Japanese for “close-cropped” or “close-cut.” Other sources may call it a Bald or Shaven Head Candle.'
string sLabel = 'MW'
setPatternIndicatorLabel( lblValue = sLabel, tooltip = sMsg, lblColor = bullishColor, lblStyle = bullishLabel, txtColor = textColor, lblLocation = patternLabelPosLow )
C_MarubozuBlackBearishNumberOfCandles = 1
C_MarubozuShadowPercentBearish = 5.0
C_MarubozuBlackBearish = C_BlackBody and C_LongBody and C_UpShadow <= C_MarubozuShadowPercentBearish / 100 * C_Body and C_DnShadow <= C_MarubozuShadowPercentBearish / 100 * C_Body and C_BlackBody
alertcondition(C_MarubozuBlackBearish, title='Marubozu Black', message='New Marubozu Black - Bearish pattern detected.')
if C_MarubozuBlackBearish and MarubozuBlackInput and showBearishSignal
string sMsg = 'Marubozu Black\nThis is a candlestick that has no shadow, which extends from the red-bodied candle at the open, the close, or even at both. In Japanese, the name means “close-cropped” or “close-cut.” The candlestick can also be referred to as Bald or Shaven Head.'
string sLabel = 'MB'
setPatternIndicatorLabel( lblValue = sLabel, tooltip = sMsg, lblColor = bearishColor, lblStyle = bearishLabel, txtColor = textColor, lblLocation = patternLabelPosHigh )
C_DojiNumberOfCandles = 1
C_DragonflyDoji = C_IsDojiBody and C_UpShadow <= C_Body
C_GravestoneDojiOne = C_IsDojiBody and C_DnShadow <= C_Body
alertcondition(C_Doji and not C_DragonflyDoji and not C_GravestoneDojiOne, title='Doji', message='New Doji pattern detected.')
if C_Doji and not C_DragonflyDoji and not C_GravestoneDojiOne and DojiInput and showNeutralSignal
string sMsg = 'Doji\nWhen the open and close of a security are essentially equal to each other, a doji candle forms. The length of both upper and lower shadows may vary, causing the candlestick you are left with to either resemble a cross, an inverted cross, or a plus sign. Doji candles show the playout of buyer-seller indecision in a tug-of-war of sorts. As price moves either above or below the opening level during the session, the close is either at or near the opening level.'
string sLabel = 'D'
setPatternIndicatorLabel(lblValue = sLabel, tooltip = sMsg, lblColor = neutralColor, lblStyle = neutralLabel, txtColor = textColor, lblLocation = patternLabelPosLow )
C_GravestoneDojiBearishNumberOfCandles = 1
C_GravestoneDojiBearish = C_IsDojiBody and C_DnShadow <= C_Body
alertcondition(C_GravestoneDojiBearish, title='Gravestone Doji', message='New Gravestone Doji - Bearish pattern detected.')
if C_GravestoneDojiBearish and GravestoneDojiInput and showBearishSignal
string sMsg = 'Gravestone Doji\nWhen a doji is at or is close to the day’s low point, a doji line will develop.'
string sLabel = 'GD'
setPatternIndicatorLabel( lblValue = sLabel, tooltip = sMsg, lblColor = bearishColor, lblStyle = bearishLabel, txtColor = textColor, lblLocation = patternLabelPosHigh )
C_DragonflyDojiBullishNumberOfCandles = 1
C_DragonflyDojiBullish = C_IsDojiBody and C_UpShadow <= C_Body
alertcondition(C_DragonflyDojiBullish, title='Dragonfly Doji', message='New Dragonfly Doji - Bullish pattern detected.')
if C_DragonflyDojiBullish and DragonflyDojiInput and showBullishSignal
string sMsg = 'Dragonfly Doji\nSimilar to other Doji days, this particular Doji also regularly appears at pivotal market moments. This is a specific Doji where both the open and close price are at the high of a given day.'
string sLabel = 'DD'
setPatternIndicatorLabel( lblValue = sLabel, tooltip = sMsg, lblColor = bullishColor, lblStyle = bullishLabel, txtColor = textColor, lblLocation = patternLabelPosLow )
C_HaramiCrossBullishNumberOfCandles = 2
C_HaramiCrossBullish = C_LongBody[1] and C_BlackBody[1] and C_DownTrend[1] and C_IsDojiBody and high <= C_BodyHi[1] and low >= C_BodyLo[1]
alertcondition(C_HaramiCrossBullish, title='Harami Cross', message='New Harami Cross - Bullish pattern detected.')
if C_HaramiCrossBullish and HaramiCrossInput and showBullishSignal
string sMsg = 'Harami Cross\nThis candlestick pattern is a variation of the Harami Bullish pattern. It is found during a downtrend. The two-day candlestick pattern consists of a Doji candle that is entirely encompassed within the body of what was once a red-bodied candle.'
string sLabel = 'HC'
setPatternIndicatorLabel( lblValue = sLabel, tooltip = sMsg, lblColor = bullishColor, lblStyle = bullishLabel, txtColor = textColor, lblLocation = patternLabelPosLow )
C_HaramiCrossBearishNumberOfCandles = 2
C_HaramiCrossBearish = C_LongBody[1] and C_WhiteBody[1] and C_UpTrend[1] and C_IsDojiBody and high <= C_BodyHi[1] and low >= C_BodyLo[1]
alertcondition(C_HaramiCrossBearish, title='Harami Cross', message='New Harami Cross - Bearish pattern detected.')
if C_HaramiCrossBearish and HaramiCrossInput and showBearishSignal
string sMsg = 'Harami Cross\nThis candlestick pattern is a variation of the Harami Bearish pattern. It is found during an uptrend. This is a two-day candlestick pattern with a Doji candle that is entirely encompassed within the body that was once a green-bodied candle. The Doji shows that some indecision has entered the minds of sellers, and the pattern hints that the trend might reverse.'
string sLabel = 'HC'
setPatternIndicatorLabel( lblValue = sLabel, tooltip = sMsg, lblColor = bearishColor, lblStyle = bearishLabel, txtColor = textColor, lblLocation = patternLabelPosHigh )
C_HaramiBullishNumberOfCandles = 2
C_HaramiBullish = C_LongBody[1] and C_BlackBody[1] and C_DownTrend[1] and C_WhiteBody and C_SmallBody and high <= C_BodyHi[1] and low >= C_BodyLo[1]
alertcondition(C_HaramiBullish, title='Harami', message='New Harami - Bullish pattern detected.')
if C_HaramiBullish and HaramiInput and showBullishSignal
string sMsg = 'Harami\nThis two-day candlestick pattern consists of a small-bodied green candle that is entirely encompassed within the body of what was once a red-bodied candle.'
string sLabel = 'BH'
setPatternIndicatorLabel( lblValue = sLabel, tooltip = sMsg, lblColor = bullishColor, lblStyle = bullishLabel, txtColor = textColor, lblLocation = patternLabelPosLow )
C_HaramiBearishNumberOfCandles = 2
C_HaramiBearish = C_LongBody[1] and C_WhiteBody[1] and C_UpTrend[1] and C_BlackBody and C_SmallBody and high <= C_BodyHi[1] and low >= C_BodyLo[1]
alertcondition(C_HaramiBearish, title='Harami', message='New Harami - Bearish pattern detected.')
if C_HaramiBearish and HaramiInput and showBearishSignal
string sMsg = 'Harami\nThis is a two-day candlestick pattern with a small, red-bodied candle that is entirely encompassed within the body that was once a green-bodied candle.'
string sLabel = 'BH'
setPatternIndicatorLabel( lblValue = sLabel, tooltip = sMsg, lblColor = bearishColor, lblStyle = bearishLabel, txtColor = textColor, lblLocation = patternLabelPosHigh )
C_LongLowerShadowBullishNumberOfCandles = 1
C_LongLowerShadowPercent = 75.0
C_LongLowerShadowBullish = C_DnShadow > C_Range / 100 * C_LongLowerShadowPercent
alertcondition(C_LongLowerShadowBullish, title='Long Lower Shadow', message='New Long Lower Shadow - Bullish pattern detected.')
if C_LongLowerShadowBullish and LongLowerShadowInput and showBullishSignal
string sMsg = 'Long Lower Shadow\nTo indicate seller domination of the first part of a session, candlesticks will present with long lower shadows and short upper shadows, consequently lowering prices.'
string sLabel = 'LLS'
setPatternIndicatorLabel( lblValue = sLabel, tooltip = sMsg, lblColor = bullishColor, lblStyle = bullishLabel, txtColor = textColor, lblLocation = patternLabelPosLow )
C_LongUpperShadowBearishNumberOfCandles = 1
C_LongShadowPercent = 75.0
C_LongUpperShadowBearish = C_UpShadow > C_Range / 100 * C_LongShadowPercent
alertcondition(C_LongUpperShadowBearish, title='Long Upper Shadow', message='New Long Upper Shadow - Bearish pattern detected.')
if C_LongUpperShadowBearish and LongUpperShadowInput and showBearishSignal
string sMsg = 'Long Upper Shadow\nTo indicate buyer domination of the first part of a session, candlesticks will present with long upper shadows, as well as short lower shadows, consequently raising bidding prices.'
string sLabel = 'LUS'
setPatternIndicatorLabel( lblValue = sLabel, tooltip = sMsg, lblColor = bearishColor, lblStyle = bearishLabel, txtColor = textColor, lblLocation = patternLabelPosHigh )
C_SpinningTopWhiteNumberOfCandles = 1
C_SpinningTopWhitePercent = 34.0
C_IsSpinningTopWhite = C_DnShadow >= C_Range / 100 * C_SpinningTopWhitePercent and C_UpShadow >= C_Range / 100 * C_SpinningTopWhitePercent and not C_IsDojiBody
C_SpinningTopWhite = C_IsSpinningTopWhite and C_WhiteBody
alertcondition(C_SpinningTopWhite, title='Spinning Top White', message='New Spinning Top White pattern detected.')
if C_SpinningTopWhite and SpinningTopWhiteInput and showNeutralSignal
string sMsg = 'Spinning Top White\nWhite spinning tops are candlestick lines that are small, green-bodied, and possess shadows (upper and lower) that end up exceeding the length of candle bodies. They often signal indecision between buyer and seller.'
string sLabel = 'STW'
setPatternIndicatorLabel(lblValue = sLabel, tooltip = sMsg, lblColor = neutralColor, lblStyle = neutralLabel, txtColor = textColor, lblLocation = patternLabelPosLow )
C_SpinningTopBlackNumberOfCandles = 1
C_SpinningTopBlackPercent = 34.0
C_IsSpinningTop = C_DnShadow >= C_Range / 100 * C_SpinningTopBlackPercent and C_UpShadow >= C_Range / 100 * C_SpinningTopBlackPercent and not C_IsDojiBody
C_SpinningTopBlack = C_IsSpinningTop and C_BlackBody
alertcondition(C_SpinningTopBlack, title='Spinning Top Black', message='New Spinning Top Black pattern detected.')
if C_SpinningTopBlack and SpinningTopBlackInput and showNeutralSignal
string sMsg = 'Spinning Top Black\nBlack spinning tops are candlestick lines that are small, red-bodied, and possess shadows (upper and lower) that end up exceeding the length of candle bodies. They often signal indecision.'
string sLabel = 'STB'
setPatternIndicatorLabel(lblValue = sLabel, tooltip = sMsg, lblColor = neutralColor, lblStyle = neutralLabel, txtColor = textColor, lblLocation = patternLabelPosLow )
C_ThreeWhiteSoldiersBullishNumberOfCandles = 3
C_3WSld_ShadowPercent = 5.0
C_3WSld_HaveNotUpShadow = C_Range * C_3WSld_ShadowPercent / 100 > C_UpShadow
C_ThreeWhiteSoldiersBullish = false
if C_LongBody and C_LongBody[1] and C_LongBody[2]
if C_WhiteBody and C_WhiteBody[1] and C_WhiteBody[2]
C_ThreeWhiteSoldiersBullish := close > close[1] and close[1] > close[2] and open < close[1] and open > open[1] and open[1] < close[2] and open[1] > open[2] and C_3WSld_HaveNotUpShadow and C_3WSld_HaveNotUpShadow[1] and C_3WSld_HaveNotUpShadow[2]
C_ThreeWhiteSoldiersBullish
alertcondition(C_ThreeWhiteSoldiersBullish, title='Three White Soldiers', message='New Three White Soldiers - Bullish pattern detected.')
if C_ThreeWhiteSoldiersBullish and ThreeWhiteSoldiersInput and showBullishSignal
string sMsg = 'Three White Soldiers\nThis bullish reversal pattern is made up of three long-bodied, green candles in immediate succession. Each one opens within the body before it and the close is near to the daily high.'
string sLabel = '3WS'
setPatternIndicatorLabel( lblValue = sLabel, tooltip = sMsg, lblColor = bullishColor, lblStyle = bullishLabel, txtColor = textColor, lblLocation = patternLabelPosLow )
C_ThreeBlackCrowsBearishNumberOfCandles = 3
C_3BCrw_ShadowPercent = 5.0
C_3BCrw_HaveNotDnShadow = C_Range * C_3BCrw_ShadowPercent / 100 > C_DnShadow
C_ThreeBlackCrowsBearish = false
if C_LongBody and C_LongBody[1] and C_LongBody[2]
if C_BlackBody and C_BlackBody[1] and C_BlackBody[2]
C_ThreeBlackCrowsBearish := close < close[1] and close[1] < close[2] and open > close[1] and open < open[1] and open[1] > close[2] and open[1] < open[2] and C_3BCrw_HaveNotDnShadow and C_3BCrw_HaveNotDnShadow[1] and C_3BCrw_HaveNotDnShadow[2]
C_ThreeBlackCrowsBearish
alertcondition(C_ThreeBlackCrowsBearish, title='Three Black Crows', message='New Three Black Crows - Bearish pattern detected.')
if C_ThreeBlackCrowsBearish and ThreeBlackCrowsInput and showBearishSignal
string sMsg = 'Three Black Crows\nThis is a bearish reversal pattern that consists of three long, red-bodied candles in immediate succession. For each of these candles, each day opens within the body of the day before and closes either at or near its low.'
string sLabel = '3BC'
setPatternIndicatorLabel( lblValue = sLabel, tooltip = sMsg, lblColor = bearishColor, lblStyle = bearishLabel, txtColor = textColor, lblLocation = patternLabelPosHigh )
C_EngulfingBullishNumberOfCandles = 2
C_EngulfingBullish = C_DownTrend and C_WhiteBody and C_LongBody and C_BlackBody[1] and C_SmallBody[1] and close >= open[1] and open <= close[1] and (close > open[1] or open < close[1])
alertcondition(C_EngulfingBullish, title='Engulfing', message='New Engulfing - Bullish pattern detected.')
if C_EngulfingBullish and BullishEngulfingInput and showBullishSignal
string sMsg = 'Engulfing\nAt the end of a given downward trend, there will most likely be a reversal pattern. To distinguish the first day, this candlestick pattern uses a small body, followed by a day where the candle body fully overtakes the body from the day before, and closes in the trend’s opposite direction. Although similar to the outside reversal chart pattern, it is not essential for this pattern to completely overtake the range (high to low), rather only the open and the close.'
string sLabel = 'BE'
setPatternIndicatorLabel( lblValue = sLabel, tooltip = sMsg, lblColor = bullishColor, lblStyle = bullishLabel, txtColor = textColor, lblLocation = patternLabelPosLow )
C_EngulfingBearishNumberOfCandles = 2
C_EngulfingBearish = C_UpTrend and C_BlackBody and C_LongBody and C_WhiteBody[1] and C_SmallBody[1] and close <= open[1] and open >= close[1] and (close < open[1] or open > close[1])
alertcondition(C_EngulfingBearish, title='Engulfing', message='New Engulfing - Bearish pattern detected.')
if C_EngulfingBearish and BearishEngulfingInput and showBearishSignal
string sMsg = 'Engulfing\nAt the end of a given uptrend, a reversal pattern will most likely appear. During the first day, this candlestick pattern uses a small body. It is then followed by a day where the candle body fully overtakes the body from the day before it and closes in the trend’s opposite direction. Although similar to the outside reversal chart pattern, it is not essential for this pattern to fully overtake the range (high to low), rather only the open and the close.'
string sLabel = 'BE'
setPatternIndicatorLabel( lblValue = sLabel, tooltip = sMsg, lblColor = bearishColor, lblStyle = bearishLabel, txtColor = textColor, lblLocation = patternLabelPosHigh )
C_AbandonedBabyBullishNumberOfCandles = 3
C_AbandonedBabyBullish = C_DownTrend[2] and C_BlackBody[2] and C_IsDojiBody[1] and low[2] > high[1] and C_WhiteBody and high[1] < low
alertcondition(C_AbandonedBabyBullish, title='Abandoned Baby', message='New Abandoned Baby - Bullish pattern detected.')
if C_AbandonedBabyBullish and BullishAbandonedBabyInput and showBullishSignal
string sMsg = 'Abandoned Baby\nThis candlestick pattern is quite rare as far as reversal patterns go. The first of the pattern is a large down candle. Next comes a doji candle that gaps below the candle before it. The doji candle is then followed by another candle that opens even higher and swiftly moves to the upside.'
string sLabel= 'AB'
setPatternIndicatorLabel( lblValue = sLabel, tooltip = sMsg, lblColor = bullishColor, lblStyle = bullishLabel, txtColor = textColor, lblLocation = patternLabelPosLow )
C_AbandonedBabyBearishNumberOfCandles = 3
C_AbandonedBabyBearish = C_UpTrend[2] and C_WhiteBody[2] and C_IsDojiBody[1] and high[2] < low[1] and C_BlackBody and low[1] > high
alertcondition(C_AbandonedBabyBearish, title='Abandoned Baby', message='New Abandoned Baby - Bearish pattern detected.')
if C_AbandonedBabyBearish and AbandonedBabyInput and showBearishSignal
string sMsg = 'Abandoned Baby\nA bearish abandoned baby is a specific candlestick pattern that often signals a downward reversal trend in terms of security price. It is formed when a gap appears between the lowest price of a doji-like candle and the candlestick of the day before. The earlier candlestick is green, tall, and has small shadows. The doji candle is also tailed by a gap between its lowest price point and the highest price point of the candle that comes next, which is red, tall and also has small shadows. The doji candle shadows must completely gap either below or above the shadows of the first and third day in order to have the abandoned baby pattern effect.'
string sLabel = 'AB'
setPatternIndicatorLabel( lblValue = sLabel, tooltip = sMsg, lblColor = bearishColor, lblStyle = bearishLabel, txtColor = textColor, lblLocation = patternLabelPosHigh )
C_TriStarBullishNumberOfCandles = 3
C_3DojisBullish = C_Doji[2] and C_Doji[1] and C_Doji
C_BodyGapUpBullish = C_BodyHi[1] < C_BodyLo
C_BodyGapDnBullish = C_BodyLo[1] > C_BodyHi
C_TriStarBullish = C_3DojisBullish and C_DownTrend[2] and C_BodyGapDnBullish[1] and C_BodyGapUpBullish
alertcondition(C_TriStarBullish, title='Tri-Star', message='New Tri-Star - Bullish pattern detected.')
if C_TriStarBullish and TriStarInput and showBullishSignal
string sMsg = 'Tri-Star\nA bullish TriStar candlestick pattern can form when three doji candlesticks materialize in immediate succession at the tail-end of an extended downtrend. The first doji candle marks indecision between bull and bear. The second doji gaps in the direction of the leading trend. The third changes the attitude of the market once the candlestick opens in the direction opposite to the trend. Each doji candle has a shadow, all comparatively shallow, which signify an interim cutback in volatility.'
string sLabel = '3S'
setPatternIndicatorLabel( lblValue = sLabel, tooltip = sMsg, lblColor = bullishColor, lblStyle = bullishLabel, txtColor = textColor, lblLocation = patternLabelPosLow )
C_TriStarBearishNumberOfCandles = 3
C_3Dojis = C_Doji[2] and C_Doji[1] and C_Doji
C_BodyGapUp = C_BodyHi[1] < C_BodyLo
C_BodyGapDn = C_BodyLo[1] > C_BodyHi
C_TriStarBearish = C_3Dojis and C_UpTrend[2] and C_BodyGapUp[1] and C_BodyGapDn
alertcondition(C_TriStarBearish, title='Tri-Star', message='New Tri-Star - Bearish pattern detected.')
if C_TriStarBearish and BearishTriStarInput and showBearishSignal
string sMsg = 'Tri-Star\nThis particular pattern can form when three doji candlesticks appear in immediate succession at the end of an extended uptrend. The first doji candle marks indecision between bull and bear. The second doji gaps in the direction of the leading trend. The third changes the attitude of the market once the candlestick opens in the direction opposite to the trend. Each doji candle has a shadow, all comparatively shallow, which signify an interim cutback in volatility.'
string sLabel = '3S'
setPatternIndicatorLabel( lblValue = sLabel, tooltip = sMsg, lblColor = bearishColor, lblStyle = bearishLabel, txtColor = textColor, lblLocation = patternLabelPosHigh )
C_KickingBullishNumberOfCandles = 2
C_MarubozuShadowPercent = 5.0
C_Marubozu = C_LongBody and C_UpShadow <= C_MarubozuShadowPercent / 100 * C_Body and C_DnShadow <= C_MarubozuShadowPercent / 100 * C_Body
C_MarubozuWhiteBullishKicking = C_Marubozu and C_WhiteBody
C_MarubozuBlackBullish = C_Marubozu and C_BlackBody
C_KickingBullish = C_MarubozuBlackBullish[1] and C_MarubozuWhiteBullishKicking and high[1] < low
alertcondition(C_KickingBullish, title='Kicking', message='New Kicking - Bullish pattern detected.')
if C_KickingBullish and KickingInput and showBullishSignal
string sMsg = 'Kicking\nThe first day candlestick is a bearish marubozu candlestick with next to no upper or lower shadow and where the price opens at the day’s high and closes at the day’s low. The second day is a bullish marubozu pattern, with next to no upper or lower shadow and where the price opens at the day’s low and closes at the day’s high. Additionally, the second day gaps up extensively and opens above the opening price of the day before. This gap or window, as the Japanese call it, lies between day one and day two’s bullish candlesticks.'
string sLabel = 'K'
setPatternIndicatorLabel( lblValue = sLabel, tooltip = sMsg, lblColor = bullishColor, lblStyle = bullishLabel, txtColor = textColor, lblLocation = patternLabelPosLow )
C_KickingBearishNumberOfCandles = 2
C_MarubozuBullishShadowPercent = 5.0
C_MarubozuBearishKicking = C_LongBody and C_UpShadow <= C_MarubozuBullishShadowPercent / 100 * C_Body and C_DnShadow <= C_MarubozuBullishShadowPercent / 100 * C_Body
C_MarubozuWhiteBearish = C_MarubozuBearishKicking and C_WhiteBody
C_MarubozuBlackBearishKicking = C_MarubozuBearishKicking and C_BlackBody
C_KickingBearish = C_MarubozuWhiteBearish[1] and C_MarubozuBlackBearishKicking and low[1] > high
alertcondition(C_KickingBearish, title='Kicking', message='New Kicking - Bearish pattern detected.')
if C_KickingBearish and KickingInput and showBearishSignal
string sMsg = 'Kicking\nA bearish kicking pattern will occur, subsequently signaling a reversal for a new downtrend. The first day candlestick is a bullish marubozu. The second day gaps down extensively and opens below the opening price of the day before. There is a gap between day one and two’s bearish candlesticks.'
setPatternIndicatorLabel( lblValue = "K", tooltip = sMsg, lblColor = bearishColor, lblStyle = label.style_label_down, txtColor = textColor, lblLocation = patternLabelPosHigh )
setPatternIndicatorLabel( lblValue = "", tooltip = "", lblColor = bullishColor, lblStyle = bearishLabel, txtColor = bearishColor, lblLocation = patternLabelPosHigh )
sMsg := 'All Candlestick Patterns\n'
setPatternIndicatorLabel( lblValue = "Collection", tooltip = sMsg, lblColor = neutralColor, lblStyle = label.style_label_up, txtColor = textColor, lblLocation = patternLabelPosHigh )