【问题标题】:Strategy Tester Exit Always Re-Enters策略测试员退出总是重新进入
【发布时间】:2019-03-23 13:48:11
【问题描述】:

我在策略测试器中有以下代码,当它在 300 止盈期间自动退出时,它总是再次进入。退出触发时如何阻止它重新进入

isShort=false
isLong=false

if (goLong)
    if(isShort==false)
        strategy.entry("Long", strategy.long,100000,when=isShort?false:true)
        strategy.exit("b1","Long",profit=300)
        isShort:=true
        isLong:=false

else
    if(isLong==false)
        strategy.entry("Short", strategy.short,100000,when=isLong?false:true)
        strategy.exit("b2","Short",profit=300)
        isShort:=false
        isLong:=true

【问题讨论】:

    标签: pine-script


    【解决方案1】:

    当您想要访问变量的先前值时,您需要使用 历史引用运算符 []

    您可以认为,对于 pine-script 中的每个新栏,您的代码都会重新执行。因此,发生的情况是,您每次都在代码的开头将isShortisLong 设置为false。因此,如果您稍后在代码中更改它们并不重要。对于下一个小节,您的代码将重新执行,isShortisLong 在开头得到值 false

    您需要做的是,只需在声明后将它们的旧值重新分配给这些变量。这样,您首先声明变量,然后将它们的最后一个值从 previos bar/execution 分配给它们。

    isShort=false
    isLong=false
    
    isShort := nz(isShort[1], false)
    isLong := nz(isLong[1], false)
    

    【讨论】:

      猜你喜欢
      • 2023-01-08
      • 2015-11-01
      • 2016-01-23
      • 1970-01-01
      • 1970-01-01
      • 2022-12-18
      • 2010-11-09
      • 1970-01-01
      • 2020-09-26
      相关资源
      最近更新 更多