Ejemplo n.º 1
0
def three_black_crows(key, dataList, time_frame):

    price_action = pd.DataFrame(dataList, columns=[id.time, id.open, id.close, id.high, id.low, id.volume])
    if price_action.empty:
        return

    window_size = constants.strategy_params[id.window_size]
    # crows=check if the last 3 candles are crows
    crows = utils.__is_bear(price_action.iloc[-1][id.open], price_action.iloc[-1][id.close]) \
            and utils.__is_bear(price_action.iloc[-2][id.open], price_action.iloc[-2][id.close]) \
            and utils.__is_bear(price_action.iloc[-3][id.open], price_action.iloc[-3][id.close]) \
            and __is_lower(price_action.iloc[-1][id.open], price_action.iloc[-1][id.close],
                           price_action.iloc[-2][id.open], price_action.iloc[-2][id.close], price_action.iloc[-2][id.low]) \
            and __is_lower(price_action.iloc[-2][id.open], price_action.iloc[-2][id.close],
                           price_action.iloc[-3][id.open], price_action.iloc[-3][id.close], price_action.iloc[-3][id.low])
    # check lower wick
    lower_wick = __small_lower_wick(price_action.iloc[-1]) \
                 and __small_lower_wick(price_action.iloc[-2]) \
                 and __small_lower_wick(price_action.iloc[-3])

    # find trend for candles from -17 to -3, extra window_size data for sma buffer
    trend = utils.__uptrend(price_action.iloc[-2*window_size - 3:-3][id.close].values, window_size)

    # check strategy
    if trend and crows and lower_wick:
        try:
            #db.insert_strategy(key, time_frame, values.three_black_crow, price_action.iloc[-1][id.time])
            return {
                id.name: id.three_black_crow,
                id.key: key,
                id.price_action: dataList
            }
        except:
            print('Unable to add to database')
            return {}
Ejemplo n.º 2
0
def morning_star(key, dataList, time_frame):
    price_action = pd.DataFrame(
        dataList,
        columns=[id.time, id.open, id.close, id.high, id.low, id.volume])
    if price_action.empty:
        return

    window_size = constants.strategy_params[id.window_size]
    downtrend = utils.__downtrend(
        price_action.iloc[-window_size - 3:-3][id.close].values, window_size)

    morning_star = utils.__is_bull(price_action.iloc[-1][id.open], price_action.iloc[-1][id.close]) \
                  and utils.__percentage_change(price_action.iloc[-1][id.open], price_action.iloc[-1][id.close]) > constants.strategy_params[id.body_percentage] \
                  and utils.__is_gap_up(price_action.iloc[-1][id.open], price_action.iloc[-2][id.open], price_action.iloc[-2][id.close]) \
                  and utils.__percentage_change(price_action.iloc[-2][id.open], price_action.iloc[-2][id.close]) < constants.strategy_params[id.small_body_percentage] \
                  and utils.__is_gap_up(price_action.iloc[-3][id.open], price_action.iloc[-2][id.open], price_action.iloc[-2][id.close]) \
                  and utils.__is_bear(price_action.iloc[-3][id.open], price_action.iloc[-3][id.close]) \
                  and utils.__percentage_change(price_action.iloc[-3][id.open], price_action.iloc[-3][id.close]) > constants.strategy_params[id.body_percentage] \
                  and utils.__threshold_down(price_action.iloc[-3][id.open], price_action.iloc[-3][id.close], price_action.iloc[-1][id.close])

    if downtrend and morning_star:
        try:
            #db.insert_strategy(key, time_frame, values.morning_star, price_action.iloc[-1][id.time])
            return {
                id.name: id.morning_star,
                id.key: key,
                id.price_action: dataList
            }
        except:
            print('Unable to add to database')
            return {}
Ejemplo n.º 3
0
def bullish_abandoned_baby(key, dataList, time_frame):

    price_action = pd.DataFrame(
        dataList,
        columns=[id.time, id.open, id.close, id.high, id.low, id.volume])
    if price_action.empty:
        return

    window_size = constants.strategy_params[id.window_size]
    downTrend = utils.__downtrend(
        price_action.iloc[-2 * window_size - 3:-3][id.close].values,
        window_size)

    abandonedBaby = utils.__is_bull(price_action.iloc[-1][id.open], price_action.iloc[-1][id.close]) \
                    and utils.__percentage_change(price_action.iloc[-1][id.open], price_action.iloc[-1][id.close]) > constants.strategy_params[id.body_percentage] \
                    and price_action.iloc[-1][id.low] > price_action.iloc[-2][id.high] \
                    and utils.__is_doji(price_action.iloc[-2][id.open], price_action.iloc[-2][id.close]) \
                    and price_action.iloc[-3][id.high] > price_action.iloc[-2][id.low] \
                    and utils.__is_bear(price_action.iloc[-3][id.open], price_action.iloc[-3][id.close]) \
                    and utils.__percentage_change(price_action.iloc[-2][id.open], price_action.iloc[-2][id.close]) > constants.strategy_params[id.body_percentage]

    if downTrend and abandonedBaby:
        try:
            #db.insert_strategy(key, time_frame, values.bullish_abandoned_baby, price_action.iloc[-1][id.time])
            return {
                id.name: id.bullish_abandoned_baby,
                id.key: key,
                id.price_action: price_action.to_dict()
            }
        except:
            print('Unable to add to database')
            return {}
