def get_ema(): global short_ema global long_ema global cross_up global cross_down global ema_diff short = ti.ema(close_price_historicals, 10) long = ti.ema(close_price_historicals, 20) short_ema = short[-1] long_ema = long[-1] ema_diff = short_ema - long_ema short_cross_up = ti.crossover(short, long)[-1] short_cross_down = ti.crossover(long, short)[-1] if (short_cross_up == 1): cross_up = True else: cross_up = False if (short_cross_down == 1): cross_down == True else: cross_down == False
def on_candle_update(self): ma1 = ti.sma(self.handler.close, period=10) ma2 = ti.sma(self.handler.close, period=20) if ti.crossover(ma1, ma2)[0]: self.handler.buy() elif ti.crossover(ma2, ma1)[0]: self.handler.sell()
def compute(self, data_dict): close = data_dict['close'] f1 = self.boll.get_numpy() return ti.crossover(f1, close)
def start(): while True: # [ # 1499040000000, // Open time # "0.01634790", // Open # "0.80000000", // High # "0.01575800", // Low # "0.01577100", // Close # "148976.11427815", // Volume # 1499644799999, // Close time # "2434.19055334", // Quote asset volume # 308, // Number of trades # "1756.87402397", // Taker buy base asset volume # "28.46694368", // Taker buy quote asset volume # "17928899.62484339" // Ignore # ] try: now = datetime.datetime.now() is_close_position() if (now.minute == 0 and now.second == 0) or (now.minute == 30 and now.second == 10): print(now, 'UPDATE DATA OHLC') ohlc = client.futures_klines(symbol=MARKET, interval=Client.KLINE_INTERVAL_30MINUTE) close = [] for row in ohlc: close.append(float(row[4])) ma1 = ti.sma(np.array(close), period=10) ma2 = ti.sma(np.array(close), period=20) if POSITION['price'] == 0: if ti.crossover(ma1, ma2)[0]: create_position(price=float(row[4]), side=Client.SIDE_BUY, date=now) elif ti.crossover(ma2, ma1)[0]: create_position(price=float(row[4]), side=Client.SIDE_SELL, date=now) print(now, 'GET POSITION ENTRY_PRICE[{}] ROE[{}] AMOUNT[{}] SIDE[{}]'.format(POSITION['price'], POSITION['roe'], POSITION['amount'], POSITION['side'])) time.sleep(1) except: traceback.print_exc()
# ma1 = ti.sma(np.array(CLOSE), period=1) # ma2 = ti.sma(np.array(CLOSE), period=2) # print(ti.crossover(ma1, ma2)) for row in OHLC[::-1]: # print(row['close']) CLOSE.insert(0, row['close']) if len(CLOSE) < 50: continue ma1 = ti.sma(np.array(CLOSE), period=10) ma2 = ti.sma(np.array(CLOSE), period=20) # print(ti.crossover(ma1, ma2)) is_close_position(row) if POSITION['price'] > 0: continue if ti.crossover(ma1, ma2)[0]: POSITION['price'] = row['close'] POSITION['side'] = 'BUY' POSITION['date'] = row['date'] elif ti.crossover(ma2, ma1)[0]: POSITION['price'] = row['close'] POSITION['side'] = 'SELL' POSITION['date'] = row['date'] # print(TRADES) print('MAX_MARTINGALE', MAX_MARTINGALE) print('MAX_AMOUNT', MAX_AMOUNT) print('WINS', WINS) print('LOSSES', LOSSES) # print('TRADES', len(TRADES)) # print('RESULT', len(WINS)*AMOUNT)
'side': 'SELL', 'amount': AMOUNT_NOW }) reset_position() martingale() LOSSES += 1 for row in OHLC[::-1]: CLOSE.insert(0, row['close']) if len(CLOSE) < 50: continue is_close_position(row) if POSITION['price'] > 0: continue macd, macd_signal, macd_histogram = ti.macd(np.array(CLOSE), 12, 26, 9) if ti.crossover(macd, macd_signal)[0]: POSITION['price'] = row['close'] POSITION['side'] = 'BUY' POSITION['date'] = row['date'] elif ti.crossover(macd_signal, macd)[0]: POSITION['price'] = row['close'] POSITION['side'] = 'SELL' POSITION['date'] = row['date'] print(TRADES) print('MAX_MARTINGALE', MAX_MARTINGALE) print('MAX_AMOUNT', MAX_AMOUNT) print('WINS', WINS) print('LOSSES', LOSSES)