File size: 8,957 Bytes
9bf26a6 |
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 |
'''
* Project : Screenipy
* Author : Pranjal Joshi
* Created : 11/04/2021
* Description : Class for analyzing candle-stick patterns
'''
import pandas as pd
from classes.ScreenipyTA import ScreenerTA
from classes.ColorText import colorText
class CandlePatterns:
reversalPatternsBullish = ['Morning Star', 'Morning Doji Star', '3 Inside Up', 'Hammer', '3 White Soldiers', 'Bullish Engulfing', 'Dragonfly Doji', 'Supply Drought', 'Demand Rise']
reversalPatternsBearish = ['Evening Star', 'Evening Doji Star', '3 Inside Down', 'Inverted Hammer', 'Hanging Man', '3 Black Crows', 'Bearish Engulfing', 'Shooting Star', 'Gravestone Doji']
def __init__(self):
pass
# Find candle-stick patterns
# Arrange if statements with max priority from top to bottom
def findPattern(self, data, dict, saveDict):
data = data.head(4)
data = data[::-1]
check = ScreenerTA.CDLMORNINGSTAR(data['Open'], data['High'], data['Low'], data['Close'])
if(check):
dict['Pattern'] = colorText.BOLD + colorText.GREEN + 'Morning Star' + colorText.END
saveDict['Pattern'] = 'Morning Star'
return True
check = ScreenerTA.CDLMORNINGDOJISTAR(data['Open'], data['High'], data['Low'], data['Close'])
if(check):
dict['Pattern'] = colorText.BOLD + colorText.GREEN + 'Morning Doji Star' + colorText.END
saveDict['Pattern'] = 'Morning Doji Star'
return True
check = ScreenerTA.CDLEVENINGSTAR(data['Open'], data['High'], data['Low'], data['Close'])
if(check):
dict['Pattern'] = colorText.BOLD + colorText.FAIL + 'Evening Star' + colorText.END
saveDict['Pattern'] = 'Evening Star'
return True
check = ScreenerTA.CDLEVENINGDOJISTAR(data['Open'], data['High'], data['Low'], data['Close'])
if(check):
dict['Pattern'] = colorText.BOLD + colorText.FAIL + 'Evening Doji Star' + colorText.END
saveDict['Pattern'] = 'Evening Doji Star'
return True
check = ScreenerTA.CDLLADDERBOTTOM(data['Open'], data['High'], data['Low'], data['Close'])
if(check):
if(check is not None and check.tail(1).item() > 0):
dict['Pattern'] = colorText.BOLD + colorText.GREEN + 'Ladder Bottom' + colorText.END
saveDict['Pattern'] = 'Bullish Ladder Bottom'
else:
dict['Pattern'] = colorText.BOLD + colorText.FAIL + 'Ladder Bottom' + colorText.END
saveDict['Pattern'] = 'Bearish Ladder Bottom'
return True
check = ScreenerTA.CDL3LINESTRIKE(data['Open'], data['High'], data['Low'], data['Close'])
if(check):
if(check is not None and check.tail(1).item() > 0):
dict['Pattern'] = colorText.BOLD + colorText.GREEN + '3 Line Strike' + colorText.END
else:
dict['Pattern'] = colorText.BOLD + colorText.FAIL + '3 Line Strike' + colorText.END
saveDict['Pattern'] = '3 Line Strike'
return True
check = ScreenerTA.CDL3BLACKCROWS(data['Open'], data['High'], data['Low'], data['Close'])
if(check):
dict['Pattern'] = colorText.BOLD + colorText.FAIL + '3 Black Crows' + colorText.END
saveDict['Pattern'] = '3 Black Crows'
return True
check = ScreenerTA.CDL3INSIDE(data['Open'], data['High'], data['Low'], data['Close'])
if(check):
if(check is not None and check.tail(1).item() > 0):
dict['Pattern'] = colorText.BOLD + colorText.GREEN + '3 Outside Up' + colorText.END
saveDict['Pattern'] = '3 Inside Up'
else:
dict['Pattern'] = colorText.BOLD + colorText.FAIL + '3 Outside Down' + colorText.END
saveDict['Pattern'] = '3 Inside Down'
return True
check = ScreenerTA.CDL3OUTSIDE(data['Open'], data['High'], data['Low'], data['Close'])
if(check > 0):
dict['Pattern'] = colorText.BOLD + colorText.GREEN + '3 Outside Up' + colorText.END
saveDict['Pattern'] = '3 Outside Up'
return True
elif(check < 0):
dict['Pattern'] = colorText.BOLD + colorText.FAIL + '3 Outside Down' + colorText.END
saveDict['Pattern'] = '3 Outside Down'
return True
check = ScreenerTA.CDL3WHITESOLDIERS(data['Open'], data['High'], data['Low'], data['Close'])
if(check):
dict['Pattern'] = colorText.BOLD + colorText.GREEN + '3 White Soldiers' + colorText.END
saveDict['Pattern'] = '3 White Soldiers'
return True
check = ScreenerTA.CDLHARAMI(data['Open'], data['High'], data['Low'], data['Close'])
if(check):
if(check is not None and check.tail(1).item() > 0):
dict['Pattern'] = colorText.BOLD + colorText.GREEN + 'Bullish Harami' + colorText.END
saveDict['Pattern'] = 'Bullish Harami'
else:
dict['Pattern'] = colorText.BOLD + colorText.FAIL + 'Bearish Harami' + colorText.END
saveDict['Pattern'] = 'Bearish Harami'
return True
check = ScreenerTA.CDLHARAMICROSS(data['Open'], data['High'], data['Low'], data['Close'])
if(check):
if(check is not None and check.tail(1).item() > 0):
dict['Pattern'] = colorText.BOLD + colorText.GREEN + 'Bullish Harami Cross' + colorText.END
saveDict['Pattern'] = 'Bullish Harami Cross'
else:
dict['Pattern'] = colorText.BOLD + colorText.FAIL + 'Bearish Harami Cross' + colorText.END
saveDict['Pattern'] = 'Bearish Harami Cross'
return True
check = ScreenerTA.CDLMARUBOZU(data['Open'], data['High'], data['Low'], data['Close'])
if(check):
if(check is not None and check.tail(1).item() > 0):
dict['Pattern'] = colorText.BOLD + colorText.GREEN + 'Bullish Marubozu' + colorText.END
saveDict['Pattern'] = 'Bullish Marubozu'
else:
dict['Pattern'] = colorText.BOLD + colorText.FAIL + 'Bearish Marubozu' + colorText.END
saveDict['Pattern'] = 'Bearish Marubozu'
return True
check = ScreenerTA.CDLHANGINGMAN(data['Open'], data['High'], data['Low'], data['Close'])
if(check):
dict['Pattern'] = colorText.BOLD + colorText.FAIL + 'Hanging Man' + colorText.END
saveDict['Pattern'] = 'Hanging Man'
return True
check = ScreenerTA.CDLHAMMER(data['Open'], data['High'], data['Low'], data['Close'])
if(check):
dict['Pattern'] = colorText.BOLD + colorText.GREEN + 'Hammer' + colorText.END
saveDict['Pattern'] = 'Hammer'
return True
check = ScreenerTA.CDLINVERTEDHAMMER(data['Open'], data['High'], data['Low'], data['Close'])
if(check):
dict['Pattern'] = colorText.BOLD + colorText.GREEN + 'Inverted Hammer' + colorText.END
saveDict['Pattern'] = 'Inverted Hammer'
return True
check = ScreenerTA.CDLSHOOTINGSTAR(data['Open'], data['High'], data['Low'], data['Close'])
if(check):
dict['Pattern'] = colorText.BOLD + colorText.FAIL + 'Shooting Star' + colorText.END
saveDict['Pattern'] = 'Shooting Star'
return True
check = ScreenerTA.CDLDRAGONFLYDOJI(data['Open'], data['High'], data['Low'], data['Close'])
if(check):
dict['Pattern'] = colorText.BOLD + colorText.GREEN + 'Dragonfly Doji' + colorText.END
saveDict['Pattern'] = 'Dragonfly Doji'
return True
check = ScreenerTA.CDLGRAVESTONEDOJI(data['Open'], data['High'], data['Low'], data['Close'])
if(check):
dict['Pattern'] = colorText.BOLD + colorText.FAIL + 'Gravestone Doji' + colorText.END
saveDict['Pattern'] = 'Gravestone Doji'
return True
check = ScreenerTA.CDLDOJI(data['Open'], data['High'], data['Low'], data['Close'])
if(check):
dict['Pattern'] = colorText.BOLD + 'Doji' + colorText.END
saveDict['Pattern'] = 'Doji'
return True
check = ScreenerTA.CDLENGULFING(data['Open'], data['High'], data['Low'], data['Close'])
if(check > 0):
dict['Pattern'] = colorText.BOLD + colorText.GREEN + 'Bullish Engulfing' + colorText.END
saveDict['Pattern'] = 'Bullish Engulfing'
return True
elif(check < 0):
dict['Pattern'] = colorText.BOLD + colorText.FAIL + 'Bearish Engulfing' + colorText.END
saveDict['Pattern'] = 'Bearish Engulfing'
return True
dict['Pattern'] = ''
saveDict['Pattern'] = ''
return False
|