def three_black_crows(key, price_action, time_frame):
    window_size = constants.strategy_params[id.window_size]
    # crows=check if the last 3 candles are crows
    crows = utils.__is_bear(price_action.iloc[-1][id.open], price_action.iloc[-1][id.close]) \
            and utils.__is_bear(price_action.iloc[-2][id.open], price_action.iloc[-2][id.close]) \
            and utils.__is_bear(price_action.iloc[-3][id.open], price_action.iloc[-3][id.close]) \
            and __is_lower(price_action.iloc[-1][id.open], price_action.iloc[-1][id.close],
                           price_action.iloc[-2][id.open], price_action.iloc[-2][id.close], price_action.iloc[-2][id.low]) \
            and __is_lower(price_action.iloc[-2][id.open], price_action.iloc[-2][id.close],
                           price_action.iloc[-3][id.open], price_action.iloc[-3][id.close], price_action.iloc[-3][id.low])
    # check lower wick
    lower_wick = __small_lower_wick(price_action.iloc[-1]) \
                 and __small_lower_wick(price_action.iloc[-2]) \
                 and __small_lower_wick(price_action.iloc[-3])

    # find trend for candles from -17 to -3, extra window_size data for sma buffer
    trend = utils.__uptrend(
        price_action.iloc[-2 * window_size - 3:-3][id.close].values,
        window_size)

    # check strategy
    if trend and crows and lower_wick:
        db.insert_strategy(key, time_frame, values.three_black_crow,
                           price_action.iloc[-1][id.time])
Ejemplo n.º 5
0
def bullish_abandoned_baby(key, price_action, time_frame):

    window_size = constants.strategy_params[id.window_size]
    downTrend = utils.__downtrend(
        price_action.iloc[-2 * window_size - 3:-3][id.close].values,
        window_size)

    abandonedBaby = utils.__is_bull(price_action.iloc[-1][id.open], price_action.iloc[-1][id.close]) \
                    and utils.__percentage_change(price_action.iloc[-1][id.open], price_action.iloc[-1][id.close]) > constants.strategy_params[id.body_percentage] \
                    and price_action.iloc[-1][id.low] > price_action.iloc[-2][id.high] \
                    and utils.__is_doji(price_action.iloc[-2][id.open], price_action.iloc[-2][id.close]) \
                    and price_action.iloc[-3][id.high] > price_action.iloc[-2][id.low] \
                    and utils.__is_bear(price_action.iloc[-3][id.open], price_action.iloc[-3][id.close]) \
                    and utils.__percentage_change(price_action.iloc[-2][id.open], price_action.iloc[-2][id.close]) > constants.strategy_params[id.body_percentage]

    if downTrend and abandonedBaby:
        db.insert_strategy(key, time_frame, values.bullish_abandoned_baby,
                           price_action.iloc[-1][id.time])
def evening_star(data, w_start, window_size, ratio):
    evening_star = utils.__is_bull(data['open'].values[w_start + window_size],
                                   data['close'].values[w_start + window_size]) \
                   and utils.__is_gap_down(data['close'].values[w_start + window_size],
                                           data['open'].values[w_start + window_size + 1],
                                           data['close'].values[w_start + window_size + 1]) \
                   and utils.__body(data['open'].values[w_start + window_size + 1],
                                    data['close'].values[w_start + window_size + 1]) < ratio * \
                   utils.__body(data['open'].values[w_start + window_size], data['close'].values[w_start + window_size]) \
                   and utils.__body(data['open'].values[w_start + window_size + 1],
                                    data['close'].values[w_start + window_size + 1]) < ratio * \
                   utils.__body(data['open'].values[w_start + window_size + 2],
                                data['close'].values[w_start + window_size + 2]) \
                   and utils.__is_gap_down(data['open'].values[w_start + window_size + 2],
                                           data['open'].values[w_start + window_size + 1],
                                           data['close'].values[w_start + window_size + 1]) \
                   and utils.__is_bear(data['open'].values[w_start + window_size + 2],
                                       data['close'].values[w_start + window_size + 2]) \
                   and utils.__threshold_up(data['open'].values[w_start + window_size],
                                            data['close'].values[w_start + window_size],
                                            data['close'].values[w_start + window_size + 2])

    return evening_star