【发布时间】: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