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
#2
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
Reply


Messages In This Thread
RE: problem about slope in python script for bitcoin trading - by fisher_garry - Sep-02-2020, 01:39 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Star Pairs Trading Simulation Kiitoos 0 262 Feb-19-2024, 08:27 PM
Last Post: Kiitoos
  Is there a *.bat DOS batch script to *.py Python Script converter? pstein 3 3,419 Jun-29-2023, 11:57 AM
Last Post: gologica
  how to manage crypto trading flooding data from exchange servers Mikeardy 0 1,259 Dec-26-2021, 08:31 PM
Last Post: Mikeardy
  Script stop work after 3 actioins - PLEASE WHERE IS THE PROBLEM? rondon442 0 1,587 Sep-27-2021, 05:40 PM
Last Post: rondon442
  Problem executing a script on a remote host tester_V 3 2,524 Sep-26-2021, 04:25 AM
Last Post: tester_V
  cbot ctrader automate trading hl29951 1 1,683 Jul-25-2021, 08:14 PM
Last Post: Larz60+
  problem with sphinx and file directory in script kiyoshi7 0 2,315 Mar-11-2021, 03:52 PM
Last Post: kiyoshi7
  Code should download and output trading data tayy 2 2,685 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,992 Jun-26-2020, 10:50 PM
Last Post: jc_lafleur
  slope intercept form Dasiey12 6 4,030 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