Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def check_for_signal():
- global position
- atr_stop_loss = max(0.5,round(ATR(ohlc,120)["ATR"][len(ATR(ohlc,120)["ATR"]) - 1],0))
- atr_stop_loss *= 5
- if position == "None" and price <= renko_df["MA"].iloc[-1] + atr_stop_loss and price >= renko_df["MA"].iloc[-1] - atr_stop_loss:
- 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]):
- order = client.futures_create_order(
- symbol='BTCUSDT',
- side=Client.SIDE_BUY,
- type=Client.ORDER_TYPE_MARKET,
- quantity=quantity)
- print(f"BUY MARKET {quantity}")
- order_stop_loss = client.futures_create_order(
- symbol='BTCUSDT',
- side=Client.SIDE_SELL,
- type="STOP_MARKET",
- quantity=quantity,
- stopPrice="{:.2f}".format(float(renko_df["MA"].iloc[-1]) - atr_stop_loss)
- )
- stop_loss = "{:.2f}".format(float(renko_df["MA"].iloc[-1]) - atr_stop_loss)
- print(f"STOP LOSS {stop_loss}")
- position = "Long"
- 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]):
- order = client.futures_create_order(
- symbol='BTCUSDT',
- side=Client.SIDE_SELL,
- type=Client.ORDER_TYPE_MARKET,
- quantity=quantity)
- print(f"SELL MARKET {quantity}")
- order_stop_loss = client.futures_create_order(
- symbol='BTCUSDT',
- side=Client.SIDE_BUY,
- type="STOP_MARKET",
- quantity=quantity,
- stopPrice="{:.2f}".format(float(renko_df["MA"].iloc[-1]) + atr_stop_loss)
- )
- stop_loss = "{:.2f}".format(float(renko_df["MA"].iloc[-1]) + atr_stop_loss)
- print(f"STOP LOSS {stop_loss}")
- position = "Short"
- 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]):
- client.futures_cancel_all_open_orders(symbol="BTCUSDT")
- print("CANCEL ALL ORDERS")
- order = client.futures_create_order(
- symbol='BTCUSDT',
- side=Client.SIDE_SELL,
- type=Client.ORDER_TYPE_MARKET,
- quantity=quantity * 2)
- print(f"CLOSE LONG {quantity}")
- print(f"SELL MARKET {quantity}")
- order_stop_loss = client.futures_create_order(
- symbol='BTCUSDT',
- side=Client.SIDE_BUY,
- type="STOP_MARKET",
- quantity=quantity,
- stopPrice="{:.2f}".format(float(renko_df["MA"].iloc[-1]) + atr_stop_loss)
- )
- stop_loss = "{:.2f}".format(float(renko_df["MA"].iloc[-1]) + atr_stop_loss)
- print(f"STOP LOSS {stop_loss}")
- position = "Short"
- 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]):
- client.futures_cancel_all_open_orders(symbol="BTCUSDT")
- print("CANCEL ALL ORDERS")
- order = client.futures_create_order(
- symbol='BTCUSDT',
- side=Client.SIDE_BUY,
- type=Client.ORDER_TYPE_MARKET,
- quantity=quantity * 2)
- print(f"CLOSE SHORT {quantity}")
- print(f"BUY MARKET {quantity}")
- order_stop_loss = client.futures_create_order(
- symbol='BTCUSDT',
- side=Client.SIDE_SELL,
- type="STOP_MARKET",
- quantity=quantity,
- stopPrice="{:.2f}".format(float(renko_df["MA"].iloc[-1]) - atr_stop_loss)
- )
- stop_loss = "{:.2f}".format(float(renko_df["MA"].iloc[-1]) - atr_stop_loss)
- print(f"STOP LOSS {stop_loss}")
- position = "Long"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement