将linreg V1函数转换为V5(Tradingview – Pine Script)

huangapple go评论44阅读模式
英文:

Converting a linreg V1 Function to V5 (Tradingview - Pine Script)

问题

我尝试将pine v1 linreg函数转换为v3(然后自动转换为V5),但一直出现以下错误:

输入处的语法错误 'end of line without line continuation'

这是V1的代码:

val = linreg(source  -  avg(avg(highest(high, lengthKC), lowest(low, lengthKC)),sma(close,lengthKC)), 
            lengthKC,0)

所以我在pine脚本语言参考中查找了一下,函数应该是这样的:

linreg(source, length, offset) → series

如果我没弄错的话,source应该是这样的:

source - avg(avg(highest(high, lengthKC), lowest(low, lengthKC)),

长度:

sma(close,lengthKC)),

和偏移:

lengthKC,0)

所以我在V3中写成了这样:

val = linreg((source  -  avg(highest(high, lengthKC)), avg(lowest(low, lengthKC))), (avg(sma(close,lengthKC))), (lengthKC,0))

但它一直告诉我:

输入不匹配 ',' 期望 ')'

我尝试了一些其他解决方案,但无法解决这个问题。

编辑:
这是完整的代码:

study(shorttitle = "SQZMOM_LB", title="Squeeze Momentum Indicator [LazyBear]", overlay=false)

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")

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(highest(high, lengthKC)), avg(lowest(low, lengthKC))), (avg(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=bcolor, style=histogram, linewidth=4)
plot(0, color=scolor, style=cross, linewidth=2)
英文:

I tried to convert pine v1 linreg function to v3 (and afterwards convert it automatically to V5) but I kept getting this error:

> syntax error at input 'end of line without line continuation'

This is the V1 code

val = linreg(source  -  avg(avg(highest(high, lengthKC), lowest(low, lengthKC)),sma(close,lengthKC)), 
            lengthKC,0)

So I looked it up in the pine script language reference and the function should look like this:

> linreg(source, length, offset) → series

If I'm correct, the source should be this:

> source - avg(avg(highest(high, lengthKC), lowest(low, lengthKC)),

Length:

> sma(close,lengthKC)),

And Offset:

> lengthKC,0)

So I wrote it like this in V3:

val = linreg((source - avg(highest(high, lengthKC)), avg(lowest(low, lengthKC))), (avg(sma(close,lengthKC))), (lengthKC,0))

But it keeps telling me

> mismatched input ',' expecting ')'

I played around with some other solutions but couldnt figure out how to solve the problem.

EDIT:
This is the full code:

study(shorttitle = &quot;SQZMOM_LB&quot;, title=&quot;Squeeze Momentum Indicator [LazyBear]&quot;, overlay=false)

length = input(20, title=&quot;BB Length&quot;)
mult = input(2.0,title=&quot;BB MultFactor&quot;)
lengthKC=input(20, title=&quot;KC Length&quot;)
multKC = input(1.5, title=&quot;KC MultFactor&quot;)

useTrueRange = input(true, title=&quot;Use TrueRange (KC)&quot;, 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 &gt; lowerKC) and (upperBB &lt; upperKC)
sqzOff = (lowerBB &lt; lowerKC) and (upperBB &gt; upperKC)
noSqz  = (sqzOn == false) and (sqzOff == false)

val = linreg((source  -  avg(highest(high, lengthKC)), avg(lowest(low, lengthKC))), (avg(sma(close,lengthKC))), (lengthKC,0))

bcolor = iff( val &gt; 0, 
            iff( val &gt; nz(val[1]), lime, green),
            iff( val &lt; nz(val[1]), red, maroon))
scolor = noSqz ? blue : sqzOn ? black : gray 
plot(val, color=bcolor, style=histogram, linewidth=4)
plot(0, color=scolor, style=cross, linewidth=2)```


</details>


# 答案1
**得分**: 0

原始代码略有不同。

`val` 的定义如下:

val = linreg(source - avg(avg(highest(high, lengthKC), lowest(low, lengthKC)), sma(close, lengthKC)), lengthKC, 0)


如果您在指标列表中搜索 *Squeeze Momentum Indicator [LazyBear]*,您可以找到该指标。

[![enter image description here][1]][1]

<details>
<summary>英文:</summary>

The original code is slightly different.

The definition of `val` is as below:

    val = linreg(source - avg(avg(highest(high, lengthKC), lowest(low, lengthKC)),sma(close,lengthKC)), lengthKC,0)

If you search for *Squeeze Momentum Indicator [LazyBear]* in the indicator list, you can find the indicator.

[![enter image description here][1]][1]


  [1]: https://i.stack.imgur.com/FVVk8.png

</details>



huangapple
  • 本文由 发表于 2023年6月12日 17:21:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76455215.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定