コード例 #1
0
 def add_macd(df_or_lst, short_period, long_period):
     if isinstance(df_or_lst, list) == True:
         return macd(df_or_lst, short_period, long_period)
     else:
         Indicator.stand_alone.append('macd ' + str(short_period) +
                                      str(long_period))
         data_frame['macd ' + str(short_period) + str(long_period)] = macd(
             df_or_lst['close'].tolist(), short_period, long_period)
コード例 #2
0
def screen():
    client = Client("api-key", "api-secret", {"verify": False, "timeout": 20})
    positiveCoin = get_positive_coin.positiveCoin
    bullishKScoin = []
    for m in positiveCoin:
        candles = client.get_klines(symbol=m, interval=client.KLINE_INTERVAL_30MINUTE)
        if candles[-2][1] < candles[-2][4] <= candles[-1][1] < candles[-1][4]:
            bullishKScoin.append(m)

    macdCoin = []
    for m in bullishKScoin:
        candles = client.get_klines(symbol=m, interval=client.KLINE_INTERVAL_1HOUR)
        close = []
        for n in candles:
            close.append(float(n[4]))
        mac = macd(close, 12, 26)
        macs = macds(mac)
        mach = macdh(mac, macs)
        # if mach[-1] > 0 and (macs[-1] - macs[-2]) > 0 and (mac[-1] - mac[-2]) > 0:
        #     macdCoin.append(m)
        if mach[-1] > 0 and (macs[-1] - macs[-2]) > 0 and (mac[-1] - mac[-2]) > 0:
            macdCoin.append(m)

    bollCoin = []
    for m in macdCoin:
        candles = client.get_klines(symbol=m, interval=client.KLINE_INTERVAL_1HOUR)
        close = []
        for n in candles:
            close.append(float(n[4]))
        lb = lbb(close, 20, 2)
        mb = mbb(close, 20, 2)
        ub = ubb(close, 20, 2)

        if lb[-1] < close[-1] < ((0.8 * ub[-1]) + (0.2 * mb[-1])):
            bollCoin.append(m)

    maxDemandRatio = 0
    buyingCoin = ''
    for m in bollCoin:
        depth = client.get_order_book(symbol=m)
        buyingVol = 0
        sellingVol = 0
        for n in depth['bids'][0:20]:
            buyingVol = buyingVol + float(n[1])
        for n in depth['asks'][0:20]:
            sellingVol = sellingVol + float(n[1])
        demandRatio = buyingVol / sellingVol
        print(demandRatio)
        print(maxDemandRatio)
        if demandRatio > maxDemandRatio:
            maxDemandRatio = demandRatio
            buyingCoin = m

    print(bullishKScoin)
    print(macdCoin)
    print(bollCoin)
    print(buyingCoin)
    return buyingCoin
コード例 #3
0
ファイル: pyti_macd.py プロジェクト: w1r2p1/KryptoBot
 def next_calculation(self, candle):
     if self.get_datawindow() is not None:
         md = macd(self.get_close(), self.params['short_window'],
                   self.periods)[-1]
         self.macd.append(md)
         signal = ema(self.macd, self.params['signal_window'])
         self.value = {
             'macd': md,
             'signal': signal[-1],
             'crossover': md - signal[-1]
         }
コード例 #4
0
def macd_func(indices, presences, data):
    presence = np.mean([presences])
    if presence > 52.5:
        if indices[0] > indices[1]:
            indices[0], indices[1] = indices[1], indices[0]
        print("indices: " + str(indices[0]) + "  " + str(indices[1]))
        values = "(" + str(indices[0]) + "," + str(indices[1]) + ")"
        data['macd' + values] = macd(data['Close'].values, indices[0],
                                     indices[1])
        data['macd_sign'] = ema(data['macd' + values].values, 9)
        data['macd_hist'] = data['macd' +
                                 values].values - data['macd_sign'].values
    return data
コード例 #5
0
def prepare_data(symbol):

    coin = symbol
    coin_1 = crypto_data(coin)
    df = coin_1

    df['SMA_20'] = sma(df['Close'], 20)
    df['SMA_50'] = sma(df['Close'], 50)

    df['EMA_20'] = ema(df['Close'], 20)
    df['EMA_50'] = ema(df['Close'], 50)

    df['MACD'] = macd(df['Close'], 26, 12)

    df['per_k_stoch_10'] = percent_k(df['Close'], 10)
    df['per_d_stoch_10'] = percent_d(df['Close'], 10)

    df['OBV'] = obv(df['Close'], df['Volume'])

    fp = []
    for price in df['Close']:
        fp.append(price)

    fp.pop(0)
    fp.append(df['Close'].mean())
    df['FP'] = fp

    df_predict = df.tail(1)
    df.drop(df.tail(1).index, inplace=True)

    label = []
    for i in range(len(df)):
        if df['FP'][i] > df['Close'][i]:
            label.append(1)
        else:
            label.append(0)

    df['goes_up'] = label
    df = df.drop(['FP'], axis=1)
    df = df.fillna(df.mean())
    df_predict = df_predict.drop(['FP'], axis=1)

    return df, df_predict
コード例 #6
0
def screen():
    client = Client("api-key", "api-secret", {"verify": False, "timeout": 20})
    positiveCoin = get_positive_coin.coin

    bollCoin = []
    for m in positiveCoin:
        candles = client.get_klines(symbol=m,
                                    interval=client.KLINE_INTERVAL_15MINUTE)
        close = []
        for n in candles:
            close.append(float(n[4]))
        pb = pbb(close, 20, 2.0, 2.0)
        if pb[-1] < 10:
            bollCoin.append(m)

    macdCoin = []
    for m in bollCoin:
        candles = client.get_klines(symbol=m,
                                    interval=client.KLINE_INTERVAL_5MINUTE)
        close = []
        for n in candles:
            close.append(float(n[4]))
        mac = macd(close, 12, 26)
        macs = macds(mac)
        mach = macdh(mac, macs)
        if mach[-1] > 0 and (macs[-1] - macs[-2]) < 0 and (mac[-1] -
                                                           mac[-2]) > 0:
            macdCoin.append(m)

    rsiCoin = []
    for m in macdCoin:
        candles = client.get_klines(symbol=m,
                                    interval=client.KLINE_INTERVAL_15MINUTE)
        close = []
        for n in candles:
            close.append(float(n[4]))
        rs = rsi(close, 14)
        if rs[-1] < 30:
            rsiCoin.append(m)
    buyingCoin = ''
    maxDemandRatio = 0
    for m in rsiCoin:
        depth = client.get_order_book(symbol=m)
        buyingVol = 0
        sellingVol = 0
        for n in depth['bids'][0:20]:
            buyingVol = buyingVol + float(n[1])
        for n in depth['asks'][0:20]:
            sellingVol = sellingVol + float(n[1])
        demandRatio = buyingVol / sellingVol
        print(demandRatio)
        print(maxDemandRatio)
        if demandRatio > maxDemandRatio:
            maxDemandRatio = demandRatio
            buyingCoin = m

    if maxDemandRatio < 1.5:
        buyingCoin = ''

    print(bollCoin)
    print(macdCoin)
    print(rsiCoin)
    print(buyingCoin)
    return buyingCoin
コード例 #7
0
def moving_average_convergence_divergence(data, short_period, long_period):
    return macd(data, short_period, long_period)