繁体   English   中英

Pinescript strategy.exit() 执行顺序

[英]Pinescript strategy.exit() execution order

这是我的退出策略的一些 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函数似乎按照它们编写的顺序执行,这意味着跟踪止损 function(ID 为“Long exit”和“Short exit”)永远无法执行,除非所有达到获利水平。 这显然不是我希望脚本运行的方式。 如何解决这个执行顺序问题?

(我的追踪loss确实有效。我已经使用单个strategy.exit对其进行了测试。退出带有profit参数)

strategy.exit的概念是进入/仓位(从 1% 到 100%)某些部分的“守护者”。 您从“Long”条目中创建了 20、25、33、50、100 % 的五个“监护人”。 如果“多头”入场有 100 张合约,则“监护人”将保护:20、25、33、22、0 份合约。 即最后一位监护人没有任何数量。

您可以尝试将stop=long_stop_price传递给每个“监护人”:

strategy.exit("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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM