繁体   English   中英

Pine Script 中的 Tradingview 策略 position 大小不起作用

[英]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.

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