def start_buy_local_bottom_test(_asset): _klines = get_pickled(trades_logs_dir, "test_klines_{}".format(_asset.market)) _klines_tail = get_last(_klines, -1, len(_klines)) for _i in range(116, len(_klines_tail)): _klines_test = _klines_tail[0:_i] buy_local_bottom_bullish_test(_klines_test, _i)
def get_most_volatile_market(): _filename = "exclude-markets" _ticker = Client.KLINE_INTERVAL_3MINUTE _volatile_markets = {} _exclude_markets = {} _window = "1 days ago" if path.isfile(key_dir + _filename + ".pkl"): _exclude_markets = get_pickled(key_dir, _filename) else: _exclude_markets[_ticker] = exclude_markets _markets = binance_obj.get_all_btc_currencies(_exclude_markets[_ticker]) _window = "1 day ago" for _market in _markets: try: _klines = get_klines(_market, _ticker, _window) _closes = get_closes(_klines) if _market == 'COCOSBTC': i = 1 if is_magnitude_gt(_closes[-1], -6.5): _std = get_std_last(_closes, 1) _volatile_markets[_market] = _std / _closes[-1] except Exception: print(f"No data for market : {_market}") if _ticker in _exclude_markets: _exclude_markets[_ticker].append(_market) else: _exclude_markets[_ticker] = [_market] _s = sorted(_volatile_markets, key=_volatile_markets.get, reverse=True) save_to_file(key_dir, "exclude-markets", _exclude_markets) i = 1
def show_klines(_asset): _klines = get_pickled(trades_logs_dir, "test_klines_{}".format(_asset.market)) _closes = get_closes(_klines) _ma7 = talib.MA(_closes, timeperiod=7) _ma50 = talib.MA(_closes, timeperiod=50) _ma100 = talib.MA(_closes, timeperiod=100) r = talib.RSI(_closes, timeperiod=14) plt.subplot2grid((3, 1), (1, 0)) plt.plot(_ma7, 'pink', lw=1) # plt.plot(_ma50, 'red', lw=1) plt.plot(_ma100, 'green', lw=1) plt.subplot2grid((3, 1), (2, 0)) plt.plot(r, 'red', lw=1) plt.show()
def read_broken_rsi(): _closes = get_pickled(trades_logs_dir, "broken_rsi_closes_1562196654.5590825") r = relative_strength_index(_closes)
def main(): # asset = Asset(exchange="binance", name="LINK", ticker=BinanceClient.KLINE_INTERVAL_1HOUR) # is_bullish_setup(asset) # analyze_markets() # get_most_volatile_market() asset = "NEO" market = "{}BTC".format(asset) # ticker = BinanceClient.KLINE_INTERVAL_30MINUTE ticker = BinanceClient.KLINE_INTERVAL_1HOUR time_interval = "2 weeks ago" # _klines = get_binance_klines(market, ticker, time_interval) _kucoin_ticker = "1day" # _klines = get_kucoin_klines(market, _kucoin_ticker, get_kucoin_interval_unit(_kucoin_ticker, 400)) # _klines = get_klines(market, ticker, time_interval) # save_to_file("e://bin//data//", "klines-neo", _klines) _klines = get_pickled('e://bin/data//', "klines-neo") _klines = _klines[:-3] _closes = np.array(list(map(lambda _x: float(_x.closing), _klines))) # find_valuable_alts(_closes) _is, _1 = is_second_golden_cross(_klines) bf = is_bull_flag(_klines) # fw0 = is_falling_wedge_0(_closes) fw = is_falling_wedge(_klines) macd, macdsignal, macdhist = talib.MACD(_closes, fastperiod=12, slowperiod=26, signalperiod=9) r = relative_strength_index(_closes) hl = is_higher_low(r, 45.0, 33, -1) is_it = is_tradeable(_closes, r, macd, macdsignal) res0 = is_second_golden_cross(_klines[:-1]) res = is_first_golden_cross(_klines) d = is_drop_below_ma50_after_rally(_klines) d1 = is_drop_below_ma200_after_rally(_klines) # _closes = np.array(list(map(lambda _x: float(_x[4]), _klines))) # _opens = np.array(list(map(lambda _x: float(_x[1]), _klines))) # _high = list(map(lambda _x: float(_x[2]), _klines)) # _low = list(map(lambda _x: float(_x[3]), _klines)) _closes = np.array(list(map(lambda _x: float(_x.closing), _klines))) _opens = np.array(list(map(lambda _x: float(_x.opening), _klines))) _high = list(map(lambda _x: float(_x.highest), _klines)) _low = list(map(lambda _x: float(_x.lowest), _klines)) bv, bi = bear_cross(_closes) _ind, _rel_ind, _diff = index_of_max_mas_difference(_closes) _res = [] _r = compute_wider_interval(is_tilting, _klines) # for i in range(0, 24): # if i == 0: # _res.append(is_tilting(_closes)) # else: # _res.append(is_tilting(_closes[:-i])) # _is_it = is_tilting(_closes) ## MACD # _out = is_second_golden_cross(_closes) # _first = is_first_golden_cross(_klines) # start = 0 # stop = -5*60-30-32 stop = -1 # stop = -2650 # save_to_file("/juno/", "klines-theta", _klines[start:stop:1]) # out = is_second_golden_cross(_closes[:stop]) # t = is_tradeable(_closes, r, macd, macdsignal) # rsi_normal_cond = is_rsi_slope_condition(r, 45, 30, start, stop) # rsi_normal_tight = is_rsi_slope_condition(r, 30, 20, start, stop) # macd_normal_cond = is_macd_condition(macd, 45, start, stop) # divergence_ratio = is_signal_divergence_ratio(macd, macdsignal, 0.1, start, stop) # is_hl = is_higher_low(r, 45, start, stop) plt.subplot2grid((3, 1), (0, 0)) plt.plot(macd[start:stop:1], 'blue', lw=1) plt.plot(macdsignal[start:stop:1], 'red', lw=1) # plt.plot(ema9[-wins:], 'red', lw=1) # plt.plot(macd[-wins:], 'blue', lw=1) # plt.subplot2grid((2, 1), (7, 0)) # plt.plot(macd[start:stop:1] - macdsignal[start:stop:1], 'k', lw=2) plt.plot(np.zeros(len(macd[start:stop:1])), 'y', lw=2) # plt.axhline(y=0, color='b', linestyle='-') plt.subplot2grid((3, 1), (1, 0)) plt.plot(r[start:stop:1], 'red', lw=1) ma40 = talib.MA(_closes, timeperiod=40) plt.subplot2grid((3, 1), (2, 0)) plt.plot(ma40[start:stop:1], 'black', lw=1) plt.plot(_closes[start:stop:1], 'green', lw=1) _outcome = check_ma_crossing(ma40, _high) _zero = find_zero(macd[start:stop:1] - macdsignal[start:stop:1]) _min_val, _min_ind = find_first_minimum(macd[start:stop:1] - macdsignal[start:stop:1], _window=1) _price = get_bid_price(macd[start:stop:1] - macdsignal[start:stop:1], _low) _p = get_setup_entry(_klines) plt.show() ma200 = talib.MA(_closes, timeperiod=200) # ma100 = talib.MA(_closes, timeperiod=100) ma50 = talib.MA(_closes, timeperiod=50) # ma20 = talib.MA(_closes, timeperiod=20) # ma7 = talib.MA(_closes, timeperiod=7) _ma200 = ma200[start:stop:1] _ma50 = ma50[start:stop:1] _mv, _mi = find_first_maximum(_ma200[-500:], 10) _mv2, _m2i = find_maximum_2(_ma200, 10) _minv, _mini = find_minimum_2(_ma200, 10) _maxv, _maxi = find_maximum_2(_ma200[-_mini:], 10) _cond1 = True if _ma200[-1] < _maxv: _cond1 = (_maxv - _minv) / _minv > 0.05 _cond2 = (_ma200[-1] - _minv) / _minv > 0.05 and _mini > 500 _bc_val, _bc_ind = bull_cross(_closes) _cond3 = _bc_ind < 10 _fmax_v, _fmax_i = find_first_maximum(_ma200, 10) _fminv, _fmin_i0 = find_first_minimum(_ma200[:-_fmax_i], 10) _fmin_i = _fmax_i + _fmin_i0 - 1 _fmax_v0, _fmax_i0_ = find_first_maximum(_ma200[:-_fmin_i], 10) _fmax_i0 = _fmax_i0_ + _fmin_i - 1 _cond4_bear = not (_fmax_v - _fminv) / _fminv > 0.05 and _fmax_v - _fmax_v0 < 0 _is = is_bull_cross_in_bull_mode(_closes) _first_gc = find_first_golden_cross(_ma50, _ma200, 50) below_ma = drop_below_ma(_ma200[-_first_gc[1]:], _closes[-_first_gc[1]:], 5) _max_high = find_local_maximum(_high[-_first_gc[1]:], 100) rally = (_max_high[0] - _first_gc[0]) / _first_gc[0] # 48, 82 % if rally > 0.5 and below_ma[1] > 0: i = 1 k = 1 # _max_200 = find_local_maximum(_ma200, 200) # first a long-period maximum # _min_200 = find_minimum_2(_ma200, 200) # first a long-period minimum # _max_200_1 = find_first_maximum(_ma200, 5) # second lower max # _min_200_1 = find_first_minimum(_ma200, 25) # first higher minimum # # # fall = (np.max(_high[-500:])-np.min(_low[-500:]))/np.max(_high[-500:]) # > 22% # # # _max_200_1 = find_first_maximum(_ma200, 5) # # _max = find_first_maximum(_ma50, 10) # _min = find_minimum(_ma50[-_max[1]:]) # # _max_g = find_local_maximum(_ma50, 50) # _max_l = find_local_maximum(_ma50[-_max_g[1]:], 50) # _min_l = find_minimum(_ma50[-_max_g[1]:-_max_l[1]]) # _min_low_l = find_minimum(_low[-_max_g[1]:-_max_l[1]]) # # _min_l_ind = -_max_l[1] + _min_l[1] # _min_low_l_ind = -_max_l[1] + _min_low_l[1] # _max_l_ind = - _max_l[1] # # _max_high_l = find_local_maximum(_high[_min_l_ind:-_max_l[1]], 10) # _min_before_local_max = find_minimum(_low[_max_l_ind:]) # rise = (_max_high_l[0]-_min_low_l[0])/_min_low_l[0] # > 15% # drop = (_max_high_l[0] - _min_before_local_max[0]) / _max_high_l[0] # > 10% # _ma50[-_max_l[1] - 44] - _min_l[0] # _ma200[:-_max[1] + 1] # first n elements until max element # _max_b = find_local_maximum(_ma200[-_max[1]:_min[1]], 10) # 43, 36, 20 % # if fall > 0.22 and rise > 0.15 and drop > 0.1 and np.abs(_max_l_ind) > 50: # i = 7 _ma50 = ma50[start:stop:1] _max_50 = find_local_maximum(_ma50, 200) # first a long-period maximum _min_50 = find_minimum_2(_ma50, 200) # first a long-period minimum _max_50_1 = find_first_maximum(_ma50, 10) # second lower max _min_50_1 = find_first_minimum(_ma50, 25) # first higher minimum if _min_50[0] < _min_50_1[0] < _max_50_1[0] < _max_50[0] and _max_50[ 1] > _min_50[1] > _max_50_1[1] > _min_50_1[1]: aja = 1 # HL_ma50_reversal_cond = _min_50[0] < _min_50_1[0] < _max_50_1[0] < _max_50[0] and _max_50[1] > _min_50[1] > _max_50_1[1] > _min_50_1[1] # min_after_max_low_variance = _min_200[0] < _max_200[0] and _max_200[1] > _min_200[1] and np.std(ma200[-200:]) / np.mean(ma200[-200:]) < 0.02 # before_second_golden_cross_cond = _min_50[0] < _ma200[-_min_50[1]] and _max_50_1[0] > _ma200[-_max_50_1[1]] and _max_50_1[0] > _ma200[ # -_max_50_1[1]] and _min_50_1[0] < _ma200[-_min_50_1[1]] # if _min_200[0] < _max_200[0] and _max_200[1] > _min_200[1] and np.std(ma200[-200:])/np.mean(ma200[-200:]) < 0.02: # aja = 1 # # if _min_50[0] < _ma200[-_min_50[1]] and _max_50_1[0] > _ma200[-_max_50_1[1]] and _max_50_1[0] > _ma200[-_max_50_1[1]] and _min_50_1[0] < _ma200[-_min_50_1[1]]: # asd = 1 # if HL_ma50_reversal_cond and min_after_max_low_variance and before_second_golden_cross_cond: # asd = 1 # _ma200[:-_max[1] + 1] # first n elements until max element # _max_b_50 = find_local_maximum(_ma50[-_max_50[1]:_min_50[1]], 10) _curr_rsi = get_avg_last_2(r, stop) _curr_ma_50 = get_avg_last(ma50, stop) # _curr_ma_20 = get_avg_last(ma20, stop) # _curr_ma_7 = get_avg_last(ma7, stop) # _curr_ma_7_2 = get_avg_last_2(ma7, stop) # l1 = get_last(ma7, stop) # l2 = get_last_2(ma7, stop) # b = bullishness_2(_opens, _closes, ma100, ma50, ma20, stop) plt.subplot2grid((3, 1), (2, 0)) # plt.plot(ma200[start:stop:1], 'green', lw=1) # plt.plot(ma50[start:stop:1], 'red', lw=1) plt.plot(_ma200, 'black', lw=1) plt.plot(_ma200[-_first_gc[1]:], 'green', lw=1) plt.plot(_ma50, 'red', lw=1) # plt.plot(_ma200[:-_min_200[1] + 1], 'green', lw=1) # plt.hlines(_min_200[0], 0, len(_ma200[:-_min_200[1] + 1]), 'black', lw=1) # plt.hlines(_max_200[0], 0, len(_ma200[:-_max_200[1] + 1]), 'black', lw=1) # plt.hlines(_max_200_1[0], 0, len(_ma200[:-_max_200_1[1] + 1]), 'black', lw=1) # plt.vlines(len(_ma200) - _min_200[1], np.min(_ma200[~np.isnan(_ma200)]), np.max(_ma200[~np.isnan(_ma200)]), 'black', lw=1) # plt.vlines(len(_ma200) - _max_200_1[1], np.min(_ma200[~np.isnan(_ma200)]), np.max(_ma200[~np.isnan(_ma200)]), 'black', # lw=1) # plt.vlines(len(_ma200) - _max_200[1], np.min(_ma200[~np.isnan(_ma200)]), np.max(_ma200[~np.isnan(_ma200)]), 'black', lw=1) # plt.plot(_ma200[:-_max_200[1] + 1], 'yellow', lw=1) # plt.plot(_ma50, 'black', lw=1) # plt.plot(_ma50[:-_min_50[1] + 1], 'green', lw=1) # plt.hlines(_min_50[0], 0, len(_ma50[:-_min_50[1] + 1]), 'black', lw=1) # plt.hlines(_max_50[0], 0, len(_ma50[:-_max_50[1] + 1]), 'black', lw=1) # plt.hlines(_max_50_1[0], 0, len(_ma50[:-_max_50_1[1] + 1]), 'black', lw=1) # plt.vlines(len(_ma50) - _min_50[1], np.min(_ma50[~np.isnan(_ma50)]), np.max(_ma50[~np.isnan(_ma50)]), 'black', lw=1) # plt.vlines(len(_ma50) - _max_50_1[1], np.min(_ma50[~np.isnan(_ma50)]), np.max(_ma50[~np.isnan(_ma50)]), 'black', # lw=1) # plt.vlines(len(_ma50) - _max_50[1], np.min(_ma50[~np.isnan(_ma50)]), np.max(_ma50[~np.isnan(_ma50)]), 'black', lw=1) # plt.plot(_ma50[:-_max_50[1] + 1], 'yellow', lw=1) # plt.plot(_ma50[:-_max_50_1[1] + 1], 'red', lw=1) # plt.plot(ma20[start:stop:1], 'blue ', lw=1) plt.show() # t = get_time_from_binance_tmstmp(_klines[-1][0]) i = 1 # ba = BuyAsset('ZRX', 0.00002520, 0.00002420, 0.00005520, 1) # take_profit(ba) i = 1