以下是我的退出策略的一些pinescript代码:
// Strategy exit
// Long Exits
strategy.exit("Long TP1", "Long", profit=close*0.02/syminfo.mintick, qty_percent=20)
strategy.exit("Long TP2", "Long", profit=close*0.04/syminfo.mintick, qty_percent=25)
strategy.exit("Long TP3", "Long", profit=close*0.06/syminfo.mintick, qty_percent=33)
strategy.exit("Long TP4", "Long", profit=close*0.08/syminfo.mintick, qty_percent=50)
strategy.exit("Long exit", "Long", stop=long_stop_price, qty_percent=100)
// Short Exits
strategy.exit("Short TP1", "Short", profit=close*0.02/syminfo.mintick, qty_percent=20)
strategy.exit("Short TP2", "Short", profit=close*0.04/syminfo.mintick, qty_percent=25)
strategy.exit("Short TP3", "Short", profit=close*0.06/syminfo.mintick, qty_percent=33)
strategy.exit("Short TP4", "Short", profit=close*0.08/syminfo.mintick, qty_percent=50)
strategy.exit("Short exit", "Short", stop=short_stop_price, qty_percent=100)
目标是在多个获利水平(2%、4%、6%、8% )退出,然后让交易继续进行,直到达到拖累止损。我想要在每一个获利水平后面都有一个跟踪止损。我的问题是,strategy.exit
函数似乎是按照编写的顺序执行的,这意味着除非达到所有获利水平,否则尾随的止损函数( ID为"Long exit“和"Short exit")永远不能执行。这显然不是我希望脚本运行的方式。我如何解决这个执行顺序问题?
(我的跟踪止损确实起作用了。我已经使用带有profit
和loss
参数的单个strategy.exit
对其进行了测试)
发布于 2021-09-30 12:09:07
strategy.exit
的概念是入口/位置的某些部分的“守护者”(从1%到100%)。您已经创建了5个“守护者”,其中20 %、25 %、33 %、50 %、100 %来自"Long“条目。如果“长”条目有100个合同,那么“守护者”将保护: 20,25,33,22,0个合同。也就是说,对于最后一个监护人,没有任何数量。
您可以尝试将stop=long_stop_price
传递给每个“监护人”:
("Long TP1", "Long", profit=close*0.02/syminfo.mintick, stop=long_stop_price, qty_percent=20)
strategy.exit("Long TP2", "Long", profit=close*0.04/syminfo.mintick, stop=long_stop_price, qty_percent=25)
strategy.exit("Long TP3", "Long", profit=close*0.06/syminfo.mintick, stop=long_stop_price, qty_percent=33)
strategy.exit("Long TP4", "Long", profit=close*0.08/syminfo.mintick, stop=long_stop_price, qty_percent=50)
https://stackoverflow.com/questions/69390549
复制相似问题