diff --git a/src/classes/Screener.py b/src/classes/Screener.py index 9b6841b..38f9a2a 100644 --- a/src/classes/Screener.py +++ b/src/classes/Screener.py @@ -97,36 +97,36 @@ def findBreakout(data, dict, saveDict, daysToLookback): if ((hs - hc) <= (hs*2/100)): saveDict['Breaking-Out'] = str(hc) if rc >= hc: - dict['Breaking-Out'] = colorText.BOLD + colorText.GREEN + "Yes (BO: " + str(hc) + " R: " + str(hs) + ")" + colorText.END + dict['Breaking-Out'] = colorText.BOLD + colorText.GREEN + "BO: " + str(hc) + " R: " + str(hs) + colorText.END return True else: - dict['Breaking-Out'] = colorText.BOLD + colorText.FAIL + "NO (BO: " + str(hc) + " R: " + str(hs) + ")" + colorText.END + dict['Breaking-Out'] = colorText.BOLD + colorText.FAIL + "BO: " + str(hc) + " R: " + str(hs) + colorText.END return False else: noOfHigherShadows = len(data[data.High > hc]) if(daysToLookback/noOfHigherShadows <= 3): saveDict['Breaking-Out'] = str(hs) if rc >= hs: - dict['Breaking-Out'] = colorText.BOLD + colorText.GREEN + "Yes (BO: " + str(hs) + ")" + colorText.END + dict['Breaking-Out'] = colorText.BOLD + colorText.GREEN + "BO: " + str(hs) + colorText.END return True else: - dict['Breaking-Out'] = colorText.BOLD + colorText.FAIL + "NO (BO: " + str(hs) + ")" + colorText.END + dict['Breaking-Out'] = colorText.BOLD + colorText.FAIL + "BO: " + str(hs) + colorText.END return False else: saveDict['Breaking-Out'] = str(hc) + ", " + str(hs) if rc >= hc: - dict['Breaking-Out'] = colorText.BOLD + colorText.GREEN + "Yes (BO: " + str(hc) + " R: " + str(hs) + ")" + colorText.END + dict['Breaking-Out'] = colorText.BOLD + colorText.GREEN + "BO: " + str(hc) + " R: " + str(hs) + colorText.END return True else: - dict['Breaking-Out'] = colorText.BOLD + colorText.FAIL + "NO (BO: " + str(hc) + " R: " + str(hs) + ")" + colorText.END + dict['Breaking-Out'] = colorText.BOLD + colorText.FAIL + "BO: " + str(hc) + " R: " + str(hs) + colorText.END return False else: saveDict['Breaking-Out'] = str(hc) if rc >= hc: - dict['Breaking-Out'] = colorText.BOLD + colorText.GREEN + "Yes (BO: " + str(hc) + ")" + colorText.END + dict['Breaking-Out'] = colorText.BOLD + colorText.GREEN + "BO: " + str(hc) + colorText.END return True else: - dict['Breaking-Out'] = colorText.BOLD + colorText.FAIL + "NO (BO: " + str(hc) + ")" + colorText.END + dict['Breaking-Out'] = colorText.BOLD + colorText.FAIL + "BO: " + str(hc) + colorText.END return False # Validate 'Inside Bar' structure for recent days @@ -169,20 +169,34 @@ def findTrend(data, dict, saveDict, daysToLookback=ConfigManager.daysToLookback) data = data.set_index(np.arange(len(data))) data['tops'] = data['Close'].iloc[list(argrelextrema(np.array(data['Close']), np.greater_equal, order=1)[0])] data = data.fillna(0) - slope,c = np.polyfit(data.index[data.tops > 0], data['tops'][data.tops > 0], 1) - angle = np.rad2deg(np.arctan(slope)) - if(slope <= 2.5 and slope >= -2.5): - dict['Trend'] = colorText.BOLD + colorText.WARN + "Sideways" + colorText.END - saveDict['Trend'] = 'Sideways' - elif slope >= 2.5: - dict['Trend'] = colorText.BOLD + colorText.GREEN + "Uptrend" + colorText.END - saveDict['Trend'] = 'Uptrend' - elif slope <= -2.5: - dict['Trend'] = colorText.BOLD + colorText.FAIL + "Downtrend" + colorText.END - saveDict['Trend'] = 'Downtrend' + try: + slope,c = np.polyfit(data.index[data.tops > 0], data['tops'][data.tops > 0], 1) + angle = np.rad2deg(np.arctan(slope)) + if (angle <= 30 and angle >= -30): + dict['Trend'] = colorText.BOLD + colorText.WARN + "Sideways" + colorText.END + saveDict['Trend'] = 'Sideways' + elif (angle >= 30 and angle < 61): + dict['Trend'] = colorText.BOLD + colorText.GREEN + "Weak Up" + colorText.END + saveDict['Trend'] = 'Weak Up' + elif angle >= 60: + dict['Trend'] = colorText.BOLD + colorText.GREEN + "Strong Up" + colorText.END + saveDict['Trend'] = 'Strong Up' + elif (angle >= -30 and angle < -61): + dict['Trend'] = colorText.BOLD + colorText.FAIL + "Weak Down" + colorText.END + saveDict['Trend'] = 'Weak Down' + elif angle <= -60: + dict['Trend'] = colorText.BOLD + colorText.FAIL + "Strong Down" + colorText.END + saveDict['Trend'] = 'Strong Down' + except np.linalg.LinAlgError: + dict['Trend'] = colorText.BOLD + "Unknown" + colorText.END + saveDict['Trend'] = 'Unknown' return saveDict['Trend'] + # Debugging - Experiment with data # import matplotlib.pyplot as plt + # print(saveDict['Trend']) + # print(slope) + # print(math.degrees(math.atan(slope))) # plt.scatter(data.index[data.tops > 0], data['tops'][data.tops > 0], c='r') # plt.plot(data.index, data['Close']) # plt.plot(data.index, slope*data.index+c,) diff --git a/src/classes/Utility.py b/src/classes/Utility.py index fb320e1..3207d33 100644 --- a/src/classes/Utility.py +++ b/src/classes/Utility.py @@ -65,6 +65,7 @@ def getLastScreenedResults(): df = pd.read_pickle(lastScreened) print(colorText.BOLD + colorText.GREEN + '\n[+] Showing recently screened results..\n' + colorText.END) print(tabulate(df, headers='keys', tablefmt='psql')) + print(colorText.BOLD + colorText.WARN + "[+] Note: Trend calculation is based on number of recent days to screen as per your configuration." + colorText.END) input(colorText.BOLD + colorText.GREEN + '[+] Press any key to continue..' + colorText.END) except: print(colorText.BOLD + colorText.FAIL + '[+] Failed to load recently screened result table from disk! Skipping..' + colorText.END) diff --git a/src/screenipy.py b/src/screenipy.py index a17d1e6..0d999a2 100644 --- a/src/screenipy.py +++ b/src/screenipy.py @@ -189,6 +189,7 @@ def main(testing=False): print(tabulate(screenResults, headers='keys', tablefmt='psql')) Utility.tools.setLastScreenedResults(screenResults) Utility.tools.promptSaveResults(saveResults) + print(colorText.BOLD + colorText.WARN + "[+] Note: Trend calculation is based on number of days recent to screen as per your configuration." + colorText.END) print(colorText.BOLD + colorText.GREEN + "[+] Screening Completed! Happy Trading! :)" + colorText.END) input('') main()