簡體   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