![](/img/trans.png)
[英]Tradingview Pine script `strategy.exit` and `strategy.close` don't respect `from_entry` value
[英]Tradingview in Pine Script the strategy position size don't work
我有一个简单的策略,我想打开或 1 长 position 或 1 短 position。 例如,当已经打开一个长 position 时,我不想打开一个短 position。
所以,我的代码是:
strategy.entry("Long", strategy.long, stop=livelloIngressoLong, when = strategy.position_size == 0)
和
strategy.entry("Short", strategy.short, stop=livelloIngressoShort, when = strategy.position_size == 0)
但他们不工作。 你可以看到截图添加。 开空头时开多头,但如果空头开仓 strategy.position_size 不为 0? 那么为什么要开长呢? 我不敢相信!
我还尝试了一些变化,例如:
if strategy.position_size == 0
strategy.entry("Long", strategy.long, stop=livelloIngressoLong)
或者
longCondition = Strategy.position_size == 0
if longCondition
strategy.entry("Long", strategy.long, stop=livelloIngressoLong)```
[1]: https://i.stack.imgur.com/HFkex.png
when
参数指定何时生成入场单。 但是当达到止损价格条件时,可以稍后执行止损订单。 您的情况的解决方法可以是:
longCondition = Strategy.position_size == 0
if longCondition
strategy.entry("Long", strategy.long, stop=livelloIngressoLong)
else
strategy.cancel("Long")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.