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 = "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)```
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.