Python Forum
problem about slope in python script for bitcoin trading
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
problem about slope in python script for bitcoin trading
#1
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)
Reply


Messages In This Thread
problem about slope in python script for bitcoin trading - by fisher_garry - Aug-19-2020, 08:29 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Star Pairs Trading Simulation Kiitoos 0 255 Feb-19-2024, 08:27 PM
Last Post: Kiitoos
  Is there a *.bat DOS batch script to *.py Python Script converter? pstein 3 3,384 Jun-29-2023, 11:57 AM
Last Post: gologica
  how to manage crypto trading flooding data from exchange servers Mikeardy 0 1,257 Dec-26-2021, 08:31 PM
Last Post: Mikeardy
  Script stop work after 3 actioins - PLEASE WHERE IS THE PROBLEM? rondon442 0 1,581 Sep-27-2021, 05:40 PM
Last Post: rondon442
  Problem executing a script on a remote host tester_V 3 2,510 Sep-26-2021, 04:25 AM
Last Post: tester_V
  cbot ctrader automate trading hl29951 1 1,675 Jul-25-2021, 08:14 PM
Last Post: Larz60+
  problem with sphinx and file directory in script kiyoshi7 0 2,309 Mar-11-2021, 03:52 PM
Last Post: kiyoshi7
  Code should download and output trading data tayy 2 2,679 Mar-04-2021, 04:07 AM
Last Post: tayy
  How to kill a bash script running as root from a python script? jc_lafleur 4 5,977 Jun-26-2020, 10:50 PM
Last Post: jc_lafleur
  slope intercept form Dasiey12 6 4,016 Jun-14-2020, 06:34 PM
Last Post: SheeppOSU

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020