Jump to content

fresh22

Medlemmer
  • Content Count

    1
  • Joined

  • Last visited

Posts posted by fresh22


  1.  

         




     

    def initialize(state):
    
        state.counter = 0
    
        
    
     
    
    @schedule(interval="1h",symbol="BTCUSDT")
    
    
    
    
    
    
    
    if state.counter<4:
    
       state.counter += 1
    
    Else:
    
    state.counter = 0
    
     
    
     if counter == 4: (every four hours)
    
    
    
    
    
    macd = data.macd(12,26,9)
    
    signalLine = macd[‘macd_signal’]
    
    
    
    
    - Check if bot has position
    
     
    
    has_position = has_open_position(data.symbol, truncated=True)
    
    
    
    
    
    
    
    
    
    
    import numpy as np
    
    
    
    
    
    
    
    
    
    
    
    def initialize(state):
    
     
    
    state.counter = 0
    
    
    
    
    
    @schedule(interval="1h", symbol="BTCTUSD")
    
     
    
    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],"BTCTUSD")
    
    
    
    
    
    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,"BTCTUSD")
    
    
    
    
    
    if angle > 30 and balance_base<buy_amount:
    
     
    
    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 < -30 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)

     

    When I run this script in the python program I get this error message:

     

    > Engine error:   File "bot.py", line 20.

    > Engine error:     if state.counter<4:.

    > Engine error:      ^.

    > Engine error: SyntaxError: invalid syntax.

    >   File "bot.py", line 20

        if state.counter<4:

         ^

    SyntaxError: invalid syntax

     

    This is a picture of the error:

    image.png.105947c3354b4a22daca34bb573547df.png

×
×
  • Create New...