1
This commit is contained in:
parent
9e8bb4387c
commit
2e1f709fd0
3
main.py
3
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}')
|
||||
|
||||
@ -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"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user