【问题标题】:How to exit after certain days from `strategy.entry`如何在某些天后从`strategy.entry`退出
【发布时间】:2018-04-14 19:22:50
【问题描述】:

我似乎无法弄清楚从交易进入的特定时间间隔退出交易的语法。任何帮助将不胜感激。

if (crossover(delta, 0))
    strategy.entry("Long", strategy.long, comment="Long")
    strategy.exit("Exit", "Long", when = 15)

上面的代码我想在15天后exit多头头寸。但这似乎不起作用。

【问题讨论】:

    标签: stock pine-script trading


    【解决方案1】:

    试试 barssince

    // Example - Buy when the price closes below 22
    
    myEntry = close  < 22
    
    strategy.entry(id= "sample", long = strategy.long, when= myEntry)
    
    // Close 10 bar periods after the condition that triggered the entry
    
    strategy.close(id = "sample", when = barssince(myEntry) >= 10)
    

    【讨论】:

      【解决方案2】:

      我想出了一个解决方案。我创建了另一个 if 语句,但偏移了 15 天才能触发。我还将交叉设置为一个变量。见代码:

      buy = (crossover(delta, 0))
      
      if (buy)
          strategy.entry("Long", strategy.long, comment="Long")
      if (buy[15])
          strategy.close("Long")
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-07-22
        • 2019-12-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多