【问题标题】:ta.crossover does not work as expected in pine scriptta.crossover 在 pine 脚本中无法按预期工作
【发布时间】:2021-12-20 13:00:58
【问题描述】:

我有以下脚本

//@version=5
strategy("Bollinger Bands Strategy", overlay=true)
// BB
source = close
length = input.int(20, minval=1)
mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev")
basis = ta.sma(source, length)
dev = mult * ta.stdev(source, length)
upper = basis + dev
lower = basis - dev

// Stoch
periodK = input.int(14, title="%K Length", minval=1)
periodD = input.int(3, title="%D Smoothing", minval=1)
smoothK = input.int(1, title="%K Smoothing", minval=1)
k = ta.sma(ta.stoch(close, high, low, periodK), smoothK)
d = ta.sma(k, periodD)
lcb = input.int(20, title="Long border cross", minval=1) // long condition bollinger
scb = input.int(80, title="Short border cross", minval=1) // short condition bollinger


long_condition = (k[2] < k[1]) and (k[1] < k) and ((k[2] + k[1] + k) / 3) < 20
plotchar(long_condition, "long?", "", location = location.top)
short_condition = (k[2] > k[1]) and (k[1] > k)  and ((k[2] + k[1] + k) / 3) > 80
plotchar(short_condition, "short?", "", location = location.top)
plotchar(source, "source", "", location = location.top)
plotchar(lower, "lower", "", location = location.top)
my_crossunder = (source[1] > upper[1]) and (source < upper) 
plotchar(my_crossunder, "my_crossunder", "", location = location.top)

if (my_crossunder)
    strategy.entry("BBS", strategy.short, stop=upper, oca_name="BollingerBands", oca_type=strategy.oca.cancel, comment="BBS")
else
    strategy.cancel(id="BBS")

由于某种原因,它没有进入我的 if 条件,而 plotchar(my_crossunder, "my_crossunder", "", location = location.top) 表示该变量为真

这里截图,要输入位置,但是不输入,条件为真,为什么?

【问题讨论】:

    标签: algorithm pine-script trading


    【解决方案1】:

    解决了,strategy.entry() 不能多开,当前策略下只能开一个仓位。所以这意味着我之前的订单是用相同的策略打开的。 More info here。所以如果你想下订单,你应该使用strategy.order()

    【讨论】:

      猜你喜欢
      • 2013-09-30
      • 1970-01-01
      • 1970-01-01
      • 2021-11-08
      • 1970-01-01
      • 2013-11-25
      • 2015-06-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多