Esempio n. 1
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 {}
Esempio n. 2
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 {}
Esempio n. 3
0
def double_top_double_bottom(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]
    # To determine up/down trend and the strength
    upTrend = utils.__uptrend(
        price_action.iloc[-2 * window_size - 3:-3][id.close].values,
        window_size)
    downTrend = utils.__downtrend(
        price_action.iloc[-2 * window_size - 3:-3][id.close].values,
        window_size)

    # ADX to determine the strength of the trend and OBV to get volume of trades placed
    adx = ta.ADX(price_action[id.high], price_action[id.low],
                 price_action[id.close], window_size)
    obv = ta.OBV(price_action[id.close], price_action[id.volume])

    # Calculate the local maxima and minima in the window frame
    local_minima, local_maxima, indices_minima, indices_maxima = utils.__local_min_max(
        np.array(price_action[id.high]))

    notifier = {values.double_top: False, values.double_bottom: False}

    if upTrend and adx[len(adx) -
                       1] >= constants.strategy_params[id.trend_strength]:
        notifier[values.double_top] = check_double_top(price_action,
                                                       indices_maxima, obv)
    if downTrend and adx[len(adx) -
                         1] >= constants.strategy_params[id.trend_strength]:
        notifier[values.double_bottom] = check_double_bottom(
            price_action, indices_minima, obv)

    if notifier[values.double_top]:
        try:
            #db.insert_strategy(key, time_frame, values.double_top, price_action.iloc[-1][id.time])
            return {
                id.name: id.double_top,
                id.key: key,
                id.price_action: dataList
            }
        except:
            print('Unable to add to database')
            return {}

    if notifier[values.double_bottom]:
        try:
            #db.insert_strategy(key, time_frame, values.double_bottom, price_action.iloc[-1][id.time])
            return {
                id.name: id.double_bottom,
                id.key: key,
                id.price_action: dataList
            }
        except:
            print('Unable to add to database')
            return {}
Esempio n. 4
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])
Esempio n. 5
0
def three_white_soldiers(key, price_action, time_frame):
    window_size = constants.strategy_params[id.window_size]
    # soldiers=check if the last 3 candles are soldiers
    soldiers = utils.__is_bull(price_action.iloc[-1][id.open], price_action.iloc[-1][id.close]) \
            and utils.__is_bull(price_action.iloc[-2][id.open], price_action.iloc[-2][id.close]) \
            and utils.__is_bull(price_action.iloc[-3][id.open], price_action.iloc[-3][id.close]) \
            and __is_higher(price_action.iloc[-1][id.open], price_action.iloc[-1][id.close], price_action.iloc[-1][id.low],
                           price_action.iloc[-2][id.open], price_action.iloc[-2][id.close]) \
            and __is_higher(price_action.iloc[-2][id.open], price_action.iloc[-2][id.close], price_action.iloc[-2][id.low],
                           price_action.iloc[-3][id.open], price_action.iloc[-3][id.close])
    # check lower wick
    lower_wick = __small_upper_wick(price_action.iloc[-1]) \
                 and __small_upper_wick(price_action.iloc[-2]) \
                 and __small_upper_wick(price_action.iloc[-3])

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

    # check strategy
    if trend and soldiers and lower_wick:
        db.insert_strategy(key, time_frame, values.three_white_soldiers, price_action.iloc[-1][id.time])
def three_white_soldiers(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]
    # soldiers=check if the last 3 candles are soldiers
    soldiers = utils.__is_bull(price_action.iloc[-1][id.open], price_action.iloc[-1][id.close]) \
            and utils.__is_bull(price_action.iloc[-2][id.open], price_action.iloc[-2][id.close]) \
            and utils.__is_bull(price_action.iloc[-3][id.open], price_action.iloc[-3][id.close]) \
            and __is_higher(price_action.iloc[-1][id.open], price_action.iloc[-1][id.close], price_action.iloc[-1][id.low],
                           price_action.iloc[-2][id.open], price_action.iloc[-2][id.close]) \
            and __is_higher(price_action.iloc[-2][id.open], price_action.iloc[-2][id.close], price_action.iloc[-2][id.low],
                           price_action.iloc[-3][id.open], price_action.iloc[-3][id.close])
    # check lower wick
    lower_wick = __small_upper_wick(price_action.iloc[-1]) \
                 and __small_upper_wick(price_action.iloc[-2]) \
                 and __small_upper_wick(price_action.iloc[-3])

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

    # check strategy
    if trend and soldiers and lower_wick:
        try:
            #db.insert_strategy(key, time_frame, values.three_white_soldiers, price_action.iloc[-1][id.time])
            return {
                id.name: id.three_white_soldiers,
                id.key: key,
                id.price_action: dataList
            }
        except:
            print('Unable to add to database')
            return {}
Esempio n. 7
0
        # shooting star
        for window_size in range(5, 21):
            small_body = 0.05
            while small_body <= 0.50:
                lower_wick = 0
                while lower_wick < 1.00:
                    w_start = 0
                    correct = 0
                    identify = 0
                    while w_start != data.shape[0] - 2 * window_size:
                        # do this for all the strategies...
                        uptrend = utils.__uptrend(
                            data['close'][w_start:w_start +
                                          window_size].values, window_size)
                        downtrend = utils.__downtrend(
                            data['close'][w_start:w_start +
                                          window_size].values, window_size)

                        # shooting star
                        shooting_star = ss.shooting_star(
                            data, w_start, window_size, lower_wick, small_body)
                        if uptrend and shooting_star:
                            # verify if it is followed by a downtrend
                            downtrend = utils.__downtrend(
                                data['close'][w_start + window_size +
                                              1:w_start + 2 * window_size +
                                              1].values, window_size)
                            if downtrend:
                                print('up_down')
                                correct += 1
                            identify += 1
Esempio n. 8
0
 dt_identify = 0
 db_correct = 0
 db_identify = 0
 while w_start != data.shape[0] - 3 * window_size:
     print(w_start)
     # do this for all the strategies...
     res = dtdb.double_top_double_bottom(
         price_action=data.iloc[w_start:w_start +
                                3 * window_size],
         window_size=window_size,
         trend_strength=trend_strength,
         diff_threshold=diff_threshold)
     if res['dt']:
         downtrend = utils.__downtrend(
             data['close'][w_start + 3 * window_size +
                           1:w_start +
                           4 * window_size].values,
             window_size)
         if downtrend:
             print('Yay')
             dt_correct += 1
         dt_identify += 1
     if res['db']:
         uptrend = utils.__uptrend(
             data['close'][w_start + 3 * window_size +
                           1:w_start +
                           4 * window_size].values,
             window_size)
         if uptrend:
             print('Yay')
             db_correct += 1