繁体   English   中英

多个停止/退出订单 - Pinescript 策略

[英]Multiple Stop/exit Orders - Pinescript Strategy

我对两种不同类型的交易平仓有疑问。 例如,当多头 position 生效时,我希望有两种不同的方式退出交易:

  1. 在启动 position 的前一根蜡烛的低点设置固定止损
  2. 利用 boolean 条件在满足时退出交易

似乎当我尝试这样做时,只有一个出口被使用,另一个被丢弃。 由于 boolean 条件主要用于止盈,将其用作止盈是否更有意义,还是有办法同时使用两者?

下面是我正在使用的代码。

// long entry
if (flaglong)
    strategy.entry("Long", strategy.long, qty=2)
    strategy.exit("Long", strategy.short, stop=low[1]-1.5)
// long exit 
if (flagshort1)
    strategy.close("Long", qty=2)

您可以同时使用两者。

您的代码不应编译,因为您使用的strategy.exit() function 错误。 您正在将strategy.short传递给它的from_entry参数,这应该会引发编译器错误。

strategy.exit() function 的第一个参数是id ,第二个参数是from_entry

像下面这样调用它:

if (longCondition)
    strategy.entry("Long", strategy.long)
    strategy.exit("Long Exit", "Long", stop=low[1]-1.5)

暂无
暂无

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

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