Sep-02-2020, 01:39 PM
(This post was last modified: Sep-02-2020, 01:39 PM by fisher_garry.)
I have made it running:
import numpy as np def initialize(state): state.counter = 0 state.lastsignals = [] @schedule(interval="1d", symbol="BNBUSDT") def handler(state, data): angle = 0 signal = data.sma(2).last 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 if state.counter < 2: state.counter += 1 state.lastsignals.append(signal) else: state.lastsignals.append(signal) if state.counter == 2: plot("signal", state.lastsignals[-1], "BNBUSDT") # calculating the slope of last 4 candles slope = (state.lastsignals[-1] - state.lastsignals[-2]) / 0.125 angle = np.rad2deg(np.arctan(slope)) print("slope: ", slope) print("angle: ", angle) plot("angle of signal", angle, "BNBUSDT") if angle > 10: 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 < -5 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)I am trading in BNB on a one day interval. Feel free to test it out on trality.com. They are in beta so it is free. They also have trading testing for the past year or more for coins on binance. Cheers