[英]Trailing stop loss logic not working in function
我实际上是在尝试创建一个追踪止损程序......如果价格上涨并且追踪止损 (TSL) 是价格的 99%,那么将当前的 TSL 设为该价格。 因此,如果价格上涨,TSL 也会随之上涨,但如果价格下跌,则保持 TSL 不变。 所以 TSL 永远不会下降。
我让它在 for 循环中工作正常......但是当我将它移动到一个函数以适应我的程序的其余部分时它不起作用......
# Coin Pair info
crypto = "ADA"
bank = "BUSD"
coin = str(crypto) + str(bank)
#Trailing Stop Loss %
tsl_percent = 0.15
tsl_percent = 1-(tsl_percent/100)
tsl_price = 0
current_price = 0
current_tsl = 0
def strategy ():
global tsl_price
latest_price = client.get_symbol_ticker(symbol=coin)
current_price = latest_price['price']
current_price = float(current_price)
print("")
print("Current price is ", current_price)
print("")
if float(current_price) > float(tsl_price) :
tsl_price = float(tsl_percent) * float(current_price)
print("")
print("NEW TSL Price is - ", tsl_price)
else:
tsl_price = tsl_price
if float(current_price) < float(tsl_price) :
tsl_price = tsl_price
print("")
print("SELL ", tsl_price)
sell_crtpto()
我觉得我做错了什么,但无法解决!
任何帮助,将不胜感激!
干杯
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.