在此TradingView脚本中找到2个值的麻烦
我试图将两行(红色和蓝色)的交叉添加在指示器中,作为我的肠道和Entershort交易条件的一部分,但似乎无法弄清楚这两条线。我想在A< or>并尝试了enterlong =(val> signalperiod),(val> ma),但似乎无法弄清楚
length = input(20, title="BB Length")
mult = input(2.0,title="BB MultFactor")
lengthKC=input(20, title="KC Length")
multKC = input(1.5, title="KC MultFactor")
SignalPeriod=input(5, title="Signal Length")
useTrueRange = input(true, title="Use TrueRange (KC)", type=bool)
// Calculate BB
source = close
basis = sma(source, length)
dev = multKC * stdev(source, length)
upperBB = basis + dev
lowerBB = basis - dev
// Calculate KC
ma = sma(source, lengthKC)
range = useTrueRange ? tr : (high - low)
rangema = sma(range, lengthKC)
upperKC = ma + rangema * multKC
lowerKC = ma - rangema * multKC
sqzOn = (lowerBB > lowerKC) and (upperBB < upperKC)
sqzOff = (lowerBB < lowerKC) and (upperBB > upperKC)
noSqz = (sqzOn == false) and (sqzOff == false)
val = linreg(source - avg(avg(highest(high, lengthKC), lowest(low,
lengthKC)),sma(close,lengthKC)),
lengthKC,0)
bcolor = iff( val > 0,
iff( val > nz(val[1]), lime, green),
iff( val < nz(val[1]), red, maroon))
scolor = noSqz ? blue : sqzOn ? black : gray
plot(val, color=blue, linewidth=2)
plot(0, color=scolor, style=cross, linewidth=2)
plot(sma(val,SignalPeriod), color=red, linewidth=2)
I'm trying to add the crossing of the two lines (red and blue) in the indicator as part of my enterlong and entershort trading conditions but cant seem to figure out the 2 lines. I'd like to have them at a < or > and have tried enterlong = (val > signalperiod) , (val > ma) but can't seem to figure it out
length = input(20, title="BB Length")
mult = input(2.0,title="BB MultFactor")
lengthKC=input(20, title="KC Length")
multKC = input(1.5, title="KC MultFactor")
SignalPeriod=input(5, title="Signal Length")
useTrueRange = input(true, title="Use TrueRange (KC)", type=bool)
// Calculate BB
source = close
basis = sma(source, length)
dev = multKC * stdev(source, length)
upperBB = basis + dev
lowerBB = basis - dev
// Calculate KC
ma = sma(source, lengthKC)
range = useTrueRange ? tr : (high - low)
rangema = sma(range, lengthKC)
upperKC = ma + rangema * multKC
lowerKC = ma - rangema * multKC
sqzOn = (lowerBB > lowerKC) and (upperBB < upperKC)
sqzOff = (lowerBB < lowerKC) and (upperBB > upperKC)
noSqz = (sqzOn == false) and (sqzOff == false)
val = linreg(source - avg(avg(highest(high, lengthKC), lowest(low,
lengthKC)),sma(close,lengthKC)),
lengthKC,0)
bcolor = iff( val > 0,
iff( val > nz(val[1]), lime, green),
iff( val < nz(val[1]), red, maroon))
scolor = noSqz ? blue : sqzOn ? black : gray
plot(val, color=blue, linewidth=2)
plot(0, color=scolor, style=cross, linewidth=2)
plot(sma(val,SignalPeriod), color=red, linewidth=2)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
蓝线是
val
,红线为sma(val,signalperiod)
。一旦知道了这一点,我们就可以使用
Crossover()
和crossunder()
函数来检查它们是否相互交叉。例如:
The blue line is
val
and the red line issma(val,SignalPeriod)
.Once we know this, we can use the
crossover()
andcrossunder()
functions to check if they crossed each other.For example: