在此TradingView脚本中找到2个值的麻烦

发布于 2025-01-29 20:26:48 字数 1358 浏览 1 评论 0原文

我试图将两行(红色和蓝色)的交叉添加在指示器中,作为我的肠道和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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

在你怀里撒娇 2025-02-05 20:26:48

蓝线是val,红线为sma(val,signalperiod)

一旦知道了这一点,我们就可以使用Crossover()crossunder()函数来检查它们是否相互交叉。

例如:

val_sma = sma(val,SignalPeriod)

enterlong = crossover(val, val_sma)
entershort = crossunder(val, val_sma)

The blue line is val and the red line is sma(val,SignalPeriod).

Once we know this, we can use the crossover() and crossunder() functions to check if they crossed each other.

For example:

val_sma = sma(val,SignalPeriod)

enterlong = crossover(val, val_sma)
entershort = crossunder(val, val_sma)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文