【问题标题】:Strategy Tester: Stochastic long and short signals are impacting each other策略测试器:随机多头和空头信号相互影响
【发布时间】:2020-11-09 07:49:35
【问题描述】:

我正在尝试为随机进入/退出建立一个简单的策略。 我几乎从内置指标中复制粘贴了随机公式。 我遇到的问题是长短布尔信号似乎有一些问题。

虽然使用“goshort”布尔值的 k >= 75 交叉对我来说非常好,但当我尝试使用“golong”布尔值评估 k

我在下面的代码中将 'golong' 布尔值保留为与 k

//@version=4
strategy("Stochastic Slow Strategy", overlay=true)
periodK = input(8, title="K", minval=1)
periodD = input(3, title="D", minval=1)
smoothK = input(3, title="Smooth", minval=1)
k = sma(stoch(close, high, low, periodK), smoothK)
d = sma(k, periodD)
OverSold = 20
OverBought = 80
co = k >= d and k[1] <= d[1] ? true : false
cu = k <= d and k[1] >= d[1] ? true : false

golong=co and k <= 75? true: false  // <--This is the line where I have a problem
goshort=cu and k >= 75? true: false

strategy.entry("Sell",  strategy.short, comment="Sell", when=goshort==true)

strategy.entry("Buy", strategy.long, comment="Buy", when=golong==true)

【问题讨论】:

    标签: pine-script stochastic


    【解决方案1】:

    我建议用plots调试这个问题:

    //@version=4
    strategy("Stochastic Slow Strategy", overlay=true)
    periodK = input(8, title="K", minval=1)
    periodD = input(3, title="D", minval=1)
    smoothK = input(3, title="Smooth", minval=1)
    k = sma(stoch(close, high, low, periodK), smoothK)
    d = sma(k, periodD)
    OverSold = 20
    OverBought = 80
    co = k >= d and k[1] <= d[1] ? true : false
    cu = k <= d and k[1] >= d[1] ? true : false
    
    golong=co and k <= 75? true: false  // <--This is the line where I have a problem
    goshort=cu and k >= 75? true: false
    
    strategy.entry("Sell",  strategy.short, comment="Sell", when=goshort==true)
    
    strategy.entry("Buy", strategy.long, comment="Buy", when=golong==true)
    
    plot(golong ? 1 : 0)
    plot(goshort ? 1 : 0)
    plot(co)
    plot(cu)
    plot(k)
    

    我想问题出在k == d and k[1] == d[1] 为真的栏上

    【讨论】:

      【解决方案2】:

      感谢安德烈 D, 我使用您提供的绘图命令来分析数据。

      此外,经过一番研究,我在策略条目之前添加了这两行,现在它工作正常。我想,我应该在生成下一次买入之前关闭现有的买入或卖出信号。

      strategy.close("Buy", when=goshort==true or golong==true)
      strategy.close("Sell", when=golong==true or goshort==true)
      

      我想这是初学者的错误。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-08-22
        • 2012-01-04
        • 1970-01-01
        • 2022-12-18
        • 1970-01-01
        • 1970-01-01
        • 2012-01-09
        相关资源
        最近更新 更多