update.
This commit is contained in:
parent
db4760100d
commit
7ba3ec9ce6
1
bn.py
1
bn.py
@ -2,7 +2,6 @@ from binance.spot import Spot
|
|||||||
|
|
||||||
client = Spot()
|
client = Spot()
|
||||||
|
|
||||||
|
|
||||||
# Get klines
|
# Get klines
|
||||||
def klines(symbol, interval):
|
def klines(symbol, interval):
|
||||||
lines = client.klines(symbol,interval)
|
lines = client.klines(symbol,interval)
|
||||||
|
|||||||
@ -16,7 +16,8 @@ def check_bullish_crossover(data):
|
|||||||
ema200 = talib.EMA(close_prices, timeperiod=200)
|
ema200 = talib.EMA(close_prices, timeperiod=200)
|
||||||
|
|
||||||
# 判断是否出现多头排列信号
|
# 判断是否出现多头排列信号
|
||||||
if ema7[-1] > ema30[-1] > ema100[-1] > ema200[-1] and ema7[-2] <= ema30[-2] <= ema100[-2] <= ema200[-2]:
|
# if ema7[-1] > ema30[-1] > ema100[-1] > ema200[-1] and ema7[-2] <= ema30[-2] <= ema100[-2] <= ema200[-2]:
|
||||||
|
if ema7[-1] > ema30[-1] > ema100[-1] and ema7[-2] <= ema30[-2] <= ema100[-2]:
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
@ -33,7 +34,9 @@ def check_bearish_crossover(data):
|
|||||||
ema200 = talib.EMA(close_prices, timeperiod=200)
|
ema200 = talib.EMA(close_prices, timeperiod=200)
|
||||||
|
|
||||||
# 判断是否出现空头排列信号
|
# 判断是否出现空头排列信号
|
||||||
if ema7[-1] < ema30[-1] < ema100[-1] < ema200[-1] and ema7[-2] >= ema30[-2] >= ema100[-2] >= ema200[-2]:
|
if ema7[-1] < ema30[-1] < ema100[-1] < ema200[-1] >= ema30[-2] >= ema100[-2]:
|
||||||
|
# if ema7[-1] < ema30[-1] < ema100[-1] < ema200[-1] and ema7[-2] >= ema30[-2] >= ema100[-2] >= ema200[-2]:
|
||||||
|
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|||||||
44
strategy/support_resistance.py
Normal file
44
strategy/support_resistance.py
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
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)
|
||||||
4
strategy_test.py
Normal file
4
strategy_test.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import strategy.support_resistance as sr
|
||||||
|
|
||||||
|
|
||||||
|
sr.strategy_run('BTCUSDT', '1h')
|
||||||
31
test.py
Normal file
31
test.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import bn
|
||||||
|
import pandas as pd
|
||||||
|
import mplfinance as mpf
|
||||||
|
import datetime as dt
|
||||||
|
|
||||||
|
def binanceDataFrame(klines):
|
||||||
|
df = pd.DataFrame(klines.reshape(-1,12),dtype=float, columns = ('Open Time',
|
||||||
|
'Open',
|
||||||
|
'High',
|
||||||
|
'Low',
|
||||||
|
'Close',
|
||||||
|
'Volume',
|
||||||
|
'Close time',
|
||||||
|
'Quote asset volume',
|
||||||
|
'Number of trades',
|
||||||
|
'Taker buy base asset volume',
|
||||||
|
'Taker buy quote asset volume',
|
||||||
|
'Ignore'))
|
||||||
|
|
||||||
|
df['Open Time'] = pd.to_datetime(df['Open Time'], unit='ms')
|
||||||
|
|
||||||
|
|
||||||
|
return df
|
||||||
|
|
||||||
|
|
||||||
|
klines = bn.klines('BTCUSDT', '1h')
|
||||||
|
|
||||||
|
df = pd.DataFrame(klines,dtype=float)
|
||||||
|
df.columns = ['Open time', 'Open', 'High', 'Low', 'Close', 'Volume', 'ctime', 'Quote asset volume', 'Number of trades', 'Taker buy base asset volume', 'Taker buy quote asset volume', 'Can be ignored']
|
||||||
|
df.index = [dt.datetime.fromtimestamp(x/1000.0) for x in df.ctime]
|
||||||
|
mpf.plot(df, type='line')
|
||||||
Loading…
Reference in New Issue
Block a user