diff --git a/main.py b/main.py index e1aed86..c8a8f9b 100644 --- a/main.py +++ b/main.py @@ -26,6 +26,9 @@ schedule.every().hour.at(":30").do(macd_boll.run_crypto, interval = '15m') schedule.every().hour.at(":45").do(macd_boll.run_crypto, interval = '15m') schedule.every().hour.at(":00").do(macd_boll.run_crypto, interval = '1h') +times = ["00:00", "04:00", "08:00", "12:00", "16:00", "20:00"] +for t in times: + schedule.every().day.at(t).do(macd_boll.run_crypto, interval = '4h') version = 'V1.13' print(f'Running... {version}') diff --git a/monitors/macd_boll.py b/monitors/macd_boll.py index e7965f1..f7e9358 100644 --- a/monitors/macd_boll.py +++ b/monitors/macd_boll.py @@ -31,30 +31,26 @@ def stratergy_run(symbol, interval, df, debug): # 计算布林带 upperband, middleband, lowerband = talib.BBANDS(df['close'], timeperiod=bollinger_length, nbdevup=bollinger_mult, nbdevdn=bollinger_mult, matype=0) - # MACD 上穿和下穿 0 轴的逻辑 - macd_bullish_cross = (macd.shift(1) <= 0) & (macd > 0) # 上穿0轴 - macd_bearish_cross = (macd.shift(1) >= 0) & (macd < 0) # 下穿0轴 - # 生成交易信号 - long_condition = macd_bullish_cross & (df['high'] < upperband) - short_condition = macd_bearish_cross & (df['low'] > lowerband) + long_condition = (macd.shift(1) <= 0) & (macd > 0) & (df['high'] < upperband) + short_condition = (macd.shift(1) >= 0) & (macd < 0) & (df['low'] > lowerband) - # 将信号添加到 DataFrame - df['Long_Signal'] = long_condition - df['Short_Signal'] = short_condition - latest = df.iloc[-1] + df['Long_Signal'] = np.where(long_condition, True, False) + df['Short_Signal'] = np.where(short_condition,True, False) + + latest = df.iloc[-2] direction = "" if latest['Short_Signal'] == True: direction = '空' if latest['Long_Signal'] == True: direction = '多' - print(df) + print(latest) print(f"【{symbol} - {interval}】 is checked!") if direction != "": - message = f"策略:【MACD+BOLL策略】\r\n" + message = f"策略:【MACD+BOLL价格策略】\r\n" message += f"品种: {symbol}\r\n" message += f"周期: {interval}\r\n" message += f"信号: 【{direction}】\r\n" diff --git a/test.py b/test.py index 1a33b2b..62b73d8 100644 --- a/test.py +++ b/test.py @@ -8,7 +8,7 @@ from monitors import vegas_cross from datasource import crypto from monitors import macd_boll -macd_boll.run_crypto('1h', debug=True) +macd_boll.run_crypto('15m', debug=True) # print(crypto._get_top_coins_by_market_cap(20))