问题描述
import numpy as np
def初始化(状态):
state.counter = 0
@schedule(interval =“ 1h”,symbol =“ ETHBTC”) def处理程序(状态,数据):
angle = 0
macd_ind = data.macd(12,26,9)
if macd_ind is None:
return
signal = macd_ind['macd_signal']
has_position = has_open_position(data.symbol,truncated=True)
balance_base = float(query_balance_free(data.base))
balance_quoted = float(query_balance_free(data.quoted))
buy_amount = balance_quoted * 0.80 / data.close_last
plot("signal",signal[-1],"ETHBTC")
if state.counter < 4:
state.counter += 1
else:
state.counter = 0
if state.counter == 4:
lastsignals = signal[-4:]
# calculating the slope of last 4 candles
slope = (lastsignals[-1] - lastsignals[0]) / 3
angle = np.rad2deg(np.arctan(slope))
print("slope: ",slope)
print("angle: ",angle)
plot("angle of signal",angle,"ETHBTC")
if angle > 0.26: # 15 degrees
print("-------")
print("Checking for buying possibility of {}".format(data.symbol))
print("buy amount:",buy_amount)
print("buy price:",data.close_last)
create_order(symbol=data.symbol,amount = buy_amount)
elif angle < -10 and has_position:
print("-------")
print("Checking for selling possibility of {}".format(data.symbol))
print("sell amount:",balance_base)
print("sell price:",data.close_last)
close_position(data.symbol)
上面是我一直在努力的脚本。它使用python并在trality.com网站上使用,该网站支持在python中创建自己的交易机器人以用于币安。从现在开始运行。但是我希望在可以定义为4小时的时间间隔内改变比特币价值的角度。问题在于它似乎在脚本中将值信号定义为macd。而且我认为,为了创建角度,我需要在两个点上获取比特币值,然后计算斜率以获得角度。
在脚本的下面,似乎正在解释它计算斜率的方法。但是我不确定这是否正确。简而言之,我认为信号值应该在多一点处获得比特币值,然后此信息将用于创建斜率。有人可以更改脚本来做到这一点吗?
如果您认为脚本看起来有点不整洁。我创建的这个未答复的论坛话题中提供了相同的脚本:
https://python-forum.io/Thread-problem-about-slope-in-python-script-for-bitcoin-trading
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)