Advertisement
Guest User

Untitled

a guest
Apr 10th, 2020
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.11 KB | None | 0 0
  1. def check_for_signal():
  2.  
  3.     global position
  4.     atr_stop_loss = max(0.5,round(ATR(ohlc,120)["ATR"][len(ATR(ohlc,120)["ATR"]) - 1],0))
  5.     atr_stop_loss *= 5
  6.    
  7.     if position == "None" and price <= renko_df["MA"].iloc[-1] + atr_stop_loss and price >= renko_df["MA"].iloc[-1] - atr_stop_loss:
  8.  
  9.         if float(renko_df["high"].iloc[-1]) > float(renko_df["MA"].iloc[-1]) and float(renko_df["low"].iloc[-1]) > float(renko_df["MA"].iloc[-1]):
  10.             order = client.futures_create_order(
  11.                 symbol='BTCUSDT',
  12.                 side=Client.SIDE_BUY,
  13.                 type=Client.ORDER_TYPE_MARKET,
  14.                 quantity=quantity)
  15.            
  16.             print(f"BUY MARKET {quantity}")
  17.  
  18.             order_stop_loss = client.futures_create_order(
  19.                 symbol='BTCUSDT',
  20.                 side=Client.SIDE_SELL,
  21.                 type="STOP_MARKET",
  22.                 quantity=quantity,
  23.                 stopPrice="{:.2f}".format(float(renko_df["MA"].iloc[-1]) - atr_stop_loss)
  24.             )
  25.             stop_loss = "{:.2f}".format(float(renko_df["MA"].iloc[-1]) - atr_stop_loss)
  26.             print(f"STOP LOSS {stop_loss}")
  27.            
  28.             position = "Long"
  29.        
  30.         if float(renko_df["high"].iloc[-1]) < float(renko_df["MA"].iloc[-1]) and float(renko_df["low"].iloc[-1]) < float(renko_df["MA"].iloc[-1]):
  31.             order = client.futures_create_order(
  32.                 symbol='BTCUSDT',
  33.                 side=Client.SIDE_SELL,
  34.                 type=Client.ORDER_TYPE_MARKET,
  35.                 quantity=quantity)
  36.            
  37.             print(f"SELL MARKET {quantity}")
  38.            
  39.             order_stop_loss = client.futures_create_order(
  40.                 symbol='BTCUSDT',
  41.                 side=Client.SIDE_BUY,
  42.                 type="STOP_MARKET",
  43.                 quantity=quantity,
  44.                 stopPrice="{:.2f}".format(float(renko_df["MA"].iloc[-1]) + atr_stop_loss)
  45.             )
  46.             stop_loss = "{:.2f}".format(float(renko_df["MA"].iloc[-1]) + atr_stop_loss)
  47.             print(f"STOP LOSS {stop_loss}")
  48.            
  49.             position = "Short"
  50.        
  51.     if position == "Long" and float(renko_df["high"].iloc[-1]) < float(renko_df["MA"].iloc[-1]) and float(renko_df["low"].iloc[-1]) < float(renko_df["MA"].iloc[-1]):
  52.        
  53.         client.futures_cancel_all_open_orders(symbol="BTCUSDT")
  54.         print("CANCEL ALL ORDERS")
  55.  
  56.         order = client.futures_create_order(
  57.             symbol='BTCUSDT',
  58.             side=Client.SIDE_SELL,
  59.             type=Client.ORDER_TYPE_MARKET,
  60.             quantity=quantity * 2)
  61.        
  62.         print(f"CLOSE LONG {quantity}")
  63.         print(f"SELL MARKET {quantity}")
  64.            
  65.         order_stop_loss = client.futures_create_order(
  66.             symbol='BTCUSDT',
  67.             side=Client.SIDE_BUY,
  68.             type="STOP_MARKET",
  69.             quantity=quantity,
  70.             stopPrice="{:.2f}".format(float(renko_df["MA"].iloc[-1]) + atr_stop_loss)
  71.         )
  72.         stop_loss = "{:.2f}".format(float(renko_df["MA"].iloc[-1]) + atr_stop_loss)
  73.         print(f"STOP LOSS {stop_loss}")
  74.  
  75.         position = "Short"
  76.    
  77.     if position == "Short" and float(renko_df["high"].iloc[-1]) > float(renko_df["MA"].iloc[-1]) and float(renko_df["low"].iloc[-1]) > float(renko_df["MA"].iloc[-1]):
  78.        
  79.         client.futures_cancel_all_open_orders(symbol="BTCUSDT")
  80.  
  81.         print("CANCEL ALL ORDERS")
  82.  
  83.         order = client.futures_create_order(
  84.             symbol='BTCUSDT',
  85.             side=Client.SIDE_BUY,
  86.             type=Client.ORDER_TYPE_MARKET,
  87.             quantity=quantity * 2)
  88.        
  89.         print(f"CLOSE SHORT {quantity}")
  90.         print(f"BUY MARKET {quantity}")
  91.            
  92.         order_stop_loss = client.futures_create_order(
  93.             symbol='BTCUSDT',
  94.             side=Client.SIDE_SELL,
  95.             type="STOP_MARKET",
  96.             quantity=quantity,
  97.             stopPrice="{:.2f}".format(float(renko_df["MA"].iloc[-1]) - atr_stop_loss)
  98.         )
  99.         stop_loss = "{:.2f}".format(float(renko_df["MA"].iloc[-1]) - atr_stop_loss)
  100.         print(f"STOP LOSS {stop_loss}")
  101.  
  102.         position = "Long"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement