-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathCandlestickPatterns.php
More file actions
2458 lines (2155 loc) · 91.5 KB
/
CandlestickPatterns.php
File metadata and controls
2458 lines (2155 loc) · 91.5 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
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
class CandlestickPatterns
{
public static $candlestick_patterns = array('bearishAbandonedBaby' => 'Bearish Abandonded Baby Reversal',
'bearishAdvanceBlock' => 'Bearish Advance Block Reversal',
'bearishBeltHold' => 'Bearish Belt Hold Reversal',
'bearishBreakaway' => 'Bearish Breakaway Reversal',
'bearishDarkCloudCover' => 'Bearish Dark Cloud Cover Reversal',
'bearishDeliberation' => 'Bearish Deliberation Reversal',
'bearishDojiStar' => 'Bearish Doji Star Reversal',
'bearishDownsideGapThreeMethods' => 'Bearish Downside Gap 3 Methods Continuation',
'bearishDownsideTasukiGap' => 'Bearish Downside Tasuki Gap Continuation',
'bearishEngulfing' => 'Bearish Engulfing Reversal',
'bearishEveningDojiStar' => 'Bearish Evening Doji Star Reversal',
'bearishEveningStar' => 'Bearish Evening Star Reversal',
'bearishFallingThreeMethods' => 'Bearish Falling 3 Methods Continuation',
'bearishHangingMan' => 'Bearish Hanging Man Reversal',
'bearishHarami' => 'Bearish Harami Reversal',
'bearishHaramiCross' => 'Bearish Harami Cross Reversal',
'bearishIdenticalThreeCrows' => 'Bearish Identical 3 Crows Reversal',
'bearishInNeck' => 'Bearish In-Neck Continuation',
'bearishKicking' => 'Bearish Kicking Reversal',
'bearishMeetingLines' => 'Bearish Meeting Lines Reversal',
'bearishOnNeck' => 'Bearish On-Neck Continuation',
'bearishSeparatingLines' => 'Bearish Separating Lines Continuation',
'bearishShootingStar' => 'Bearish Shooting Star Reversal',
'bearishSideBySideWhiteLines' => 'Bearish Side-By-Side White Lines Continuation',
'bearishThreeBlackCrows' => 'Bearish 3 Black Crows Reversal',
'bearishThreeInsideDown' => 'Bearish 3 Inside Down Reversal',
'bearishThreeLineStrike' => 'Bearish 3-Line Strike Continuation',
'bearishThreeOutsideDown' => 'Bearish 3 Outside Down Reversal',
'bearishThrusting' => 'Bearish Thrusting Continuation',
'bearishTriStar' => 'Bearish Tri-Star Reversal',
'bearishTweezerTop' => 'Bearish Tweezer Top Reversal',
'bearishTwoCrows' => 'Bearish 2 Crows Reversal',
'bearishUpsideGapTwoCrows' => 'Bearish Upside Gap 2 Crows Reversal',
'bullishAbandonedBaby' => 'Bullish Abandonded Baby Reversal',
'bullishBeltHold' => 'Bullish Belt Hold Reversal',
'bullishBreakaway' => 'Bullish Breakaway Reversal',
'bullishConcealingBabySwallow' => 'Bullish Concealing Baby Swallow Reversal',
'bullishDojiStar' => 'Bullish Doji Star Reversal',
'bullishEngulfing' => 'Bullish Engulfing Reversal',
'bullishHammer' => 'Bullish Hammer Reversal',
'bullishHarami' => 'Bullish Harami Reversal',
'bullishHaramiCross' => 'Bullish Harami Cross Reversal',
'bullishHomingPigeon' => 'Bullish Homing Pigeon Reversal',
'bullishInvertedHammer' => 'Bullish Inverted Hammer Reversal',
'bullishKicking' => 'Bullish Kicking Reversal',
'bullishLadderBottom' => 'Bullish Ladder Bottom Reversal',
'bullishMatHold' => 'Bullish Mat Hold Continuation',
'bullishMatchingLow' => 'Bullish Matching Low Reversal',
'bullishMeetingLines' => 'Bullish Meeting Lines Reversal',
'bullishMorningDojiStar' => 'Bullish Morning Doji Star Reversal',
'bullishMorningStar' => 'Bullish Morning Star Reversal',
'bullishPiercingLine' => 'Bullish Piercing Line Reversal',
'bullishRisingThreeMethods' => 'Bullish Rising 3 Methods Continuation',
'bullishSeparatingLines' => 'Bullish Separating Lines Continuation',
'bullishSideBySideWhiteLines' => 'Bullish Side-By-Side White Lines Continuation',
'bullishStickSandwich' => 'Bullish Stick Sandwich Reversal',
'bullishThreeInsideUp' => 'Bullish 3 Inside Up Reversal',
'bullishThreeLineStrike' => 'Bullish 3-Line Strike Continuation',
'bullishThreeOutsideUp' => 'Bullish 3 Outside Up Reversal',
'bullishThreeStarsInTheSouth' => 'Bullish 3 Stars In The South Reversal',
'bullishThreeWhiteSoldiers' => 'Bullish 3 White Soldiers Reversal',
'bullishTriStar' => 'Bullish Tri-Star Reversal',
'bullishTweezerBottom' => 'Bullish Tweezer Bottom Reversal',
'bullishUniqueThreeRiverBottom' => 'Bullish Unique 3 River Bottom Reversal',
'bullishUpsideGapThreeMethods' => 'Bullish Upside Gap 3 Methods Continuation',
'bullishUpsideTasukiGap' => 'Bullish Upside Tasuki Gap Continuation'
);
public static $candlestick_patterns_requiring_confirmation = array('bearishAbandonedBaby' => 'Watch for additional downside price action in the next few days.',
'bearishDeliberation' => 'Profit takers will quickly appear if the next day opens lower. Anticipate a Bearish Evening Star pattern.',
'bearishDojiStar' => 'Profit takers will quickly appear if the next day opens lower. Anticipate a Bearish Evening Doji Star pattern.',
'bearishDownsideGapThreeMethods' => 'More investigation of the previous weeks is recommended in order to see if this is the first gap. If so, then this pattern is probably displaying short covering to "close the gap" created and the bearish trend should continue.',
'bearishDownsideTasukiGap' => 'More investigation of the previous weeks is recommended in order to see if this is the first gap. If so, then this pattern is probably displaying short covering to "close the gap" created and the bearish trend should continue.',
'bearishEngulfing' => 'Confirmed by the Bearish 3 Outside Down pattern.',
'bearishEveningDojiStar' => 'If the penetration of the 3rd day is more than 50 percent, then this formation has a much better chance to succeed for the trader.',
'bearishEveningStar' => 'If the penetration of the 3rd day is more than 50 percent, then this formation has a much better chance to succeed for the trader.',
//'',
'bullishSeparatingLines' => 'The uptrend should resume.'
);
public function __construct() {
}
protected static function closeInPreviousBody($a, $b) {
if (min($a['open'], $a['close']) < $b['close'] and max($a['open'], $a['close']) > $b['close']) {
return true;
}
return false;
}
protected static function doji($a) {
$body_size = max($a['open'], $a['close'])-min($a['open'], $a['close']);
$upper_shadow = $a['high']-max($a['open'], $a['close']);
$lower_shadow = min($a['open'], $a['close'])-$a['low'];
if ($upper_shadow > $body_size and
$lower_shadow > $body_size) {
return true;
}
return false;
}
protected static function downCandle($a) {
if ($a['open'] > $a['close']) {
return true;
}
return false;
}
protected static function dragonflyDoji($a) {
if ($a['open'] === $a['high'] and
$a['high'] === $a['close'] and
$a['close'] > $a['low']) {
return true;
}
return false;
}
protected static function engulfing($a, $b) {
if ($a['high'] <= max($b['open'], $b['close']) and
$a['low'] >= min($b['open'], $b['close']) and
$a['open'] < max($b['open'], $b['close']) and
$a['open'] > min($b['open'], $b['close']) and
$a['close'] < max($b['open'], $b['close']) and
$a['close'] > min($b['open'], $b['close'])) {
return true;
}
return false;
}
protected static function fullEngulfing($a, $b) {
if ($a['high'] < max($b['open'], $b['close']) and
$a['high'] > min($b['open'], $b['close']) and
$a['low'] < max($b['open'], $b['close']) and
$a['low'] > min($b['open'], $b['close'])) {
return true;
}
return false; }
protected static function gappedDown($a, $b) {
if ($a['low'] > $b['high']) {
return true;
}
return false;
}
protected static function gappedDownClose($a, $b) {
if (min($a['open'], $a['close']) > $b['close']) {
return true;
}
return false;
}
protected static function gappedDownOpen($a, $b) {
if (min($a['open'], $a['close']) > $b['open']) {
return true;
}
return false;
}
protected static function gappedUp($a, $b) {
if ($a['high'] < $b['low']) {
return true;
}
return false;
}
protected static function gappedUpClose($a, $b) {
if (max($a['open'], $a['close']) < $b['close']) {
return true;
}
return false;
}
protected static function gappedUpOpen($a, $b) {
if (max($a['open'], $a['close']) < $b['open']) {
return true;
}
return false;
}
protected static function hammer($a) {
$upper_shadow = $a['high']-max($a['open'], $a['close']);
$lower_shadow = min($a['open'], $a['close'])-$a['low'];
$body = abs($a['open']-$a['close']);
if ($a['high'] >= max($a['open'], $a['close']) and
$upper_shadow < $body and
$a['low'] < min($a['open'], $a['close']) and
$body <= $lower_shadow) {
return true;
}
return false;
}
protected static function hangingMan($a) {
return self::hammer($a);
}
protected static function harami($a, $b) {
if ($b['high'] <= max($a['open'], $a['close']) and
$b['low'] >= min($a['open'], $a['close']) and
$b['open'] < max($a['open'], $a['close']) and
$b['open'] > min($a['open'], $a['close']) and
$b['close'] < max($a['open'], $a['close']) and
$b['close'] > min($a['open'], $a['close'])) {
return true;
}
return false;
}
protected static function higherClose($a, $b) {
if ($b['close'] > $a['close']) {
return true;
}
return false;
}
protected static function higherHighs($a, $b) {
if ($b['high'] > $a['high']) {
return true;
}
return false;
}
protected static function higherHighsHigherLows($a, $b) {
if (self::higherHighs($a, $b)) {
return self::higherLows($a, $b);
}
return false;
}
protected static function higherHighsLowerLows($a, $b) {
if (self::higherHighs($a, $b)) {
return self::lowerLows($a, $b);
}
return false;
}
protected static function higherLows($a, $b) {
if ($b['low'] > $a['low']) {
return true;
}
return false;
}
protected static function higherLowerShadowRatio($a, $b) {
$body_a = max($a['open'], $a['close'])-min($a['open'], $a['close']);
$body_b = max($b['open'], $b['close'])-min($b['open'], $b['close']);
$lower_shadow_a = min($a['open'], $a['close'])-$a['low'];
$lower_shadow_b = min($b['open'], $b['close'])-$b['low'];
$ratio_a = $lower_shadow_a/$body_a;
$ratio_b = $lower_shadow_b/$body_b;
if ($ratio_b > $ratio_a) {
return true;
}
return false;
}
protected static function higherUpperShadowRatio($a, $b) {
$body_a = abs($a['open']-$a['close']);
$body_b = abs($b['open']-$b['close']);
$upper_shadow_a = $a['high']-max($a['open'],$a['close']);
$upper_shadow_b = $b['high']-max($b['open'],$b['close']);
$ratio_a = $upper_shadow_a/$body_a;
$ratio_b = $upper_shadow_b/$body_b;
if ($ratio_b > $ratio_a) {
return true;
}
return false;
}
protected static function highInPreviousBody($a, $b) {
if (min($a['open'], $a['close']) < $b['high'] and max($a['open'], $a['close']) > $b['high']) {
return true;
}
return false;
}
protected static function longBody($a) {
$body = abs($a['open']-$a['close']);
$lower_shadow = min($a['open'],$a['close'])-$a['low'];
$upper_shadow = $a['high']-max($a['open'],$a['close']);
if ($body > $lower_shadow+$upper_shadow) {
return true;
}
return false;
}
protected static function lowerClose($a, $b) {
if ($b['close'] < $a['close']) {
return true;
}
return false;
}
protected static function lowerHighs($a, $b) {
if ($b['high'] < $a['high']) {
return true;
}
return false;
}
protected static function lowerHighsHigherLows($a, $b) {
if (self::lowerHighs($a, $b)) {
return self::higherLows($a, $b);
}
return false;
}
protected static function lowerHighsLowerLows($a, $b) {
if (self::lowerHighs($a, $b)) {
return self::lowerLows($a, $b);
}
return false;
}
protected static function lowerLows($a, $b) {
if ($b['low'] < $a['low']) {
return true;
}
return false;
}
protected static function lowerShadowLong($a) {
$body_size = max($a['open'], $a['close'])-min($a['open'], $a['close']);
$lower_shadow_size = min($a['open'], $a['close'])-$a['low'];
if ($body_size <= $lower_shadow_size) {
return true;
}
return false;
}
protected static function lowInPreviousBody($a, $b) {
if (min($a['open'], $a['close']) < $b['low'] and max($a['open'], $a['close']) > $b['low']) {
return true;
}
return false;
}
protected static function marubozu($a) {
if ($a['high'] === max($a['open'], $a['close']) and
$a['low'] === min($a['open'], $a['close'])) {
return true;
}
else {
$upper_shadow = $a['high']-max($a['open'], $a['close']);
$lower_shadow = min($a['open'], $a['close'])-$a['low'];
$body = max($a['open'], $a['close'])-min($a['open'], $a['close']);
if ($body > 0 and $upper_shadow/$body <= 0.01 and $lower_shadow/$body <= 0.01) {
return true;
}
}
return false;
}
protected static function openInPreviousBody($a, $b) {
if (min($a['open'], $a['close']) < $b['open'] and max($a['open'], $a['close']) > $b['open']) {
return true;
}
return false;
}
protected static function shootingStar($a) {
$body = max($a['open'], $a['close'])-min($a['open'], $a['close']);
$lower_shadow = min($a['open'], $a['close'])-$a['low'];
$upper_shadow = $a['high']-max($a['open'], $a['close']);
if (!self::longBody($a) and
$lower_shadow < $upper_shadow and
$lower_shadow < $body and
$body < $upper_shadow) {
return true;
}
return false;
}
protected static function upCandle($a) {
if ($a['open'] < $a['close']) {
return true;
}
return false;
}
protected static function upperShadowLong($a) {
$body_size = max($a['open'], $a['close'])-min($a['open'], $a['close']);
$upper_shadow_size = $a['high']-max($a['open'], $a['close']);
if ($body_size <= $upper_shadow_size) {
return true;
}
return false;
}
/**
* A Bearish Reversal Pattern
*/
public static function bearishAbandonedBaby($history) {
$third_day = $history['history'][count($history['history'])-1];
$second_day = $history['history'][count($history['history'])-2];
$first_day = $history['history'][count($history['history'])-3];
$prev_one = $history['history'][count($history['history'])-4];
$prev_two = $history['history'][count($history['history'])-5];
/*
During an up trend.
1st day is a up day.
2nd day is a doji whose shadows gap above the 1st day's close.
3rd day is a down day with no overlapping shadows.
*/
if (
(self::higherHighsHigherLows($prev_two, $prev_one) or self::higherLows($prev_two, $first_day)) and
self::higherHighsHigherLows($prev_one, $first_day) and
self::upCandle($first_day) and
(self::doji($second_day) and self::gappedUp($first_day, $second_day)) and
(self::downCandle($third_day) and self::gappedDown($second_day, $third_day))
) {
return true;
}
return false;
}
/**
* A Bearish Reversal Pattern
*/
public static function bearishAdvanceBlock($history) {
$third_day = $history['history'][count($history['history'])-1];
$second_day = $history['history'][count($history['history'])-2];
$first_day = $history['history'][count($history['history'])-3];
$prev_one = $history['history'][count($history['history'])-4];
$prev_two = $history['history'][count($history['history'])-5];
/*
During an up trend.
Three consecutive up days with higher closes each day.
Each day opens within the previous body.
Each day displays deterioration of the upward move as shown with the long upper shadows on the 2nd and 3rd days.
*/
if (
(self::higherHighsHigherLows($prev_two, $prev_one) or self::higherLows($prev_two, $first_day)) and
self::higherHighsHigherLows($prev_one, $first_day) and
self::upCandle($first_day) and
self::upCandle($second_day) and
self::openInPreviousBody($first_day, $second_day) and
self::higherClose($first_day, $second_day) and
self::higherUpperShadowRatio($first_day, $second_day) and
self::upCandle($third_day) and
self::openInPreviousBody($second_day, $third_day) and
self::higherClose($second_day, $third_day) and
self::higherUpperShadowRatio($second_day, $third_day)
) {
return true;
}
return false;
}
/**
* A Bearish Reversal Pattern
*/
public static function bearishBeltHold($history) {
$last_day = $history['history'][count($history['history'])-1];
$prev_one = $history['history'][count($history['history'])-2];
$prev_two = $history['history'][count($history['history'])-3];
/*
During an up trend.
Long down day where the open is equal to the high.
No upper shadow.
*/
if (
(self::higherHighsHigherLows($prev_two, $prev_one) or self::higherLows($prev_two, $last_day)) and
self::gappedUp($prev_one, $last_day) and
!self::lowerShadowLong($last_day) and
self::downCandle($last_day) and
($last_day['open'] === $last_day['high'] and
$last_day['close'] > $last_day['low'])
) {
return true;
}
return false;
}
/**
* A Bearish Reversal Pattern
*/
public static function bearishBreakaway($history) {
$fifth_day = $history['history'][count($history['history'])-1];
$forth_day = $history['history'][count($history['history'])-2];
$third_day = $history['history'][count($history['history'])-3];
$second_day = $history['history'][count($history['history'])-4];
$first_day = $history['history'][count($history['history'])-5];
$prev_one = $history['history'][count($history['history'])-6];
$prev_two = $history['history'][count($history['history'])-7];
/*
During an up trend.
1st day is a long up day.
2nd day is a up day whose open gaps up.
3rd & 4th days close higher each day.
5th day is a long down day that closes inside the gap created by the 1st and 2nd days.
*/
if (
(self::higherHighsHigherLows($prev_two, $prev_one) or self::higherLows($prev_two, $first_day)) and
self::higherHighsHigherLows($prev_one, $first_day) and
self::upCandle($first_day) and
self::longBody($first_day) and
self::upCandle($second_day) and
self::gappedUp($first_day, $second_day) and
self::higherClose($second_day, $third_day) and
self::higherClose($third_day, $forth_day) and
self::downCandle($fifth_day) and
self::longBody($fifth_day) and
($fifth_day['close'] < $second_day['low'] and $fifth_day['close'] > $first_day['high'])
) {
return true;
}
return false;
}
/**
* A Bearish Reversal Pattern
*/
public static function bearishDarkCloudCover($history) {
$second_day = $history['history'][count($history['history'])-1];
$first_day = $history['history'][count($history['history'])-2];
$prev_one = $history['history'][count($history['history'])-3];
$prev_two = $history['history'][count($history['history'])-4];
$first_day_middle = min($first_day['open'], $first_day['close'])+(abs($first_day['open']-$first_day['close'])/2);
/*
1st day is a long up day.
2nd day is a down day which opens above the 1st day's high.
2nd day closes within the 1st day, but below the midpoint.
*/
if (
(self::higherHighsHigherLows($prev_two, $prev_one) or self::higherLows($prev_two, $first_day)) and
self::higherHighsHigherLows($prev_one, $first_day) and
self::upCandle($first_day) and
self::downCandle($second_day) and
($first_day['high'] < $second_day['open']) and
self::closeInPreviousBody($first_day, $second_day) and
($second_day['close'] < $first_day_middle)
) {
return true;
}
return false;
}
/**
* A Bearish Reversal Pattern
*/
public static function bearishDeliberation($history) {
$third_day = $history['history'][count($history['history'])-1];
$second_day = $history['history'][count($history['history'])-2];
$first_day = $history['history'][count($history['history'])-3];
$prev_one = $history['history'][count($history['history'])-4];
$prev_two = $history['history'][count($history['history'])-5];
/*
Three consecutive up days (1st two long days) with higher opens and closes each day.
3rd day gaps above the 2nd day's close. Some texts show the 3rd day as closing near the 2nd day. HotCandlestick.com diverges from this philosophy since any small body candlestick on the 3rd day shows weakness. Some might argue that the greater the gap above the 2nd day, the more likely a short term pullback is in order. Granted, a large gap may signal a continuation of the uptrend, but the opportunity to capitalize on a profit for an immediate pullback prior to the return of the uptrend should not be ignored. Stops should be in place when trading in order to minimize potential losses.
3rd day is usually a spinning top or star (small body).
*/
if (
(self::higherHighsHigherLows($prev_two, $prev_one) or self::higherLows($prev_two, $first_day)) and
self::higherHighsHigherLows($prev_one, $first_day) and
self::upCandle($first_day) and
self::longBody($first_day) and
self::upCandle($second_day) and
self::longBody($second_day) and
($first_day['open'] < $second_day['open'] and $first_day['close'] < $second_day['close']) and
self::gappedUpOpen($second_day, $third_day) and
self::gappedUpClose($second_day, $third_day) and
!self::longBody($third_day)
) {
return true;
}
return false;
}
/**
* A Bearish Reversal Pattern
*/
public static function bearishDojiStar($history) {
$second_day = $history['history'][count($history['history'])-1];
$first_day = $history['history'][count($history['history'])-2];
$prev_one = $history['history'][count($history['history'])-3];
$prev_two = $history['history'][count($history['history'])-4];
/*
1st day is a long up day.
2nd day is a doji day that gaps above the 1st day.
The doji shadows shouldn't be excessively long.
*/
if (
(self::higherHighsHigherLows($prev_two, $prev_one) or self::higherLows($prev_two, $first_day)) and
self::higherHighsHigherLows($prev_one, $first_day) and
self::upCandle($first_day) and
self::gappedUpOpen($first_day, $second_day) and
self::gappedUpClose($first_day, $second_day) and
($first_day['close'] < $second_day['low']) and
self::doji($second_day) and
!self::upperShadowLong($second_day) and
!self::lowerShadowLong($second_day)
) {
return true;
}
return false;
}
/**
* A Bearish Continuation Pattern
*/
public static function bearishDownsideGapThreeMethods($history) {
$third_day = $history['history'][count($history['history'])-1];
$second_day = $history['history'][count($history['history'])-2];
$first_day = $history['history'][count($history['history'])-3];
$prev_one = $history['history'][count($history['history'])-4];
$prev_two = $history['history'][count($history['history'])-5];
/*
After a downtrend.
1st two days are long down days with a gap btween them.
3rd day is an up day that fills the gap of the 1st two days.
*/
if (
(self::lowerHighsLowerLows($prev_two, $prev_one) or self::higherLows($prev_two, $first_day)) and
self::lowerHighsLowerLows($prev_one, $first_day) and
self::longBody($first_day) and self::downCandle($first_day) and
self::longBody($second_day) and self::downCandle($second_day) and
self::gappedDown($first_day, $second_day) and
self::upCandle($third_day) and
self::openInPreviousBody($second_day, $third_day) and
self::openInPreviousBody($first_day, $third_day)
) {
return true;
}
return false;
}
/**
* A Bearish Continuation Pattern
*/
public static function bearishDownsideTasukiGap($history) {
$third_day = $history['history'][count($history['history'])-1];
$second_day = $history['history'][count($history['history'])-2];
$first_day = $history['history'][count($history['history'])-3];
$prev_one = $history['history'][count($history['history'])-4];
$prev_two = $history['history'][count($history['history'])-5];
/*
After an down trend.
1st two days are long down days with a gap btween them.
3rd day is an up day which opens within the body of the 2nd day and closes within the gap between the 1st and 2nd days.
3rd day should not fully close the gap.
*/
if (
(self::lowerHighsLowerLows($prev_two, $prev_one) or self::higherLows($prev_two, $first_day)) and
self::lowerHighsLowerLows($prev_one, $first_day) and
self::downCandle($first_day) and
self::longBody($first_day) and
self::downCandle($second_day) and
self::longBody($second_day) and
self::gappedDown($first_day, $second_day) and
self::upCandle($third_day) and
self::openInPreviousBody($second_day, $third_day) and
($second_day['high'] < $third_day['close'] and
$first_day['low'] > $third_day['close']) and
($first_day['close'] > $third_day['low'])
) {
return true;
}
return false;
}
/**
* A Bearish Reversal Patterns
*/
public static function bearishEngulfing($history) {
$second_day = $history['history'][count($history['history'])-1];
$first_day = $history['history'][count($history['history'])-2];
$prev_one = $history['history'][count($history['history'])-3];
$prev_two = $history['history'][count($history['history'])-4];
/*
After an up trend.
The direction of the 1st day's body reflects the trend, however could be a doji.
The 2nd day's real body engulfs the 1st day's body in the opposite direction.
*/
if (
(self::higherHighsHigherLows($prev_two, $prev_one) or self::higherLows($prev_two, $first_day)) and
self::higherHighsHigherLows($prev_one, $first_day) and
(self::upCandle($first_day) or self::doji($first_day)) and
self::engulfing($first_day, $second_day) and
self::downCandle($second_day)
) {
return true;
}
return false;
}
/**
* A Bearish Reversal Patterns
*/
public static function bearishEveningDojiStar($history) {
$third_day = $history['history'][count($history['history'])-1];
$second_day = $history['history'][count($history['history'])-2];
$first_day = $history['history'][count($history['history'])-3];
$prev_one = $history['history'][count($history['history'])-4];
$prev_two = $history['history'][count($history['history'])-5];
/*
After an up trend.
1st day is a long up day.
2nd day is a doji which gaps above the 1st day's close.
3rd day is a down day.
*/
if (
(self::higherHighsHigherLows($prev_two, $prev_one) or self::higherLows($prev_two, $first_day)) and
self::higherHighsHigherLows($prev_one, $first_day) and
self::upCandle($first_day) and
self::gappedUpOpen($first_day, $second_day) and
self::doji($second_day) and
self::downCandle($third_day) and
self::gappedDownOpen($second_day, $third_day)
) {
return true;
}
return false;
}
/**
* A Bearish Reversal Patterns
*/
public static function bearishEveningStar($history) {
$third_day = $history['history'][count($history['history'])-1];
$second_day = $history['history'][count($history['history'])-2];
$first_day = $history['history'][count($history['history'])-3];
$prev_one = $history['history'][count($history['history'])-4];
$prev_two = $history['history'][count($history['history'])-5];
/*
After an up trend.
1st day is a long up day.
2nd day is a small body day which gaps above the 1st day's close.
3rd day is a long down day.
*/
if (
(self::higherHighsHigherLows($prev_two, $prev_one) or self::higherLows($prev_two, $first_day)) and
self::higherHighsHigherLows($prev_one, $first_day) and
self::upCandle($first_day) and
self::gappedUpOpen($first_day, $second_day) and
self::doji($second_day) and
self::downCandle($third_day) and
self::gappedDownOpen($second_day, $third_day)
) {
return true;
}
return false;
}
/**
* A Bearish Reversal Patterns
*/
public static function bearishFallingThreeMethods($history) {
$last_day = $history['history'][count($history['history'])-1];
$forth_day = $history['history'][count($history['history'])-2];
$third_day = $history['history'][count($history['history'])-3];
$second_day = $history['history'][count($history['history'])-4];
$first_day = $history['history'][count($history['history'])-5];
$prev_one = $history['history'][count($history['history'])-6];
$prev_two = $history['history'][count($history['history'])-7];
/*
1st day is a long down day.
Three small body candlesticks follow the 1st day. Each trends upward and closes within the range of the 1st day.
The last day is a down day which closes below the first day's close.
*/
if (
(self::lowerHighsLowerLows($prev_two, $prev_one) or self::higherLows($prev_two, $first_day)) and
self::lowerHighsLowerLows($prev_one, $first_day) and
self::downCandle($first_day) and
(self::upCandle($second_day) and $second_day['open'] < $first_day['close'] and $second_day['close'] < $first_day['open']) and
($third_day['high'] > $second_day['high'] and $third_day['low'] > $second_day['low'] and $third_day['high'] < $first_day['open']) and
(self::upCandle($forth_day) and self::higherHighsHigherLows($third_day, $forth_day) and $forth_day['high'] < $first_day['open']) and
(self::downCandle($last_day) and $last_day['close'] > $first_day['close'])
) {
return true;
}
return false;
}
/**
* A Bearish Reversal Pattern
*/
public static function bearishHangingMan($history) {
$first_day = $history['history'][count($history['history'])-1];
$prev_one = $history['history'][count($history['history'])-2];
$prev_two = $history['history'][count($history['history'])-3];
$prev_three = $history['history'][count($history['history'])-4];
/*
Small real body at the upper trading range.
Color of the body is not important.
Long lower shadow at least twice the length of the body.
Little or no upper shadow.
Previous trend should be bullish.
*/
if (
(self::higherHighsHigherLows($prev_three, $prev_two) or self::higherLows($prev_three, $prev_one) or self::higherLows($prev_three, $first_day)) and
(self::higherHighsHigherLows($prev_two, $prev_one) or self::higherLows($prev_two, $first_day)) and
self::higherHighsHigherLows($prev_one, $first_day) and
self::hangingMan($first_day)
) {
return true;
}
return false;
}
/**
* A Bearish Reversal Pattern
*/
public static function bearishHarami($history) {
$second_day = $history['history'][count($history['history'])-1];
$first_day = $history['history'][count($history['history'])-2];
$prev_one = $history['history'][count($history['history'])-3];
$prev_two = $history['history'][count($history['history'])-4];
/*
The 1st day is a long up day.
The 2nd day is a short day whose body is engulfed by the 1st day's body.
*/
if (
(self::higherHighsHigherLows($prev_two, $prev_one) or self::higherLows($prev_two, $first_day)) and
self::higherHighsHigherLows($prev_one, $first_day) and
self::upCandle($first_day) and
self::harami($first_day, $second_day) and
self::downCandle($second_day)
) {
return true;
}
return false;
}
/**
* A Bearish Reversal Pattern
*/
public static function bearishHaramiCross($history) {
$second_day = $history['history'][count($history['history'])-1];
$first_day = $history['history'][count($history['history'])-2];
$prev_one = $history['history'][count($history['history'])-3];
$prev_two = $history['history'][count($history['history'])-4];
/*
The 1st day is a long up candle.
The 2nd day is a doji whose body is engulfed by the 1st day's body.
*/
if (
(self::higherHighsHigherLows($prev_two, $prev_one) or self::higherLows($prev_two, $first_day)) and
self::higherHighsHigherLows($prev_one, $first_day) and
self::upCandle($first_day) and
self::harami($first_day, $second_day) and
self::doji($second_day)
) {
return true;
}
return false;
}
/**
* A Bearish Reversal Pattern
*/
public static function bearishIdenticalThreeCrows($history) {
$third_day = $history['history'][count($history['history'])-1];
$second_day = $history['history'][count($history['history'])-2];
$first_day = $history['history'][count($history['history'])-3];
$prev_one = $history['history'][count($history['history'])-4];
$prev_two = $history['history'][count($history['history'])-5];
/*
Three consecutive long down candles with lower closes each day.
Each day opens at the previous day's close.
*/
if (
(self::higherHighsHigherLows($prev_two, $prev_one) or self::higherLows($prev_two, $first_day)) and
self::higherHighsHigherLows($prev_one, $first_day) and
self::downCandle($first_day) and
self::downCandle($second_day) and $first_day['close'] === $second_day['open'] and
self::downCandle($third_day) and $second_day['close'] === $third_day['open']
) {
return true;
}
return false;
}
/**
* A Bearish Continuation Pattern
*/
public static function bearishInNeck($history) {
$second_day = $history['history'][count($history['history'])-1];
$first_day = $history['history'][count($history['history'])-2];
$prev_one = $history['history'][count($history['history'])-3];
$prev_two = $history['history'][count($history['history'])-4];
$first_day_lower_third = min($first_day['open'], $first_day['close'])+(abs($first_day['open']-$first_day['close'])/3);
/*
1st day is a long down candle.
2nd day is a up candle which opens below the low of the 1st day.
2nd day closes barely into the body of the 1st day.
*/
if (
(self::lowerHighsLowerLows($prev_two, $prev_one) or self::higherLows($prev_two, $first_day)) and
self::lowerHighsLowerLows($prev_one, $first_day) and
self::longBody($first_day) and
self::downCandle($first_day) and
self::upCandle($second_day) and
self::longBody($second_day) and
($first_day['close'] > $second_day['open']) and
($first_day['close'] < $second_day['close']) and
($first_day_lower_third > $second_day['close'])
) {
return true;
}
return false;
}
/**
* A Bearish Reversal Pattern
*/
public static function bearishKicking($history) {