forked from himanjim/TradingScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPatternRecognition.py
More file actions
2144 lines (1739 loc) · 108 KB
/
PatternRecognition.py
File metadata and controls
2144 lines (1739 loc) · 108 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
import enum
import Utils as util
class Trend (enum.Enum):
uptrend = 1
downtrend = -1
notrend = 0
weak_up_trend = .5
weak_down_trend = -.5
class Action (enum.Enum):
LONG = 1
SHORT = -1
class Pattern_Name (enum.Enum):
BULLISH_MARUBOZO = 1
BEARISH_MARUBOZO = 2
HAMMER = 3
HANGING_MAN = 4
SHOOTING_STAR = 5
BULLISH_ENGULFING = 6
BEARISH_ENGULFING = 7
BULLISH_HARAMI = 8
BEARISH_HARAMI = 9
MORNING_STAR = 10
EVENING_STAR = 11
DOJI = 12
GAP_UP_DOWN = 13
INVERTED_HAMMER = 14
BULLISH_PIERCING_PATTERN = 15
BEARISH_PIERCING_PATTERN = 16
UPTREND = 17
DOWNTREND = 18
class PatternRecognitionResponse:
def __init__(self):
self.risk_reward_ratio = 0.0
self.errors = []
self.points = 0
self.pattern_match = True
self.previous_trend = None
self.strong_correct_trend = True
self.weak_correct_trend = True
self.pattern_trend_same_as_market_trend = True
self.high_volumes = True
self.current_day_volumes = None
self.last_10_day_average_volumes = None
self.current_day_current_price = None
self.correct_rsi = True
self.correct_rsi_14_9_period_SMA = True
self.correct_candle_length = True
self.correct_support = None
self.correct_resistance = None
self.correct_risk_reward_ratio = True
self.stock_id = None
self.fetch_date = None
self.pattern_name = None
self.action = None
self.fetched_dataset = []
self.supports_resistances=[]
self.support=None
self.resistance=None
self.volatility_stop_loss = None
self.rsi=None
self.rsi_14_9_period_SMA=None
def __str__(self):
res_str = ("\nPattern response start------------\n")
res_str += "Stock id:" + str (self.stock_id) + '\n'
res_str += "Pattern name:" + str (self.pattern_name) + '\n'
if (len (self.errors) > 0):
res_str += "Errors@@@@@@@@@@@@@@@@@@@@@@@@@@@:\n"
for error in self.errors:
res_str += str (error) + "\n"
res_str += "Errors@@@@@@@@@@@@@@@@@@@@@@@@@@@:\n"
res_str += "Fetch date:" + str (self.fetch_date) + '\n'
res_str += "Points:" + str (self.points) + '\n'
res_str += "Pattern match:" + str (self.pattern_match) + '\n'
res_str += "Previous trend:" + str (self.previous_trend) + '\n'
res_str += "Strong correct trend:" + str (self.strong_correct_trend) + '\n'
res_str += "Weak correct trend:" + str (self.weak_correct_trend) + '\n'
res_str += "Pattern trend same as market trend:" + str (self.pattern_trend_same_as_market_trend) + '\n'
res_str += "High volumes:" + str (self.high_volumes) + '\n'
res_str += "Current day volumes:" + str (self.current_day_volumes) + '\n'
res_str += "Last 10 day average volumes:" + str (self.last_10_day_average_volumes) + '\n'
res_str += "Current day current price:" + str (self.current_day_current_price) + '\n'
res_str += "Correct rsi:" + str (self.correct_rsi) + '\n'
res_str += "Correct rsi_14_9_period_SMA:" + str (self.correct_rsi_14_9_period_SMA) + '\n'
res_str += "Correct candle length:" + str (self.correct_candle_length) + '\n'
res_str += "Correct support:" + str (self.correct_support) + '\n'
res_str += "Correct resistance:" + str (self.correct_resistance) + '\n'
res_str += "Volatility stoploss:" + str (self.volatility_stop_loss) + '\n'
res_str += "Correct risk reward ratio:" + str (self.correct_risk_reward_ratio) + '\n'
res_str += "Action:" + str (self.action) + '\n'
res_str += "Support:" + str (self.support) + '\n'
res_str += "Resistance:" + str (self.resistance) + '\n'
res_str += "Rsi:" + str (self.rsi) + '\n'
res_str += "Rsi_14_9_period_SMA:" + str (self.rsi_14_9_period_SMA) + '\n'
res_str += "Supports & resistances:\n"+str (self.supports_resistances)+ '\n'
res_str += "Stock historic data(last 3 days)==============:\n"
res_str += "Current day :"+str(self.fetched_dataset[-1])+ '\n'
res_str += "Previous day :" + str (self.fetched_dataset[-2]) + '\n'
res_str += "Previous to previous day :" + str (self.fetched_dataset[-3]) + '\n'
res_str += "Last day :" + str(self.fetched_dataset[0]) + '\n'
res_str += "Stock historic data(last 3 days)==============:\n"
# for data in self.fetched_dataset:
# res_str += str(data) + "\n"
res_str += ("Pattern response end------------\n")
return res_str
def is_pattern_tradable(self):
return self.pattern_match and (self.previous_trend is None or (
self.strong_correct_trend or self.weak_correct_trend)) and self.high_volumes and (
self.correct_resistance or self.correct_support)
def is_perfect(self):
return self.pattern_match and (self.previous_trend is None or (
self.strong_correct_trend or self.weak_correct_trend)) and self.high_volumes and self.correct_rsi and self.correct_rsi_14_9_period_SMA and (
self.correct_resistance or self.correct_support) and (
self.previous_trend is None or self.pattern_trend_same_as_market_trend) and self.correct_risk_reward_ratio and self.correct_candle_length
acceptable_risk_reward_ratio = 1
no_of_days_for_volatility_stop_loss = 5
no_of_sessions_to_scan_for_volatility = 252
high_low_variation_percent = .5
high_low_marubuzo_variation_percent = .2
high_low_shooting_star_lower_body_variation_percent = .2
support_resistance_variation_percent = 2
no_of_sessions_for_previous_trend = 5
up_down_trend_diff_percent = 5
min_average_volume_to_consider_for_patterns = 300000
min_volume_to_consider_for_patterns_ignore_prev_vol = 500000
max_loss_to_bear_in_rs = 20000
no_of_trend_errors_to_ignore = 1
upper_limit_for_rsi = 80
lower_limit_for_rsi = 20
upper_limit_for_rsi_14_9_period_SMA = 60
lower_limit_for_rsi_14_9_period_SMA = 40
def is_pattern_trend_same_as_market_trend(action, market_previous_trend):
return (action.value > 0 and market_previous_trend.value > 0) or (
action.value < 0 and market_previous_trend.value < 0)
def calculate_risk_reward_ratio_appropriate(current_price, target, stoploss):
if current_price == stoploss:
current_price += 1
return (abs (target - current_price) / abs (current_price - stoploss))
def check_previous_trend(stock_data):
last_price_in_trend = stock_data[-1]['close']
no_of_trend_errors=0
is_there_uptrend = True
for x in range (len (stock_data) - 1):
if (last_price_in_trend < stock_data[x]['close']):
no_of_trend_errors+=1
if(no_of_trend_errors>no_of_trend_errors_to_ignore):
is_there_uptrend = False
break
if is_there_uptrend == False:
no_of_trend_errors = 0
is_there_downtrend = True
for x in range (len (stock_data) - 1):
if (last_price_in_trend > stock_data[x]['close']):
no_of_trend_errors += 1
if (no_of_trend_errors > no_of_trend_errors_to_ignore):
is_there_downtrend = False
break
if is_there_downtrend == False:
return Trend.notrend
elif (util.nearly_equal (stock_data[0]['close'], last_price_in_trend, up_down_trend_diff_percent)):
return Trend.weak_down_trend
else:
return Trend.downtrend
elif (util.nearly_equal (stock_data[0]['close'], last_price_in_trend, up_down_trend_diff_percent)):
return Trend.weak_up_trend
else:
return Trend.uptrend
def append_low_volume_error(res, last_1x_day_average_volume, stock_day_data):
res.errors.append ("Very low volume than for last 1x day average volume:" + str (
last_1x_day_average_volume) + " and/or min volume:" + str (min_average_volume_to_consider_for_patterns)+ " than for current day:" + str (stock_day_data['volume']))
def append_too_long_or_short_candle_error(res, stock_day_data):
res.errors.append ("Very short or long candle with open:" + str (stock_day_data['open']) + " close:" + str (
stock_day_data['close']))
def append_low_risk_reward_ratio_error(res, risk_reward_ratio, acceptable_risk_reward_ratio, current_price, target,
stoploss):
res.errors.append (
"Calculated risk reward ratio:" + str (risk_reward_ratio) + " lower than acceptable ratio:" + str (
acceptable_risk_reward_ratio) + " at current price:" + str (current_price) + " and target:" + str (
target) + " and stoploss:" + str (stoploss))
def append_unacceptable_rsi_error(res, rsi, acceptable_rsi):
res.errors.append ("Provided RSI value:" + str (rsi) + " not within acceptable range of:" + str (acceptable_rsi))
def append_unacceptable_rsi_14_9_period_SMA_error(res, rsi_14_9_period_SMA, acceptable_rsi_14_9_period_SMA):
res.errors.append ("Provided RSI_14_9_period_SMA value:" + str (rsi_14_9_period_SMA) + " not within acceptable range of:" + str (acceptable_rsi_14_9_period_SMA))
def append_unacceptable_target_stoploss_variation_error(res, target_or_stop_loss):
res.errors.append ("Target or stop loss:" + str (target_or_stop_loss) + " not within acceptable range")
def find_nearest_resistance_support(supports_resistances,price_to_scan,current_day_timestamp,is_support=True):
if len(supports_resistances) == 0:
return 0
if is_support:
nearest_support_resistance = supports_resistances[-1]
else:
nearest_support_resistance = supports_resistances[0]
for support_resistance in supports_resistances:
if(is_support==True and support_resistance['close']<price_to_scan and abs(current_day_timestamp-support_resistance['timestamp'])<=abs(current_day_timestamp-nearest_support_resistance['timestamp'])):
nearest_support_resistance=support_resistance
elif (is_support==False and support_resistance['close']>price_to_scan and abs(support_resistance['timestamp']-current_day_timestamp)<=abs(nearest_support_resistance['timestamp']-current_day_timestamp)):
nearest_support_resistance = support_resistance
return nearest_support_resistance['close']
def is_resistance_support_appropriate(supports_resistances,price_to_scan):
for support_resistance in supports_resistances:
if(util.nearly_equal(support_resistance['close'],price_to_scan,support_resistance_variation_percent)):
return True
return False
def is_volume_appropriate(stock_data, last_x_day_average_volume):
return (stock_data['volume'] >= min_average_volume_to_consider_for_patterns and stock_data[
'volume'] > last_x_day_average_volume) or stock_data[
'volume'] >= min_volume_to_consider_for_patterns_ignore_prev_vol
def is_rsi_appropriate(rsi):
return lower_limit_for_rsi < rsi < upper_limit_for_rsi
def Recognize_Bullish_Marubozo(stock_data, supports_resistances, rsi, rsi_14_9_period_SMA, market_trend):
last_10_day_average_volume = util.calculate_last_10_days_average_volume (stock_data[-11:-1])
current_day_data = stock_data[-1]
current_day_current_price = util.get_current_day_current_price (stock_data[-1])
resistance=find_nearest_resistance_support(supports_resistances,current_day_current_price,current_day_data['timestamp'],False)
risk_reward_ratio = calculate_risk_reward_ratio_appropriate (current_day_current_price, resistance, current_day_data['low'])
res = PatternRecognitionResponse ()
res.risk_reward_ratio = risk_reward_ratio
res.points = risk_reward_ratio + 1
res.pattern_name = Pattern_Name.BULLISH_MARUBOZO
res.action = Action.LONG
res.previous_trend = None
res.strong_correct_trend = None
res.weak_correct_trend = None
res.resistance=resistance
res.support=current_day_data['low']
res.rsi=rsi
res.rsi_14_9_period_SMA = rsi_14_9_period_SMA
res.fetch_date = util.get_date_from_timestamp(stock_data[-1]['timestamp'])
res.supports_resistances = supports_resistances
res.current_day_volumes = stock_data[-1]['volume']
res.last_10_day_average_volumes = last_10_day_average_volume
res.current_day_current_price = current_day_current_price
if is_volume_appropriate(current_day_data, last_10_day_average_volume) == False:
append_low_volume_error (res, last_10_day_average_volume, current_day_data)
res.high_volumes = False
if is_pattern_trend_same_as_market_trend (res.action, market_trend) == False:
res.pattern_trend_same_as_market_trend = False
res.errors.append ("Stock action:" + str (res.action) + " not same as market trend:" + str (market_trend.name))
if (util.not_too_long_or_short_candle (current_day_data, stock_data[-11:-1])) == False:
append_too_long_or_short_candle_error (res, current_day_data)
res.correct_candle_length = False
# if util.nearly_equal (current_day_current_price, current_day_data['high'],
# high_low_marubuzo_variation_percent) == False:
# res.errors.append ("Current day current price:" + str (
# current_day_current_price) + " not nearly equal to current day high:" + str (current_day_data['high']))
# res.pattern_match = False
if (current_day_data['open'] == current_day_data['low']) == False:
res.errors.append (
"Current day open:" + str (current_day_data['open']) + " not nearly equal to current day low:" + str (
current_day_data['low']))
res.pattern_match = False
if (current_day_current_price > current_day_data['open']) == False:
res.errors.append ("Current day current price:" + str (
current_day_current_price) + " not greater than current day open:" + str (
current_day_data['open']))
res.pattern_match = False
if is_rsi_appropriate (rsi) == False:
append_unacceptable_rsi_error (res, rsi, lower_limit_for_rsi)
res.correct_rsi = False
if (rsi_14_9_period_SMA > lower_limit_for_rsi_14_9_period_SMA) == False:
append_unacceptable_rsi_14_9_period_SMA_error (res, rsi_14_9_period_SMA, lower_limit_for_rsi_14_9_period_SMA)
res.correct_rsi_14_9_period_SMA = False
if is_resistance_support_appropriate(supports_resistances,current_day_data['low']) == False:
append_unacceptable_target_stoploss_variation_error (res, current_day_data['low'])
res.correct_support = False
else:
res.correct_support = True
if (risk_reward_ratio >= acceptable_risk_reward_ratio) == False:
append_low_risk_reward_ratio_error (res, risk_reward_ratio, acceptable_risk_reward_ratio,
current_day_current_price, resistance, current_day_data['low'])
res.correct_risk_reward_ratio = False
return res
def Recognize_Gap_Up_Down(stock_data, supports_resistances, rsi, rsi_14_9_period_SMA, market_trend):
last_10_day_average_volume = util.calculate_last_10_days_average_volume (stock_data[-11:-1])
current_day_data = stock_data[-1]
previous_day_data = stock_data[-2]
current_day_current_price = util.get_current_day_current_price (stock_data[-1])
resistance = find_nearest_resistance_support (supports_resistances, current_day_current_price,
current_day_data['timestamp'], False)
risk_reward_ratio = calculate_risk_reward_ratio_appropriate (current_day_current_price, resistance,
current_day_data['low'])
res = PatternRecognitionResponse ()
res.risk_reward_ratio = risk_reward_ratio
res.points = risk_reward_ratio + 1
res.pattern_name = Pattern_Name.GAP_UP_DOWN
res.action = Action.LONG
res.previous_trend = None
res.strong_correct_trend = None
res.weak_correct_trend = None
res.resistance = resistance
res.support = current_day_data['low']
res.rsi = rsi
res.rsi_14_9_period_SMA = rsi_14_9_period_SMA
res.fetch_date = util.get_date_from_timestamp (stock_data[-1]['timestamp'])
res.supports_resistances = supports_resistances
res.current_day_volumes = stock_data[-1]['volume']
res.last_10_day_average_volumes = last_10_day_average_volume
res.current_day_current_price = current_day_current_price
if is_volume_appropriate (current_day_data, last_10_day_average_volume) == False:
append_low_volume_error (res, last_10_day_average_volume, current_day_data)
res.high_volumes = False
if is_pattern_trend_same_as_market_trend (res.action, market_trend) == False:
res.pattern_trend_same_as_market_trend = False
res.errors.append ("Stock action:" + str (res.action) + " not same as market trend:" + str (market_trend.name))
if (util.not_too_long_or_short_candle (current_day_data, stock_data[-11:-1])) == False:
append_too_long_or_short_candle_error (res, current_day_data)
res.correct_candle_length = False
if ((current_day_data['low'] > previous_day_data['high'] and current_day_data['high'] > previous_day_data[
'high'] and current_day_data['low'] > previous_day_data['low'] and current_day_data['high'] > previous_day_data[
'low']) or (
current_day_data['low'] < previous_day_data['high'] and current_day_data['high'] < previous_day_data[
'high'] and current_day_data['low'] < previous_day_data['low'] and current_day_data['high'] <
previous_day_data['low'])) == False:
res.pattern_match = False
if is_rsi_appropriate (rsi) == False:
append_unacceptable_rsi_error (res, rsi, lower_limit_for_rsi)
res.correct_rsi = False
if (rsi_14_9_period_SMA > lower_limit_for_rsi_14_9_period_SMA) == False:
append_unacceptable_rsi_14_9_period_SMA_error (res, rsi_14_9_period_SMA, lower_limit_for_rsi_14_9_period_SMA)
res.correct_rsi_14_9_period_SMA = False
if is_resistance_support_appropriate (supports_resistances, current_day_data['low']) == False:
append_unacceptable_target_stoploss_variation_error (res, current_day_data['low'])
res.correct_support = False
else:
res.correct_support = True
if (risk_reward_ratio >= acceptable_risk_reward_ratio) == False:
append_low_risk_reward_ratio_error (res, risk_reward_ratio, acceptable_risk_reward_ratio,
current_day_current_price, resistance, current_day_data['low'])
res.correct_risk_reward_ratio = False
return res
def Recognize_Doji(stock_data, supports_resistances, rsi, rsi_14_9_period_SMA, market_trend):
last_10_day_average_volume = util.calculate_last_10_days_average_volume (stock_data[-11:-1])
current_day_data = stock_data[-1]
current_day_current_price = util.get_current_day_current_price (stock_data[-1])
resistance = find_nearest_resistance_support (supports_resistances, current_day_current_price,
current_day_data['timestamp'], False)
risk_reward_ratio = calculate_risk_reward_ratio_appropriate (current_day_current_price, resistance,
current_day_data['low'])
res = PatternRecognitionResponse ()
res.risk_reward_ratio = risk_reward_ratio
res.points = risk_reward_ratio + 1
res.pattern_name = Pattern_Name.DOJI
res.action = Action.LONG
res.previous_trend = None
res.strong_correct_trend = None
res.weak_correct_trend = None
res.resistance = resistance
res.support = current_day_data['low']
res.rsi = rsi
res.rsi_14_9_period_SMA = rsi_14_9_period_SMA
res.fetch_date = util.get_date_from_timestamp (stock_data[-1]['timestamp'])
res.supports_resistances = supports_resistances
res.current_day_volumes = stock_data[-1]['volume']
res.last_10_day_average_volumes = last_10_day_average_volume
res.current_day_current_price = current_day_current_price
if is_volume_appropriate (current_day_data, last_10_day_average_volume) == False:
append_low_volume_error (res, last_10_day_average_volume, current_day_data)
res.high_volumes = False
if is_pattern_trend_same_as_market_trend (res.action, market_trend) == False:
res.pattern_trend_same_as_market_trend = False
res.errors.append ("Stock action:" + str (res.action) + " not same as market trend:" + str (market_trend.name))
if (util.not_too_long_or_short_candle (current_day_data, stock_data[-11:-1])) == False:
append_too_long_or_short_candle_error (res, current_day_data)
res.correct_candle_length = False
if util.nearly_equal (current_day_current_price, current_day_data['open'],
high_low_marubuzo_variation_percent) == False:
res.errors.append ("Current day current price:" + str (
current_day_current_price) + " not nearly equal to current day open:" + str (current_day_data['open']))
res.pattern_match = False
if (abs (current_day_data['low'] - current_day_data['high']) > (
5 * abs (current_day_current_price - current_day_data['open']))) == False:
res.errors.append ('Doji not long enough')
res.pattern_match = False
if is_rsi_appropriate (rsi) == False:
append_unacceptable_rsi_error (res, rsi, lower_limit_for_rsi)
res.correct_rsi = False
if (rsi_14_9_period_SMA > lower_limit_for_rsi_14_9_period_SMA) == False:
append_unacceptable_rsi_14_9_period_SMA_error (res, rsi_14_9_period_SMA, lower_limit_for_rsi_14_9_period_SMA)
res.correct_rsi_14_9_period_SMA = False
if is_resistance_support_appropriate (supports_resistances, current_day_data['low']) == False:
append_unacceptable_target_stoploss_variation_error (res, current_day_data['low'])
res.correct_support = False
else:
res.correct_support = True
if (risk_reward_ratio >= acceptable_risk_reward_ratio) == False:
append_low_risk_reward_ratio_error (res, risk_reward_ratio, acceptable_risk_reward_ratio,
current_day_current_price, resistance, current_day_data['low'])
res.correct_risk_reward_ratio = False
return res
def Recognize_Bearish_Marubozo(stock_data, supports_resistances, rsi, rsi_14_9_period_SMA, market_trend):
last_10_day_average_volume = util.calculate_last_10_days_average_volume (stock_data[-11:-1])
current_day_data = stock_data[-1]
current_day_current_price = util.get_current_day_current_price (stock_data[-1])
support = find_nearest_resistance_support(supports_resistances,current_day_current_price,current_day_data['timestamp'])
risk_reward_ratio = calculate_risk_reward_ratio_appropriate (current_day_current_price, support, current_day_data['high'])
res = PatternRecognitionResponse ()
res.risk_reward_ratio = risk_reward_ratio
res.points = risk_reward_ratio + 1
res.pattern_name = Pattern_Name.BEARISH_MARUBOZO
res.action = Action.SHORT
res.previous_trend = None
res.strong_correct_trend = None
res.weak_correct_trend = None
res.resistance = current_day_data['high']
res.support = support
res.rsi = rsi
res.rsi_14_9_period_SMA = rsi_14_9_period_SMA
res.fetch_date = util.get_date_from_timestamp(stock_data[-1]['timestamp'])
res.supports_resistances = supports_resistances
res.current_day_volumes = stock_data[-1]['volume']
res.last_10_day_average_volumes = last_10_day_average_volume
res.current_day_current_price = current_day_current_price
if is_volume_appropriate(current_day_data, last_10_day_average_volume) == False:
append_low_volume_error (res, last_10_day_average_volume, current_day_data)
res.high_volumes = False
if is_pattern_trend_same_as_market_trend (res.action, market_trend) == False:
res.pattern_trend_same_as_market_trend = False
res.errors.append ("Stock action:" + str (res.action) + " not same as market trend:" + str (market_trend.name))
if (util.not_too_long_or_short_candle (current_day_data, stock_data[-11:-1])) == False:
append_too_long_or_short_candle_error (res, current_day_data)
res.correct_candle_length = False
# if util.nearly_equal (current_day_current_price, current_day_data['low'],
# high_low_marubuzo_variation_percent) == False:
# res.errors.append ("Current day current price:" + str (
# current_day_current_price) + " not nearly equal to current day low:" + str (
# current_day_data['low']))
# res.pattern_match = False
if (current_day_data['open'] == current_day_data['high']) == False:
res.errors.append (
"Current day open:" + str (current_day_data['open']) + " not nearly equal to current day high:" + str (
current_day_data['high']))
res.pattern_match = False
if (current_day_current_price < current_day_data['open']) == False:
res.errors.append (
"Current day current price:" + str (current_day_current_price) + " not less than current day open:" + str (
current_day_data['open']))
res.pattern_match = False
if is_rsi_appropriate (rsi) == False:
append_unacceptable_rsi_error (res, rsi, upper_limit_for_rsi)
res.correct_rsi = False
if (rsi_14_9_period_SMA < upper_limit_for_rsi_14_9_period_SMA) == False:
append_unacceptable_rsi_14_9_period_SMA_error (res, rsi_14_9_period_SMA, upper_limit_for_rsi_14_9_period_SMA)
res.correct_rsi_14_9_period_SMA = False
if is_resistance_support_appropriate(supports_resistances, current_day_data['high']) == False:
append_unacceptable_target_stoploss_variation_error(res, current_day_data['high'])
res.correct_resistance = False
else:
res.correct_resistance = True
if (risk_reward_ratio >= acceptable_risk_reward_ratio) == False:
append_low_risk_reward_ratio_error (res, risk_reward_ratio, acceptable_risk_reward_ratio,
current_day_current_price, support, current_day_data['high'])
res.correct_risk_reward_ratio = False
return res
def Recognize_Hammer(stock_data, supports_resistances, rsi, rsi_14_9_period_SMA, market_trend):
last_10_day_average_volume = util.calculate_last_10_days_average_volume (stock_data[-11:-1])
last_11_day_average_volume = util.calculate_last_10_days_average_volume (stock_data[-12:-2])
current_day_data = stock_data[-1]
previous_day_data = stock_data[-2]
current_day_current_price = util.get_current_day_current_price (stock_data[-1])
resistance = find_nearest_resistance_support(supports_resistances,current_day_current_price,current_day_data['timestamp'], False)
risk_reward_ratio = calculate_risk_reward_ratio_appropriate (current_day_current_price, resistance, current_day_data['low'])
res = PatternRecognitionResponse ()
res.risk_reward_ratio = risk_reward_ratio
res.points = risk_reward_ratio + 2
res.pattern_name = Pattern_Name.HAMMER
res.action = Action.LONG
res.resistance = resistance
res.support = current_day_data['low']
res.rsi = rsi
res.rsi_14_9_period_SMA = rsi_14_9_period_SMA
res.fetch_date = util.get_date_from_timestamp(stock_data[-1]['timestamp'])
res.supports_resistances = supports_resistances
res.current_day_volumes = stock_data[-1]['volume']
res.last_10_day_average_volumes = last_10_day_average_volume
res.current_day_current_price = current_day_current_price
if is_volume_appropriate(current_day_data, last_10_day_average_volume) == False:
append_low_volume_error (res, last_10_day_average_volume, current_day_data)
res.high_volumes = False
# if is_volume_appropriate(previous_day_data, last_11_day_average_volume) == True:
# append_low_volume_error (res, last_11_day_average_volume, previous_day_data)
# res.high_volumes = False
previous_trend = check_previous_trend (stock_data[-no_of_sessions_for_previous_trend - 2: -2])
res.previous_trend = previous_trend
if (previous_trend.value == Trend.downtrend.value) == False:
res.errors.append (
"No clear downtrend." + str (stock_data[-no_of_sessions_for_previous_trend - 3]['close']) + " : " + str (
stock_data[-3]['close']))
res.strong_correct_trend = False
else:
res.weak_correct_trend = False
if (previous_trend.value == Trend.weak_down_trend.value or previous_trend.value == Trend.downtrend.value) == False:
res.weak_correct_trend = False
elif (previous_trend.value == Trend.weak_down_trend.value) == True:
res.errors.append ("Weak downtrend.")
if is_pattern_trend_same_as_market_trend (res.action, market_trend) == False:
res.pattern_trend_same_as_market_trend = False
res.errors.append ("Stock action:" + str (res.action) + " not same as market trend:" + str (market_trend.name))
if (util.not_too_long_or_short_candle (current_day_data, stock_data[-11:-1])) == False:
append_too_long_or_short_candle_error (res, current_day_data)
res.correct_candle_length = False
if (util.not_too_long_or_short_candle (previous_day_data, stock_data[-12:-2])) == False:
append_too_long_or_short_candle_error (res, previous_day_data)
res.correct_candle_length = False
# if (current_day_current_price >= current_day_data['open']) == False:
# res.errors.append ("Current day current price:" + str (
# current_day_current_price) + " not greater than current day open:" + str (
# current_day_data['open']))
# res.pattern_match = False
if (previous_day_data['close'] < previous_day_data['open']) == False:
res.errors.append (
"Previous day close:" + str (previous_day_data['close']) + " not less than current day open:" + str (
current_day_data['open']))
res.pattern_match = False
if ((util.nearly_equal (current_day_current_price, current_day_data['high'], high_low_variation_percent) and (
abs (current_day_data['open'] - current_day_data['low']) > (
2 * abs (current_day_current_price - current_day_data['open'])))) or (
util.nearly_equal (current_day_data['open'], current_day_data['high'], high_low_variation_percent) and (
abs (current_day_current_price - current_day_data['low']) > (
2 * abs (current_day_data['open'] - current_day_current_price))))) == False:
res.errors.append ("Current day current price:" + str (
current_day_current_price) + " not nearly equal to current day high:" + str (
current_day_data['high']))
res.pattern_match = False
# if ( or ) == False:
# res.errors.append ("Current day (open-low):" + str ((current_day_data['open'] - current_day_data[
# 'low'])) + " not twice current day (current price-open):" + str (
# (current_day_current_price - current_day_data['open'])))
# res.pattern_match = False
if is_rsi_appropriate (rsi) == False:
append_unacceptable_rsi_error (res, rsi, lower_limit_for_rsi)
res.correct_rsi = False
if (rsi_14_9_period_SMA > lower_limit_for_rsi_14_9_period_SMA) == False:
append_unacceptable_rsi_14_9_period_SMA_error (res, rsi_14_9_period_SMA, lower_limit_for_rsi_14_9_period_SMA)
res.correct_rsi_14_9_period_SMA = False
if is_resistance_support_appropriate(supports_resistances, current_day_data['low']) == False:
append_unacceptable_target_stoploss_variation_error(res, current_day_data['low'])
res.correct_support = False
else:
res.correct_support = True
if (risk_reward_ratio >= acceptable_risk_reward_ratio) == False:
append_low_risk_reward_ratio_error (res, risk_reward_ratio, acceptable_risk_reward_ratio,
current_day_current_price, resistance, current_day_data['low'])
res.correct_risk_reward_ratio = False
return res
def Recognize_Hanging_Man(stock_data, supports_resistances, rsi, rsi_14_9_period_SMA, market_trend):
last_10_day_average_volume = util.calculate_last_10_days_average_volume (stock_data[-11:-1])
last_11_day_average_volume = util.calculate_last_10_days_average_volume (stock_data[-12:-2])
current_day_data = stock_data[-1]
previous_day_data = stock_data[-2]
current_day_current_price = util.get_current_day_current_price (stock_data[-1])
support = find_nearest_resistance_support(supports_resistances,current_day_current_price,current_day_data['timestamp'])
risk_reward_ratio = calculate_risk_reward_ratio_appropriate (current_day_current_price, support, current_day_data['high'])
res = PatternRecognitionResponse ()
res.risk_reward_ratio = risk_reward_ratio
res.points = risk_reward_ratio + 2
res.pattern_name = Pattern_Name.HANGING_MAN
res.action = Action.SHORT
res.resistance = current_day_data['high']
res.support = support
res.rsi = rsi
res.rsi_14_9_period_SMA = rsi_14_9_period_SMA
res.fetch_date = util.get_date_from_timestamp(stock_data[-1]['timestamp'])
res.supports_resistances = supports_resistances
res.current_day_volumes = stock_data[-1]['volume']
res.last_10_day_average_volumes = last_10_day_average_volume
res.current_day_current_price = current_day_current_price
if is_volume_appropriate(current_day_data, last_10_day_average_volume) == False:
append_low_volume_error (res, last_10_day_average_volume, current_day_data)
res.high_volumes = False
# if is_volume_appropriate(previous_day_data, last_11_day_average_volume) == False:
# append_low_volume_error (res, last_11_day_average_volume, previous_day_data)
# res.high_volumes = False
previous_trend = check_previous_trend (stock_data[-no_of_sessions_for_previous_trend - 2: -2])
res.previous_trend = previous_trend
if (previous_trend.value == Trend.uptrend.value) == False:
res.errors.append (
"No clear uptrend." + str (stock_data[-no_of_sessions_for_previous_trend - 3]['close']) + " : " + str (
stock_data[-3]['close']))
res.strong_correct_trend = False
else:
res.weak_correct_trend = False
if (previous_trend.value == Trend.weak_up_trend.value or previous_trend.value == Trend.uptrend.value) == False:
res.weak_correct_trend = False
elif (previous_trend.value == Trend.weak_up_trend.value) == True:
res.errors.append ("Weak uptrend.")
if is_pattern_trend_same_as_market_trend (res.action, market_trend) == False:
res.pattern_trend_same_as_market_trend = False
res.errors.append ("Stock action:" + str (res.action) + " not same as market trend:" + str (market_trend.name))
if (util.not_too_long_or_short_candle (current_day_data, stock_data[-11:-1])) == False:
append_too_long_or_short_candle_error (res, current_day_data)
res.correct_candle_length = False
if (util.not_too_long_or_short_candle (previous_day_data, stock_data[-12:-2])) == False:
append_too_long_or_short_candle_error (res, previous_day_data)
res.correct_candle_length = False
# if (current_day_current_price <= current_day_data['open']) == False:
# res.errors.append (
# "Current day current price:" + str (current_day_current_price) + " not less than current day open:" + str (
# current_day_data['open']))
# res.pattern_match = False
if (previous_day_data['close'] > previous_day_data['open']) == False:
res.errors.append (
"Previous day close:" + str (previous_day_data['close']) + " not greater than previous day open:" + str (
previous_day_data['open']))
res.pattern_match = False
if ((util.nearly_equal (current_day_current_price, current_day_data['high'], high_low_variation_percent) and (
abs (current_day_data['open'] - current_day_data['low']) > (
2 * abs (current_day_data['high'] - current_day_data['open'])))) or (
util.nearly_equal (current_day_data['open'], current_day_data['high'], high_low_variation_percent) and (
abs (current_day_current_price - current_day_data['low']) > (
2 * abs (current_day_data['high'] - current_day_current_price))))) == False:
res.errors.append ("Current day current price/open:" + str (
current_day_current_price) + " not nearly equal to current day high:" + str (
current_day_data['high']))
res.pattern_match = False
# if ( or ) == False:
# res.errors.append ("Current day (cp-low):" + str ((current_day_current_price - current_day_data['low'])) +
# " not twice current day (high-cp):" + str (
# (current_day_data['high'] - current_day_current_price)))
# res.pattern_match = False
if is_rsi_appropriate (rsi) == False:
append_unacceptable_rsi_error (res, rsi, upper_limit_for_rsi)
res.correct_rsi = False
if (rsi_14_9_period_SMA < upper_limit_for_rsi_14_9_period_SMA) == False:
append_unacceptable_rsi_14_9_period_SMA_error (res, rsi_14_9_period_SMA, upper_limit_for_rsi_14_9_period_SMA)
res.correct_rsi_14_9_period_SMA = False
if is_resistance_support_appropriate(supports_resistances, current_day_data['high']) == False:
append_unacceptable_target_stoploss_variation_error(res, current_day_data['high'])
res.correct_resistance = False
else:
res.correct_resistance = True
if (risk_reward_ratio >= acceptable_risk_reward_ratio) == False:
append_low_risk_reward_ratio_error (res, risk_reward_ratio, acceptable_risk_reward_ratio,
current_day_current_price, support, current_day_data['high'])
res.correct_risk_reward_ratio = False
return res
def Recognize_Shooting_Star(stock_data, supports_resistances, rsi, rsi_14_9_period_SMA, market_trend):
last_10_day_average_volume = util.calculate_last_10_days_average_volume (stock_data[-11:-1])
last_11_day_average_volume = util.calculate_last_10_days_average_volume (stock_data[-12:-2])
current_day_data = stock_data[-1]
previous_day_data = stock_data[-2]
current_day_current_price = util.get_current_day_current_price (stock_data[-1])
support = find_nearest_resistance_support(supports_resistances,current_day_current_price,current_day_data['timestamp'])
risk_reward_ratio = calculate_risk_reward_ratio_appropriate (current_day_current_price, support, current_day_data['high'])
res = PatternRecognitionResponse ()
res.risk_reward_ratio = risk_reward_ratio
res.points = risk_reward_ratio + 2
res.pattern_name = Pattern_Name.SHOOTING_STAR
res.action = Action.SHORT
res.resistance = current_day_data['high']
res.support = support
res.rsi = rsi
res.rsi_14_9_period_SMA = rsi_14_9_period_SMA
res.fetch_date = util.get_date_from_timestamp(stock_data[-1]['timestamp'])
res.supports_resistances = supports_resistances
res.current_day_volumes = stock_data[-1]['volume']
res.last_10_day_average_volumes = last_10_day_average_volume
res.current_day_current_price = current_day_current_price
if is_volume_appropriate(current_day_data, last_10_day_average_volume) == False:
append_low_volume_error (res, last_10_day_average_volume, current_day_data)
res.high_volumes = False
# if is_volume_appropriate(previous_day_data, last_11_day_average_volume) == False:
# append_low_volume_error (res, last_11_day_average_volume, previous_day_data)
# res.high_volumes = False
previous_trend = check_previous_trend (stock_data[-no_of_sessions_for_previous_trend - 2: -2])
res.previous_trend = previous_trend
if (previous_trend.value == Trend.uptrend.value) == False:
res.errors.append (
"No clear uptrend." + str (stock_data[-no_of_sessions_for_previous_trend - 3]['close']) + " : " + str (
stock_data[-3]['close']))
res.strong_correct_trend = False
else:
res.weak_correct_trend = False
if (previous_trend.value == Trend.weak_up_trend.value or previous_trend.value == Trend.uptrend.value) == False:
res.weak_correct_trend = False
elif (previous_trend.value == Trend.weak_up_trend.value) == True:
res.errors.append ("Weak uptrend.")
if is_pattern_trend_same_as_market_trend (res.action, market_trend) == False:
res.pattern_trend_same_as_market_trend = False
res.errors.append ("Stock action:" + str (res.action) + " not same as market trend:" + str (market_trend.name))
if (util.not_too_long_or_short_candle (current_day_data, stock_data[-11:-1])) == False:
append_too_long_or_short_candle_error (res, current_day_data)
res.correct_candle_length = False
if (util.not_too_long_or_short_candle (previous_day_data, stock_data[-12:-2])) == False:
append_too_long_or_short_candle_error (res, previous_day_data)
res.correct_candle_length = False
if (previous_day_data['close'] > previous_day_data['open']) == False:
res.errors.append (
"Previous day close:" + str (previous_day_data['close']) + " not greater than previous day open:" + str (
previous_day_data['open']))
res.pattern_match = False
# in case of bullish & bearish candle
if ((util.nearly_equal (current_day_data['open'], current_day_data['low'],
high_low_shooting_star_lower_body_variation_percent) and (
abs (current_day_data['high'] - current_day_current_price) > (
2 * abs (current_day_current_price - current_day_data['low'])))) or (
util.nearly_equal (current_day_data['low'], current_day_current_price,
high_low_shooting_star_lower_body_variation_percent) and (
abs (current_day_data['high'] - current_day_data['open']) > (
2 * abs (current_day_data['open'] - current_day_current_price))))) == False:
res.errors.append ("Current day (open or low):(" + str (current_day_data['open']) + " or " + str (
current_day_data['low']) + ") not nearly equal to current day (cp or low):(" + str (
current_day_current_price) + " or " + str (current_day_data['low']) + ")")
res.errors.append ("Current day (high-cp(or open)):(" + str (
current_day_data['high'] - current_day_current_price) + " or " + str (
current_day_data['high'] - current_day_data['open']) +
") not twice current day ((cp-low) or (open-cp)):(" + str
(current_day_current_price - current_day_data['low']) + "or " + str (
current_day_data['open'] - current_day_current_price))
res.pattern_match = False
if is_rsi_appropriate (rsi) == False:
append_unacceptable_rsi_error (res, rsi, upper_limit_for_rsi)
res.correct_rsi = False
if (rsi_14_9_period_SMA < upper_limit_for_rsi_14_9_period_SMA) == False:
append_unacceptable_rsi_14_9_period_SMA_error (res, rsi_14_9_period_SMA, upper_limit_for_rsi_14_9_period_SMA)
res.correct_rsi_14_9_period_SMA = False
if is_resistance_support_appropriate(supports_resistances, current_day_data['high']) == False:
append_unacceptable_target_stoploss_variation_error(res, current_day_data['high'])
res.correct_resistance = False
else:
res.correct_resistance = True
if (risk_reward_ratio >= acceptable_risk_reward_ratio) == False:
append_low_risk_reward_ratio_error (res, risk_reward_ratio, acceptable_risk_reward_ratio,
current_day_current_price, support, current_day_data['high'])
res.correct_risk_reward_ratio = False
return res
def Recognize_Inverted_Hammer(stock_data, supports_resistances, rsi, rsi_14_9_period_SMA, market_trend):
last_10_day_average_volume = util.calculate_last_10_days_average_volume (stock_data[-11:-1])
last_11_day_average_volume = util.calculate_last_10_days_average_volume (stock_data[-12:-2])
current_day_data = stock_data[-1]
previous_day_data = stock_data[-2]
current_day_current_price = util.get_current_day_current_price (stock_data[-1])
support = find_nearest_resistance_support (supports_resistances, current_day_current_price,
current_day_data['timestamp'])
risk_reward_ratio = calculate_risk_reward_ratio_appropriate (current_day_current_price, support,
current_day_data['high'])
res = PatternRecognitionResponse ()
res.risk_reward_ratio = risk_reward_ratio
res.points = risk_reward_ratio + 2
res.pattern_name = Pattern_Name.INVERTED_HAMMER
res.action = Action.SHORT
res.resistance = current_day_data['high']
res.support = support
res.rsi = rsi
res.rsi_14_9_period_SMA = rsi_14_9_period_SMA
res.fetch_date = util.get_date_from_timestamp (stock_data[-1]['timestamp'])
res.supports_resistances = supports_resistances
res.current_day_volumes = stock_data[-1]['volume']
res.last_10_day_average_volumes = last_10_day_average_volume
res.current_day_current_price = current_day_current_price
if is_volume_appropriate (current_day_data, last_10_day_average_volume) == False:
append_low_volume_error (res, last_10_day_average_volume, current_day_data)
res.high_volumes = False
# if is_volume_appropriate(previous_day_data, last_11_day_average_volume) == False:
# append_low_volume_error (res, last_11_day_average_volume, previous_day_data)
# res.high_volumes = False
previous_trend = check_previous_trend (stock_data[-no_of_sessions_for_previous_trend - 2: -2])
res.previous_trend = previous_trend
if (previous_trend.value == Trend.downtrend.value) == False:
res.errors.append (
"No clear downtrend." + str (stock_data[-no_of_sessions_for_previous_trend - 3]['close']) + " : " + str (
stock_data[-3]['close']))
res.strong_correct_trend = False
else:
res.weak_correct_trend = False
if (previous_trend.value == Trend.weak_down_trend.value or previous_trend.value == Trend.downtrend.value) == False:
res.weak_correct_trend = False
elif (previous_trend.value == Trend.downtrend.value) == True:
res.errors.append ("Weak downtrend.")
if is_pattern_trend_same_as_market_trend (res.action, market_trend) == False:
res.pattern_trend_same_as_market_trend = False
res.errors.append ("Stock action:" + str (res.action) + " not same as market trend:" + str (market_trend.name))
if (util.not_too_long_or_short_candle (current_day_data, stock_data[-11:-1])) == False:
append_too_long_or_short_candle_error (res, current_day_data)
res.correct_candle_length = False
if (util.not_too_long_or_short_candle (previous_day_data, stock_data[-12:-2])) == False:
append_too_long_or_short_candle_error (res, previous_day_data)
res.correct_candle_length = False
if (previous_day_data['close'] < previous_day_data['open']) == False:
res.errors.append (
"Previous day close:" + str (previous_day_data['close']) + " not less than previous day open:" + str (
previous_day_data['open']))
res.pattern_match = False
# in case of bullish & bearish candle
if ((util.nearly_equal (current_day_data['open'], current_day_data['low'],
high_low_shooting_star_lower_body_variation_percent) and (
abs (current_day_data['high'] - current_day_current_price) > (
2 * abs (current_day_current_price - current_day_data['low'])))) or (
util.nearly_equal (current_day_data['low'], current_day_current_price,
high_low_shooting_star_lower_body_variation_percent) and (
abs (current_day_data['high'] - current_day_data['open']) > (
2 * abs (current_day_data['open'] - current_day_current_price))))) == False:
res.errors.append ("Current day (open or low):(" + str (current_day_data['open']) + " or " + str (
current_day_data['low']) + ") not nearly equal to current day (cp or low):(" + str (
current_day_current_price) + " or " + str (current_day_data['low']) + ")")
res.errors.append ("Current day (high-cp(or open)):(" + str (
current_day_data['high'] - current_day_current_price) + " or " + str (
current_day_data['high'] - current_day_data['open']) +
") not twice current day ((cp-low) or (open-cp)):(" + str
(current_day_current_price - current_day_data['low']) + "or " + str (
current_day_data['open'] - current_day_current_price))
res.pattern_match = False
if is_rsi_appropriate (rsi) == False:
append_unacceptable_rsi_error (res, rsi, upper_limit_for_rsi)
res.correct_rsi = False
if (rsi_14_9_period_SMA < upper_limit_for_rsi_14_9_period_SMA) == False:
append_unacceptable_rsi_14_9_period_SMA_error (res, rsi_14_9_period_SMA, upper_limit_for_rsi_14_9_period_SMA)
res.correct_rsi_14_9_period_SMA = False
if is_resistance_support_appropriate (supports_resistances, current_day_data['high']) == False:
append_unacceptable_target_stoploss_variation_error (res, current_day_data['high'])
res.correct_resistance = False
else:
res.correct_resistance = True
if (risk_reward_ratio >= acceptable_risk_reward_ratio) == False:
append_low_risk_reward_ratio_error (res, risk_reward_ratio, acceptable_risk_reward_ratio,
current_day_current_price, support, current_day_data['high'])
res.correct_risk_reward_ratio = False