def isBullTakeover(quotes: List[Quote]) -> float: if len(quotes) >= 2 and is_red(quotes[0]) and is_green(quotes[1]) and \ quotes[0].open_price > quotes[1].open_price and body_length(quotes[0]) != 0: ratio_between_candles = body_length(quotes[1]) / body_length(quotes[0]) if ratio_between_candles > 1.2: return ratio_between_candles return 0
def falling_snippet(parameters: Dict): split_point = parameters[SPLIT_POINT] quotes = parameters[QUOTES] growth_to_fall_power = -round( is_growth_to_fall(quotes[split_point - 2:split_point + 4]), 3) if growth_to_fall_power == 0: return None parameters[CUSTOM_FILE_NAME] = str( quotes[split_point - NUMBER_OF_ROWS_IN_SNIPPET_FILE].date) + "_" + str( quotes[split_point].date) + "." + str(growth_to_fall_power) amplitude_of_fall = quotes[split_point].close_price * ( 1 - PERCENT_OF_GROWTH_OR_FALL_AFTER_SNIPPET / 100) amplitude_of_rollback = quotes[split_point].high_price * ( 1 + PERCENT_OF_MAXIMUM_ALLOWED_ROLLBACK / 100) for pointer in range(split_point + 1, split_point + PREDICTION_SIZE_IN_BUSINESS_DAYS + 1): # if graphic goes in the direction where we don't want if quotes[pointer].high_price > amplitude_of_rollback and is_green( quotes[pointer]): parameters[SNIPPET_TYPE] = SnippetTypes.hold return create_snippet(parameters) if quotes[pointer].close_price < amplitude_of_fall and is_red( quotes[pointer]): parameters[SNIPPET_TYPE] = SnippetTypes.sell return create_snippet(parameters) pointer += 1 parameters[SNIPPET_TYPE] = SnippetTypes.hold return create_snippet(parameters)
def isDojiDragonfly(quotes: List[Quote]) -> float: if len(quotes) < 3: return 0 if quotes[1].high_price == body_top and is_red(quotes[0]) and is_green(quotes[2]) and \ quotes[1].low_price < body_bottom(quotes[1]) < min(quotes[0].open_price, quotes[2].close_price) and \ (body_length == 0 or lower_shadow(quotes[1]) / body_length(quotes[1]) > 3): return confirm_fall_to_growth_trend_reversal(quotes, 1) return 0
def isDojiGravestone(quotes: List[Quote]) -> float: if len(quotes) < 3: return 0 if quotes[1].low_price == body_bottom(quotes[1]) and is_green(quotes[0]) and is_red(quotes[2]) and \ quotes[1].high_price > body_top(quotes[1]) > max(quotes[0].open_price, quotes[2].close_price) and \ (body_length == 0 or upper_shadow(quotes[1]) / body_length(quotes[1]) > 3): return 1 return 0
def isAbandonedBaby(quotes: List[Quote]) -> float: if len(quotes) < 3: return 0 if is_red(quotes[0]) and is_green(quotes[2]) and \ quotes[1].high_price < min(quotes[0].low_price, quotes[2].low_price) and \ (body_length(quotes[1]) == 0 or min(lower_shadow(quotes[1]), upper_shadow(quotes[1])) / body_length(quotes[1]) > 2): return 5 return 0
def isDojiMorningStar(quotes: List[Quote]) -> float: if len(quotes) < 3: return 0 if is_red(quotes[0]) and is_green(quotes[2]) and \ body_top(quotes[1]) < min(quotes[0].close_price, quotes[2].open_price) and \ (body_length(quotes[1]) == 0 or min(lower_shadow(quotes[1]), upper_shadow(quotes[1])) / body_length(quotes[1]) > 2): return 2 return 0
def isHammer(quotes: List[Quote]) -> float: if len(quotes) < 3: return 0 if is_red(quotes[0]) and is_green(quotes[2]) and body_length(quotes[1]) != 0 and \ quotes[1].low_price < min(quotes[0].low_price, quotes[2].low_price) and \ (upper_shadow(quotes[1]) == 0 or lower_shadow(quotes[1]) / upper_shadow(quotes[1]) > 3): ratio_shadow_to_body = lower_shadow(quotes[1]) / body_length(quotes[1]) if ratio_shadow_to_body > 2: return ratio_shadow_to_body return 0
def falling_snippet(parameters: Dict): split_point = parameters[SPLIT_POINT] quotes = parameters[QUOTES] amplitude_of_fall = quotes[split_point].close_price * ( 1 - PERCENT_OF_GROWTH_OR_FALL_AFTER_SNIPPET / 100) amplitude_of_rollback = quotes[split_point].high_price * ( 1 + PERCENT_OF_MAXIMUM_ALLOWED_ROLLBACK / 100) for pointer in range(split_point + 1, split_point + PREDICTION_SIZE_IN_BUSINESS_DAYS + 1): # if graphic goes in the direction where we don't want if quotes[pointer].high_price > amplitude_of_rollback and is_green( quotes[pointer]): parameters[SNIPPET_TYPE] = SnippetTypes.hold return create_snippet(parameters) if quotes[pointer].close_price < amplitude_of_fall and is_red( quotes[pointer]): parameters[SNIPPET_TYPE] = SnippetTypes.sell return create_snippet(parameters) pointer += 1 parameters[SNIPPET_TYPE] = SnippetTypes.hold return create_snippet(parameters)
def growing_snippet(parameters: Dict): split_point = parameters[SPLIT_POINT] quotes = parameters[QUOTES] if DecisionMaker.should_buy(parameters[QUOTES][0:split_point]) is None: return None amplitude_of_growth = quotes[split_point].close_price * ( 1 + PERCENT_OF_GROWTH_OR_FALL_AFTER_SNIPPET / 100) amplitude_of_rollback = quotes[split_point].low_price * ( 1 - PERCENT_OF_MAXIMUM_ALLOWED_ROLLBACK / 100) for pointer in range(split_point + 1, split_point + PREDICTION_SIZE_IN_BUSINESS_DAYS + 1): # if graphic goes in the direction where we don't want if quotes[pointer].low_price < amplitude_of_rollback and is_red( quotes[pointer]): parameters[SNIPPET_TYPE] = SnippetTypes.hold return create_snippet(parameters) if quotes[pointer].close_price > amplitude_of_growth and is_green( quotes[pointer]): parameters[SNIPPET_TYPE] = SnippetTypes.buy return create_snippet(parameters) pointer += 1 parameters[SNIPPET_TYPE] = SnippetTypes.hold return create_snippet(parameters)