Aug-19-2020, 08:29 PM
I am trying to run this script at trality.com which is a trading site for cryptocurrencies. I am looking for a calculation for the angle of the bitcoin slope traded against ethereum. But I am not sure what the script does to calculate the angle. I get very small angles. Can someone identify why the angles are so small. I want an angle based on a time interval of 1 hour or 4 hours. And I want to buy when the angle is above 30 degrees. I dont know if it uses radians or degrees in the script. Thank you.
import numpy as np def initialize(state): state.counter = 0 @schedule(interval="1h", symbol="ETHBTC") def handler(state, data): 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)