trading-quant/strategy/support_resistance.py
2023-06-11 08:47:53 +08:00

45 lines
1.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import talib
import numpy as np
import bn
import tg
import settings
# 获取K线价格数据
def get_prices(data):
# 提取最高价、最低价和收盘价
high_prices = [float(entry[2]) for entry in data]
low_prices = [float(entry[3]) for entry in data]
close_prices = [float(entry[4]) for entry in data]
return np.array(high_prices), np.array(low_prices), np.array(close_prices)
# 计算支撑位和压力位
def calculate_support_resistance(data):
# 获取价格数据
high_prices, low_prices, close_prices = get_prices(data)
# 计算平均真实范围ATR
atr = talib.ATR(high_prices, low_prices, close_prices, timeperiod=14)
# 计算支撑位和压力位
support = talib.SMA(close_prices - 1.618 * atr, timeperiod=20)
resistance = talib.SMA(close_prices + 1.618 * atr, timeperiod=20)
return support, resistance
def strategy_run(symbol, interval):
# 获取kline数据
data = bn.klines(symbol, interval)
support_levels, resistance_levels = calculate_support_resistance(data)
# 打印支撑位和压力位
print("支撑位:", support_levels)
print("压力位:", resistance_levels)
# if check_bullish_crossover(data):
# print('多头排列信号出现!')
# text = f'${symbol} - {interval}\r\n\r\n出现【多头排列】信号'
# tg.send_message(settings.chat_id, text)